Strange behavior of http:request/4

東村邦彦 ktoumura@REDACTED
Mon Feb 8 14:16:33 CET 2010


I just found strange behavior of http:request/4.

When I tried to retrieve a missing content with {sync, false} and
{stream, {self,once}} options, http:request/4 sent two messages like following.

{http,{#Ref<...>, stream, <<"<!DOCTYPE ...</HTML>\n">>}}
                 {{"HTTP/1.1",404,"Not Found"},
                  [{"connection","Keep-Alive"}, ...}],

There is no "stream_start/end" message, but there is "stream" message.
And, in the second message, a body part is empty.

In the inets reference manual, it says that "stream: Streams the body of
a 200 or 206 response to the calling process or to a file".
So, I think it should return just one message like following

                 {{"HTTP/1.1",404,"Not Found"},
                  [{"connection","Keep-Alive"}, ...}],
                  <<"<!DOCTYPE ...</HTML>\n">>}}}

(because it is impossible to return a status code when using "stream*" messages)

A console output is below.
$ erl
Erlang R13B03 (erts-5.7.4) [source] [smp:2:2] [rq:2] [async-threads:0]

Eshell V5.7.4  (abort with ^G)
1> inets:start().
2> http:request(get,{"",[]},[],[{sync,false},{stream,{self,once}}]).
3> flush().
Shell got {http,{#Ref<>,stream,
                 <<"<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML
2.0//EN\">\n<HTML><HEAD>\n<TITLE>404 Not
Found</TITLE>\n</HEAD><BODY>\n<H1>Not Found</H1>\nThe requested URL
/no_such_file was not found on this
server.<P>\n<HR>\n<ADDRESS>Apache/1.3.29 Server at Port
Shell got {http,{#Ref<>,
                 {{"HTTP/1.1",404,"Not Found"},
                   {"date","Mon, 08 Feb 2010 12:13:51 GMT"},
                   {"content-type","text/html; charset=iso-8859-1"},
                   {"keep-alive","timeout=35, max=99"}],

Kunihiko Toumura

More information about the erlang-questions mailing list