I'm still working with the protocol-buffers code in (planet murphy/protobuf). I want the web server to return a deserialized protocol buffer struct, then have the client deserialize it. I cannot make this work, and the problem is clearly due to the data being mangled by retrieving it from the HTTP port. How can I send binary data in an HTTP response and retrieve it on the other end without it being modified on the way?
This is how the original request is made: (define p (post-impure-port (string->url "http://localhost:25678/file-chunk-info") (serialize-pbuf proto-buff-struct))) Here's the function that generates the response: (define/contract (send-response-pbuf msg-func thk) (->* (procedure? (-> any)) () response?) (define msg-name (symbol->string (object-name msg-func))) (response/xexpr `(html (body (p ,(~a msg-name " processed")))) #:mime-type (string->bytes/utf-8 "application/octet-stream") #:headers (list (header #"Transfer-Encoding" #"identity") (header #"Content-Encoding" #"identity") (header #"X-protocol-buffer-response" (serialize-pbuf (thk)))))) Here's what I've tried, none of which worked *) Basics - Verifying that the data arrives on the server intact. It does. - Verifying that (deserialize (serialize x)) works. It does. - Verifying that putting the data into a manually-constructed (response) struct, then pulling it out and deserializing it works. It does. *) Headers on the response - Setting Content-Type to application/octet-stream - Setting Transfer-Encoding to identity - Setting Content-Encoding to identity *) Retrieving the data client side through the post-impure-port - Pull the data out with (hash-ref (heads-string->dict (port->string p)) 'X-my-custom-header) - Parse the data manually using regexp-match against (port->bytes p) - Retrieve the data with (port->bytes-lines p) and deserialize the individual The error it's failing with is "<x> does not match expected data type", which means "you've given me a blob of bytes that cannot be parsed into the structure that you want me to parse them into." It only fails on protocol-buffer types that have embedded protocol-buffer messages, for what that's worth. This would be trivial if I could get the original response object before it was turned into a port, but I don't see how to do that. I am absolutely at my wits end, and I know this has to be simple. What am I missing? Dave -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.