4

I'm attempting to process a chunked response from a 3rd-party service by introducing it to httputil.NewChunkedReader:

chunkedReader := httputil.NewChunkedReader(chunkedResponse)

buf := new(bytes.Buffer)
buf.ReadFrom(chunkedReader)
return buf.Bytes()

This code returns zero bytes, as does manually invoking reader.Read.

I'm looking for a practical example in terms of implementing httputil.NewChunkedReader.

Paul Mooney
  • 1,576
  • 12
  • 28
  • "header line too long" – Paul Mooney Aug 10 '15 at 11:11
  • 1
    @PaulMooney [ErrLineTooLong is returned when reading malformed chunked data with lines that are too long](http://golang.org/pkg/net/http/httputil/#pkg-variables). Are you sure your data is not malformed? – Ainar-G Aug 10 '15 at 11:59
  • @Ainar-G No, the payload is definitely not malformed. Both Postman and Fiddler display it without issue. – Paul Mooney Aug 10 '15 at 12:48
  • 2
    Where do you get `chunkedResponse` from? – Ainar-G Aug 10 '15 at 12:51
  • A proprietary service – unfortunately I can’t offer more than a code snippet: `34f0{"otherServiceInfoList":[],"...0` – Paul Mooney Aug 10 '15 at 12:58
  • Yes, it's returned from the net/http package, without any special encoding, etc. – Paul Mooney Aug 10 '15 at 13:03
  • When you say "above the HTTP layer" are you referring to some form of encoding applied before the payload is sent down the wire? – Paul Mooney Aug 10 '15 at 13:08
  • Yes, that's the code that I had originally implementated. I modified it to leverage `httputil` because Fiddler offered an encoded response warning. The object of the exercise was to understand the inner workings, more than anything else. – Paul Mooney Aug 10 '15 at 13:18
  • 2
    Do you have a sample of the chunked response? It sounds like it's not properly encoded. Otherwise, it works as advertised: http://play.golang.org/p/OBkZJRzIfd – JimB Aug 10 '15 at 13:59

0 Answers0