fed-sx-m1: Step 8c-actors-doc — match_prefix + GET /actors/{id} route + 13 tests
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 32s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 32s
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
-module(http_server).
|
||||
-export([route/1, ok_response/1, not_found_response/0,
|
||||
welcome_body/0, capabilities_body/0,
|
||||
capabilities_path/0]).
|
||||
capabilities_path/0,
|
||||
match_prefix/2, actors_prefix/0, actor_doc_response/1]).
|
||||
|
||||
%% HTTP request router per design §16.1.
|
||||
%%
|
||||
@@ -34,6 +35,17 @@ dispatch(<<71, 69, 84>>,
|
||||
<<47,46,119,101,108,108,45,107,110,111,119,110,
|
||||
47,115,120,45,99,97,112,97,98,105,108,105,116,105,101,115>>) ->
|
||||
ok_response(capabilities_body());
|
||||
%% GET /actors/{id}
|
||||
dispatch(<<71, 69, 84>>, Path) ->
|
||||
case match_prefix(actors_prefix(), Path) of
|
||||
{ok, Id} ->
|
||||
case byte_size(Id) of
|
||||
0 -> not_found_response();
|
||||
_ -> actor_doc_response(Id)
|
||||
end;
|
||||
nomatch ->
|
||||
not_found_response()
|
||||
end;
|
||||
dispatch(_, _) ->
|
||||
not_found_response().
|
||||
|
||||
@@ -73,3 +85,30 @@ not_found_response() ->
|
||||
field(K, [{K, V} | _]) -> V;
|
||||
field(K, [_ | Rest]) -> field(K, Rest);
|
||||
field(_, []) -> nil.
|
||||
|
||||
%% ── Dynamic-segment routing ─────────────────────────────────────
|
||||
%%
|
||||
%% match_prefix(Prefix, Path) — if Path starts with the entire
|
||||
%% Prefix binary, return {ok, Rest} where Rest is the remaining
|
||||
%% bytes; else return nomatch. Pure byte-level pattern match,
|
||||
%% no regex / no parsing. Path-segment splitting comes in later
|
||||
%% sub-deliverables (8c-art, 8c-proj) where it's needed.
|
||||
|
||||
match_prefix(<<>>, Rest) -> {ok, Rest};
|
||||
match_prefix(<<B, PRest/binary>>, <<B, PathRest/binary>>) ->
|
||||
match_prefix(PRest, PathRest);
|
||||
match_prefix(_, _) -> nomatch.
|
||||
|
||||
%% "/actors/" — 8 bytes: 47 97 99 116 111 114 115 47
|
||||
actors_prefix() ->
|
||||
<<47,97,99,116,111,114,115,47>>.
|
||||
|
||||
%% Actor doc stub. Real implementation (Step 8c continuation) will
|
||||
%% fetch the actor-state projection entry and serialise it; v1
|
||||
%% returns the id as the body so route resolution can be exercised
|
||||
%% end-to-end without the projection wiring.
|
||||
actor_doc_response(Id) ->
|
||||
%% "actor: " — 7 bytes
|
||||
Pre = <<97,99,116,111,114,58,32>>,
|
||||
Body = <<Pre/binary, Id/binary, 10>>,
|
||||
ok_response(Body).
|
||||
|
||||
Reference in New Issue
Block a user