Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Revision history for Cro::HTTP
{{NEXT}}
- Support link generation
- Make http function accept a list of http methods
- Catch URI parse errors during routing

0.8.11
- Avoid sending a 0-byte WINDOW_UPDATE frame.
Expand Down
6 changes: 6 additions & 0 deletions lib/Cro/HTTP/Router.rakumod
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,12 @@ module Cro::HTTP::Router {
my @*BIND-FAILS;
my $log-timeline-task = $request.annotations<log-timeline>;
my $routing-outcome = Cro::HTTP::LogTimeline::Route.log: $log-timeline-task, -> {
CATCH {
when X::Cro::Uri::ParseError {
emit Cro::HTTP::Response.new(:400status, :$request);
next;
}
}
$request.path ~~ $!path-matcher
}
with $routing-outcome {
Expand Down
6 changes: 6 additions & 0 deletions t/http-router.rakutest
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ sub body-text(Cro::HTTP::Response $r) {
ok $r ~~ Cro::HTTP::Response, 'Empty route set gives a response';
is $r.status, '404', 'Status code from empty route set is 404';
}

$source.emit(Cro::HTTP::Request.new(:method<GET>, :target<example[1].jpg>));
given $responses.receive -> $r {
ok $r ~~ Cro::HTTP::Response, 'No matching route gets a HTTP response';
is $r.status, '400', 'Status code uri is invalid is 400';
}
}

throws-like { request }, X::Cro::HTTP::Router::OnlyInHandler, what => 'request',
Expand Down