我正在学习erlang,下面是解释如何使用gen_tcp的一个例子的一部分.但是,几乎所有的toturials都只显示echo服务器,我发现没有人正在解析真正的世界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;
Run Code Online (Sandbox Code Playgroud)
我很好奇erlang如何解析收到的数据gen_tcp:recv.我已经浏览了一些代码,lib/inets-5.7.1/src/http_server但是有太多的模块,我仍然无法弄清楚解析http请求的基本方向是什么.任何人都可以告诉我如何解析http请求,以及这些Web框架采取的方法是什么.谢谢〜
Erlang有几个轻量级的Web服务器库,包括:
还有雅司病哪个更媲美阿帕奇.我建议查看Cowboy的代码,因为它非常模块化.
可以在此处找到回答问题的快捷方式:
http://www.erlang.org/doc/man/erlang.html#decode_packet-3和 https://github.com/extend/cowboy/blob/master/src/cowboy_http_protocol.erl#L99
| 归档时间: |
|
| 查看次数: |
2201 次 |
| 最近记录: |