Skip to content

Commit

Permalink
Merge pull request #195 from Xliff/xliff-500s
Browse files Browse the repository at this point in the history
- Adds two methods: .not-supported and .server-error which will return status codes 500 and 505, respectively.
  • Loading branch information
patrickbkr authored Jul 11, 2024
2 parents c9e2e64 + 604f944 commit ee25c84
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions lib/Cro/HTTP/Router.pm6
Original file line number Diff line number Diff line change
Expand Up @@ -1068,6 +1068,36 @@ module Cro::HTTP::Router {
content $content-type, $body, |%options;
}

proto server-error(|) is export {*}

#| Produce a HTTP 500 Server Error response
multi server-error(--> Nil) {
set-status(500, :action<server-errror>);
}

#| Produce a HTTP 500 Server Error response. The remaining arguments will be
#| passed to the content function, setting the media type, response body, and
#| other options.
multi server-error($content-type, $body, *%options --> Nil) {
set-status(500, :action<server-error>);
content $content-type, $body, |%options;
}

proto not-supported(|) is export {*}

#| Produce a HTTP 505 Not Supported response
multi not-supported(--> Nil) {
set-status(505, :action<not-supported>);
}

#| Produce a HTTP 505 Not Supported response. The remaining arguments will be
#| passed to the content function, setting the media type, response body, and
#| other options.
multi not-supported($content-type, $body, *%options --> Nil) {
set-status(505, :action<not-supported>);
content $content-type, $body, |%options;
}

#| Add a cookie to the response
sub set-cookie($name, $value, *%opts) is export {
my $resp = $*CRO-ROUTER-RESPONSE //
Expand Down

0 comments on commit ee25c84

Please sign in to comment.