Skip to content

Commit 6908f7d

Browse files
committed
Intermediate commit
1 parent f8e63fc commit 6908f7d

3 files changed

Lines changed: 24 additions & 14 deletions

File tree

‎src/nova_router.erl‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,7 @@ compile_paths([RouteInfo|Tl], Dispatch, Options) ->
358358
parse_url(_Host, [], _Prefix, _Value, Tree) -> {ok, Tree};
359359
parse_url(Host, [{StatusCode, Callback, Options}|Tl], T, Value, Tree) when is_integer(StatusCode) andalso
360360
is_function(Callback) ->
361+
%% Store this information in a separate table for easy retrieval when we need to execute the callback for this status code
361362
Value0 = Value#nova_handler_value{callback = Callback},
362363
Res = lists:foldl(fun(Method, Tree0) ->
363364
insert(Host, StatusCode, Method, Value0, Tree0)

‎src/nova_routing_trie.erl‎

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,10 @@ member(Method0, Path, Trie) ->
205205
-spec member(method_in(), host_in(), iodata(), trie()) -> boolean().
206206
member(Method0, HostIn, Path, Trie) ->
207207
case lookup(Method0, HostIn, Path, Trie) of
208-
{ok, _Node, _Payload, _Binds} -> true;
209-
error -> false
208+
{ok, _Node, _Payload, _Binds} ->
209+
true;
210+
_ ->
211+
false
210212
end.
211213

212214
%%--------------------------------------------------------------------
@@ -221,7 +223,7 @@ member(Method0, HostIn, Path, Trie) ->
221223
%%--------------------------------------------------------------------
222224

223225
-spec lookup(iodata(), trie()) ->
224-
{ok, trie_node(), term(), #{binary() => binary()}} | error.
226+
{ok, trie_node(), term(), #{binary() => binary()}} | error | {error, comparator_not_found, MethodsAllowed :: binary() | [binary()]}.
225227
lookup(Path, Trie) ->
226228
lookup(<<"ALL">>, '_', Path, Trie).
227229

@@ -246,8 +248,10 @@ lookup(Method0, HostIn, Path, Trie = #{hosts := Hosts}) ->
246248
case do_match(Jailed, HostTrie, #{}) of
247249
{ok, Node, Binds} ->
248250
case method_payload(M, Node) of
249-
{ok, Payload} -> {ok, Node, Payload, Binds};
250-
error -> error
251+
{ok, Payload, Segs} ->
252+
{ok, Node, Payload, Binds};
253+
Error ->
254+
Error
251255
end;
252256
_ ->
253257
error
@@ -429,8 +433,10 @@ method_payload(M, #{terminal := Term}) ->
429433
{ok, Payload};
430434
error ->
431435
case maps:to_list(Term) of
432-
[] -> error;
433-
[{_, P} | _] -> {ok, P}
436+
[] ->
437+
{error, comparator_not_found, Term};
438+
[{_, P} | _] ->
439+
{ok, P}
434440
end
435441
end;
436442
_ ->
@@ -439,8 +445,10 @@ method_payload(M, #{terminal := Term}) ->
439445
{ok, Payload};
440446
error ->
441447
case maps:find(<<"ALL">>, Term) of
442-
{ok, Payload} -> {ok, Payload};
443-
error -> error
448+
{ok, Payload} ->
449+
{ok, Payload};
450+
error ->
451+
{error, comparator_not_found, Term}
444452
end
445453
end
446454
end.
@@ -718,10 +726,12 @@ do_match([Seg | Rest], N, Binds0) ->
718726
error -> error;
719727
Ok -> Ok
720728
end;
721-
error -> error
729+
error ->
730+
error
722731
end,
723732
case Exact of
724-
{ok, _, _} -> Exact;
733+
{ok, _, _} ->
734+
Exact;
725735
error ->
726736
%% 2) Wildcard fallback
727737
case find_wild_child(Cs) of

‎src/nova_security_handler.erl‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ execute(Req = #{host := Host}, Env = #{secure := Callback}) ->
4141
end.
4242

4343

44-
4544
handle_response({true, AuthData}, Req, Env) ->
4645
case maps:get(cowboy_handler, Env, undefined) of
4746
nova_ws_handler ->
@@ -53,9 +52,9 @@ handle_response({true, AuthData}, Req, Env) ->
5352
handle_response(true, Req, Env) ->
5453
{ok, Req, Env};
5554
handle_response({false, Headers}, Req, Env) ->
56-
handle_response({false, 401, Headers, false}, Req, Env);
55+
handle_response({false, 401, Headers, <<>>}, Req, Env);
5756
handle_response({false, StatusCode, Headers}, Req, Env) ->
58-
handle_response({false, StatusCode, Headers, false}, Req, Env);
57+
handle_response({false, StatusCode, Headers, <<>>}, Req, Env);
5958
handle_response({false, StatusCode, Headers, Body}, Req = #{host := Host}, Env) ->
6059
{ok, Req1, _Env1} =
6160
case Body of

0 commit comments

Comments
 (0)