Skip to content

Commit 0c30cd6

Browse files
authored
Merge pull request #209 from FCO/copy-of-invalid-url
Catch URI parse errors during routing (Copy from #114 vendethiel++)
2 parents a9d0a60 + b63ae11 commit 0c30cd6

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

Changes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ Revision history for Cro::HTTP
33
{{NEXT}}
44
- Support link generation
55
- Make http function accept a list of http methods
6+
- Catch URI parse errors during routing
67

78
0.8.11
89
- Avoid sending a 0-byte WINDOW_UPDATE frame.

lib/Cro/HTTP/Router.rakumod

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,12 @@ module Cro::HTTP::Router {
322322
my @*BIND-FAILS;
323323
my $log-timeline-task = $request.annotations<log-timeline>;
324324
my $routing-outcome = Cro::HTTP::LogTimeline::Route.log: $log-timeline-task, -> {
325+
CATCH {
326+
when X::Cro::Uri::ParseError {
327+
emit Cro::HTTP::Response.new(:400status, :$request);
328+
next;
329+
}
330+
}
325331
$request.path ~~ $!path-matcher
326332
}
327333
with $routing-outcome {

t/http-router.rakutest

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ sub body-text(Cro::HTTP::Response $r) {
1919
ok $r ~~ Cro::HTTP::Response, 'Empty route set gives a response';
2020
is $r.status, '404', 'Status code from empty route set is 404';
2121
}
22+
23+
$source.emit(Cro::HTTP::Request.new(:method<GET>, :target<example[1].jpg>));
24+
given $responses.receive -> $r {
25+
ok $r ~~ Cro::HTTP::Response, 'No matching route gets a HTTP response';
26+
is $r.status, '400', 'Status code uri is invalid is 400';
27+
}
2228
}
2329

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

0 commit comments

Comments
 (0)