cowboy http request parse

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

cowboy http request parse

nickel chen-2
Hi, I'm new to erlang and being learning it, and I found cowboy is a very good project to learn how to implement a http protocol. It's based on ranch, which set socket option {packet, raw}, means it will deliver message {tcp, Socket, Data} to cowboy constantly. 
While reading parse_request function in cowboy_http.erl, I found it difficult to understand. As far as I figured out, when received message, this function append Data to Buffer unless the data contains a new line "\r\n", then it began to parse the Buffer.
The Buffer may be part of the whole request header, may ends with "\r\n", or at least contains "\r\n". So it may be:

GET / HTTP/1.1\r\n


or 

GET / HTTP/1.1\r\n
Host:

After parsed the first line for method, uri, version, it will go back to read more Data from Socket to Buffer. 
My question is, why not read the whole request header all at once, as request header and request body are seperated by two "\r\n" (Correct me if I mis-understand: one "\r\n" is for header line ending, the other is for the empty line between header and body). After reading whole request, then it will not bother going back again to read Socket Data while parsing.

Thank you.




_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Loading...