Handle gziped request bodies

1,063 views
Skip to first unread message

Kevin Conway

unread,
Mar 4, 2017, 5:12:27 PM3/4/17
to golang-nuts
I'm running a go 1.7 HTTP server. One of my clients is applying gzip to the POST body of their request and applying the appropriate content-encoding header. The current server implementation in go, unlike the client, does not appear to automatically handle decompression of the body. This is causing calls to JSON unmarshal to fail because it, rightly, expects uncompressed data to work with.

Certainly, we could add our own gzip reader on top of the request body to handle this. It seems strange, though, that this case is accounted for in the go HTTP client but not the server.

Have I missed something obvious?

John Kemp

unread,
Mar 4, 2017, 5:17:12 PM3/4/17
to Kevin Conway, golang-nuts
AFAIK, there is (still?) no out-of-the-box support for gzip.

See, for example, https://github.com/NYTimes/gziphandler

- johnk
> --
> You received this message because you are subscribed to the Google Groups "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Kevin Conway

unread,
Mar 4, 2017, 7:54:02 PM3/4/17
to John Kemp, golang-nuts
>> AFAIK, there is (still?) no out-of-the-box support for gzip.
I believe this is the answer. I figured I'd fish around to see if anyone had already solved and open sourced a solution to this problem.
While certainly related, this example only provides gzip _compression_ for responses emitted from an HTTP server when the request has the appropriate accept-encoding header. I'm also looking to gzip _decompress_ the incoming request bodies when they are marked with an appropriate content-encoding header.

Caleb Spare

unread,
Mar 5, 2017, 12:57:50 AM3/5/17
to Kevin Conway, golang-nuts, John Kemp
You'll need to handle it yourself. Gzipped requests (unlike responses) are somewhat nonstandard.

(With a response, the client can say it supports gzip, but with requests, you basically have to prenegotiate it out-of-band -- at least, that's how I've encountered it in the past.)

> To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.

> For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages