[erlang-questions] inets, httpc, streaming, and non-2xx status codes

Todd Bittner <>
Fri Jun 10 21:24:01 CEST 2011


I'm trying to stream a response from a server via the inets client, using a
call like this:

httpc:request(<URL Parameters,etc.>,[{headers_as_is,
true},{sync,false},{stream,self}])),

200 responses seem to follow the proper work flow, but, when I receive a
non-2xx response I either get messages like this:

(1) {http, {RequestId, {status_line(), headers(), body()}},

which seems to be expected as per this previous mailing list conversation -
http://erlang.org/pipermail/erlang-bugs/2009-March/001222.html

or I'll get a message that just drops right into a stream atom clause:

(2) {http, {RequestId,stream,BinBodyPart}} ->

which is unusual, because I thought only (1) should be returned for non-2xx
responses.  As a result, I have to first check to see if I receive a
stream_start atom or a stream atom first to differentiate between 2xx and
non-2xx responses.  This is always followed up with a {http, {RequestId,
{status_line(), headers(), <<>>}}

I haven't been able to figure out what type of response causes to me get a
type (1) message and what causes me to get a type (2).

In addition, sometimes (1) doesn't function as expected either - I'll
receive a body that doesn't match the content length, and even if I try and
drop into a receive to capture the rest of the body, I never get any
messages.  Am I missing an option when calling the client?

I'm running 14A, for what it's worth.

Thanks,

Todd
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20110610/bbfce279/attachment.html>


More information about the erlang-questions mailing list