log METHOD PATH, properly integrate Next
This commit is contained in:
parent
eeb149e6e5
commit
60b149d520
11
NOTES.txt
11
NOTES.txt
@ -1,6 +1,13 @@
|
|||||||
VIDEO 1 - 2025-09-16
|
VIDEO 1 - 2025-09-16
|
||||||
TODONE
|
TODONE
|
||||||
- add qhl as dep
|
- add qhl as dep
|
||||||
TODO (GOAL QUEUE)
|
|
||||||
- listen by default
|
|
||||||
- talk to a web browser
|
- talk to a web browser
|
||||||
|
- alpine works
|
||||||
|
|
||||||
|
VIDEO 2 - 2025-09-17
|
||||||
|
TODONE
|
||||||
|
- properly integrate NEXT into state
|
||||||
|
- log path/method
|
||||||
|
|
||||||
|
TODO (GOAL QUEUE)
|
||||||
|
- listen by default
|
||||||
|
|||||||
@ -30,7 +30,8 @@
|
|||||||
-include("http.hrl").
|
-include("http.hrl").
|
||||||
|
|
||||||
|
|
||||||
-record(s, {socket = none :: none | gen_tcp:socket()}).
|
-record(s, {socket = none :: none | gen_tcp:socket(),
|
||||||
|
next = none :: none | binary()}).
|
||||||
|
|
||||||
|
|
||||||
%% An alias for the state record above. Aliasing state can smooth out annoyances
|
%% An alias for the state record above. Aliasing state can smooth out annoyances
|
||||||
@ -126,15 +127,21 @@ listen(Parent, Debug, ListenSocket) ->
|
|||||||
%% The service loop itself. This is the service state. The process blocks on receive
|
%% The service loop itself. This is the service state. The process blocks on receive
|
||||||
%% of Erlang messages, TCP segments being received themselves as Erlang messages.
|
%% of Erlang messages, TCP segments being received themselves as Erlang messages.
|
||||||
|
|
||||||
loop(Parent, Debug, State = #s{socket = Socket}) ->
|
loop(Parent, Debug, State = #s{socket = Socket, next = Next}) ->
|
||||||
ok = inet:setopts(Socket, [{active, once}]),
|
ok = inet:setopts(Socket, [{active, once}]),
|
||||||
receive
|
receive
|
||||||
{tcp, Socket, Message} ->
|
{tcp, Socket, Message} ->
|
||||||
%ok = io:format("~p received: ~tp~n", [self(), Message]),
|
%ok = io:format("~p received: ~tp~n", [self(), Message]),
|
||||||
case qhl:parse(Socket, Message) of
|
Received =
|
||||||
{ok, Req, none} ->
|
case Next of
|
||||||
|
none -> Message;
|
||||||
|
_ -> <<Next/binary, Message/binary>>
|
||||||
|
end,
|
||||||
|
case qhl:parse(Socket, Received) of
|
||||||
|
{ok, Req, NewNext} ->
|
||||||
handle_request(Socket, Req),
|
handle_request(Socket, Req),
|
||||||
loop(Parent, Debug, State);
|
NewState = State#s{next = NewNext},
|
||||||
|
loop(Parent, Debug, NewState);
|
||||||
Error ->
|
Error ->
|
||||||
io:format("~tp:~tp error: ~tp~n", [self(), ?LINE, Error]),
|
io:format("~tp:~tp error: ~tp~n", [self(), ?LINE, Error]),
|
||||||
gen_tcp:shutdown(Socket, read_write),
|
gen_tcp:shutdown(Socket, read_write),
|
||||||
@ -217,6 +224,7 @@ system_replace_state(StateFun, State) ->
|
|||||||
%%% http request handling
|
%%% http request handling
|
||||||
|
|
||||||
handle_request(Sock, R = #request{method = M, path = P}) when M =/= undefined, P =/= undefined ->
|
handle_request(Sock, R = #request{method = M, path = P}) when M =/= undefined, P =/= undefined ->
|
||||||
|
zx:tell("~p ~p ~ts", [self(), M, P]),
|
||||||
route(Sock, M, P, R).
|
route(Sock, M, P, R).
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user