Below is part of one example explaining how to use gen_tcp
. However, almost all of the tutorials will just show you an echo server, but none doing parsing of a real world HTTP request.
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;
I am curious about how one can parse the data in Erlang that is received by gen_tcp:recv/\[2,3\]
. I skimmed through the code at lib/inets-5.7.1/src/http_server
but there are too many modules, and I still can't figure out what the basics of parsing an HTTP request would be.
Can anyone show me how to parse an HTTP request, and what approach web frameworks take? Thanks~