From 60b149d5206f3b156252c1f8b75e80784cf8e928 Mon Sep 17 00:00:00 2001 From: Peter Harpending Date: Wed, 17 Sep 2025 17:26:12 -0700 Subject: [PATCH] log METHOD PATH, properly integrate Next --- NOTES.txt | 11 +++++++++-- src/fd_client.erl | 18 +++++++++++++----- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/NOTES.txt b/NOTES.txt index f9e81d5..f1e6a85 100644 --- a/NOTES.txt +++ b/NOTES.txt @@ -1,6 +1,13 @@ VIDEO 1 - 2025-09-16 TODONE - add qhl as dep - TODO (GOAL QUEUE) - - listen by default - 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 diff --git a/src/fd_client.erl b/src/fd_client.erl index b2f84cc..d54b592 100644 --- a/src/fd_client.erl +++ b/src/fd_client.erl @@ -30,7 +30,8 @@ -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 @@ -126,15 +127,21 @@ listen(Parent, Debug, ListenSocket) -> %% 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. -loop(Parent, Debug, State = #s{socket = Socket}) -> +loop(Parent, Debug, State = #s{socket = Socket, next = Next}) -> ok = inet:setopts(Socket, [{active, once}]), receive {tcp, Socket, Message} -> %ok = io:format("~p received: ~tp~n", [self(), Message]), - case qhl:parse(Socket, Message) of - {ok, Req, none} -> + Received = + case Next of + none -> Message; + _ -> <> + end, + case qhl:parse(Socket, Received) of + {ok, Req, NewNext} -> handle_request(Socket, Req), - loop(Parent, Debug, State); + NewState = State#s{next = NewNext}, + loop(Parent, Debug, NewState); Error -> io:format("~tp:~tp error: ~tp~n", [self(), ?LINE, Error]), gen_tcp:shutdown(Socket, read_write), @@ -217,6 +224,7 @@ system_replace_state(StateFun, State) -> %%% http request handling 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).