HTTP and gzip

1,173 views
Skip to first unread message

Boris Solovyov

unread,
Mar 2, 2013, 9:28:36 PM3/2/13
to golang-nuts
I see some discussions on the mailing list, and when I search http://golang.org/src/pkg/net/http/transport.go for "gzip" I see a lot of code, but... I cannot put it all together. net/http is so abstract, especially because much code is both for client and server!
  • Does HTTP client and server support transparent gzip and gunzip of requests and responses?
  • If so, what do I have to do to make it happen? Some of the code makes it look like it just happens automatically in a certain way if headers are set, and some makes it look like it happens if headers are NOT set. My client is Go, my server is Go. Do I have to set headers on client only? Both client and server?
Thanks,
Boris

Kyle Lemons

unread,
Mar 2, 2013, 9:53:03 PM3/2/13
to Boris Solovyov, golang-nuts
On Sat, Mar 2, 2013 at 6:28 PM, Boris Solovyov <boris.s...@gmail.com> wrote:
I see some discussions on the mailing list, and when I search http://golang.org/src/pkg/net/http/transport.go for "gzip" I see a lot of code, but... I cannot put it all together. net/http is so abstract, especially because much code is both for client and server!
  • Does HTTP client and server support transparent gzip and gunzip of requests and responses?
No and yes.  As of the last time I looked at this stuff: Go will not gzip request bodies for you, but it will add 'accept-encoding: gzip' to outgoing requests that do not have it already and transparently gunzip them.  If it is explicitly set, it will not be transparently gunzip'd, you have to do that yourself.
  • If so, what do I have to do to make it happen? Some of the code makes it look like it just happens automatically in a certain way if headers are set, and some makes it look like it happens if headers are NOT set. My client is Go, my server is Go. Do I have to set headers on client only? Both client and server?
Thanks,
Boris

--
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/groups/opt_out.
 
 

Boris Solovyov

unread,
Mar 2, 2013, 10:07:21 PM3/2/13
to golang-nuts
On Sat, Mar 2, 2013 at 9:53 PM, Kyle Lemons <kev...@google.com> wrote:
On Sat, Mar 2, 2013 at 6:28 PM, Boris Solovyov <boris.s...@gmail.com> wrote:
I see some discussions on the mailing list, and when I search http://golang.org/src/pkg/net/http/transport.go for "gzip" I see a lot of code, but... I cannot put it all together. net/http is so abstract, especially because much code is both for client and server!
  • Does HTTP client and server support transparent gzip and gunzip of requests and responses?
No and yes.  As of the last time I looked at this stuff: Go will not gzip request bodies for you, but it will add 'accept-encoding: gzip' to outgoing requests that do not have it already and transparently gunzip them.  If it is explicitly set, it will not be transparently gunzip'd, you have to do that yourself.

Thanks. If what you say is correct, and I right understand, from the server side, if I want to serve compressed content, all I need to to is look for the Accept-Encoding header in the request, and gzip the response. It is not done magically on server side. But, if I omit headers in client, then magically client will gunzip the compressed response from server.

From the client side, if I want to send compressed content (this is for an API, so there is lots of POST with big bodies) then I should gzip the request body. And, I guess a) I will have to add Content-Encoding header manually, b) server will not gunzip request body?

I tried somethings with curl -v but could not get anything magical to happen, so it seems magic is quite specific ;-)

I will add some debug prints and print headers, and see if I can verify above.

Thanks!
Boris

Kyle Lemons

unread,
Mar 2, 2013, 10:10:08 PM3/2/13
to Boris Solovyov, golang-nuts
If you ever gzip a body (request or response) you need to set content-encoding: gzip.  Read up here.


--
Reply all
Reply to author
Forward
0 new messages