[erlang-questions] gen_tcp very slow to fetch data

zabrane Mikael zabrane3@REDACTED
Mon Nov 23 12:58:04 CET 2009

Hi Colm,

Your assumption that the initial gen_tcp:recv will give you a binary
> which always includes the full request headers is not correct.  If you
> are going down that road you would need to write code to check for the
> the header terminator and if it isn't present then buffer and read
> more until you have the terminator.

Ok. Finding headers terminator (teh double CRLF) isn't difficult.
What's difficult for me is to find the request end?
How can I know that I've read all data in my request (GET or POST)?

>  It isn't hard but it can be messy.

Joe's code helped me a lot with his reentrant parser. Thanks by the way.

Most erlang http servers these days use the {packet, http} socket
> option which is HTTP aware and which will read/parse headers one by
> one for you and will also indicate the end of the headers.

Lev Walkin introduced an example of his web server called yucan which uses
{packer, http_bin}:

Could someone explain the difference?

> mochiweb_http has a good example of how to use {packet, http} to read
> request headers :
> http://code.google.com/p/mochiweb/source/browse/trunk/src/mochiweb_http.erl

Thanks for the pointer


More information about the erlang-questions mailing list