Disable chunked encoding in responses

766 views
Skip to first unread message

John Graham-Cumming

unread,
Nov 13, 2012, 8:59:46 PM11/13/12
to golang-nuts
I'd like to be able to disable the 'dechunking' of chunked responses
so that I get the raw response after the headers (i.e. I want to be
able to see the chunks). Is there a way to do this?

John.

Dustin Sallings

unread,
Nov 13, 2012, 9:55:16 PM11/13/12
to golan...@googlegroups.com
John Graham-Cumming <jgra...@gmail.com>
writes:

> I'd like to be able to disable the 'dechunking' of chunked responses
> so that I get the raw response after the headers (i.e. I want to be
> able to see the chunks). Is there a way to do this?

Certainly the easiest way to do this would be to create an
http.Request and write it to a socket and read until an empty line
(using Request.Write).

I think any http response reader that sees chunked will give you a
body that compensates for both chunked and content length
automatically. But reading the response is pretty straightforward.
net/textproto can handle much of it for you if you actually do want
access to the headers.

Also: Why do you want the chunk info? That *feels* like you might be
doing something weird.

--
dustin

John Graham-Cumming

unread,
Nov 13, 2012, 10:25:28 PM11/13/12
to golang-nuts
On Nov 14, 2:56 am, Dustin Sallings <dsalli...@gmail.com> wrote:
>   I think any http response reader that sees chunked will give you a
> body that compensates for both chunked and content length
> automatically.  But reading the response is pretty straightforward.
> net/textproto can handle much of it for you if you actually do want
> access to the headers.

Yes, I think what I need is net/textproto.

>   Also:  Why do you want the chunk info?  That *feels* like you might be
> doing something weird.

I am doing something weird. I work on a special HTTP proxy that is
doing compression of HTTP response bodies. Ideally I want those in the
most non-munged fashion so that I reduce buffering.

John.
Reply all
Reply to author
Forward
0 new messages