erlang如何解析一个http请求?
问题描述:
我在学习erlang,下面是解释如何使用gen_tcp的一个例子的一部分。然而,几乎所有的toturials都会向你显示echo服务器,我没有发现任何真正的世界http请求解析。erlang如何解析一个http请求?
handle_connect(Socket, BinaryList, Count) ->
io:format("handle_connect ~p~n", [self()]),
case gen_tcp:recv(Socket, 0) of
{ok, Binary} ->
io:format("request is :~s~n", Binary),
case gen_tcp:send(Socket, Binary) of
ok ->
handle_connect(Socket, BinaryList, Count);
{error, Reason} ->
io:format("send failed~n"),
gen_tcp:close(Socket)
end;
我很好奇erlang如何解析收到的数据gen_tcp:recv
。我已经通过lib/inets-5.7.1/src/http_server
下的一些代码进行了浏览,但是有太多的模块,我仍然无法弄清楚解析http请求的基本方向。任何人都可以告诉我如何解析http请求,以及那些web框架采取的方法是什么。谢谢〜
答
有Erlang的一对夫妇轻量级的Web服务器库包括:
还有Yaws这与Apache相比更具可比性。我建议检查牛仔的代码,因为它是非常模块化的。
的快捷方式回答你的问题可能在这里找到:
http://www.erlang.org/doc/man/erlang.html#decode_packet-3和 https://github.com/extend/cowboy/blob/master/src/cowboy_http_protocol.erl#L99