From 604f944e5e511c5ac67f55219e3873dfa30bac68 Mon Sep 17 00:00:00 2001 From: Clifton Wood Date: Tue, 9 Jul 2024 08:44:00 -0400 Subject: [PATCH] - Adds two methods: .not-supported and .server-error which will return status codes 500 and 505, respectively. --- lib/Cro/HTTP/Router.pm6 | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/lib/Cro/HTTP/Router.pm6 b/lib/Cro/HTTP/Router.pm6 index ed76f0a..1162b0e 100644 --- a/lib/Cro/HTTP/Router.pm6 +++ b/lib/Cro/HTTP/Router.pm6 @@ -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); + } + + #| 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); + 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); + } + + #| 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); + content $content-type, $body, |%options; + } + #| Add a cookie to the response sub set-cookie($name, $value, *%opts) is export { my $resp = $*CRO-ROUTER-RESPONSE //