diff --git a/lib/Helpers.rakumod b/lib/Helpers.rakumod new file mode 100644 index 0000000..93904f8 --- /dev/null +++ b/lib/Helpers.rakumod @@ -0,0 +1,19 @@ +my $starts-with-protocol = rx:i/ ^https?\:\/\//; + +sub fix-protocol ($url) is export { + return "https://" ~ $url unless $url ~~ $starts-with-protocol; +} + +# I use a dedicated method to remove all debugging messages prior to commit +sub dbug($message) { + say "$message"; +} + +#error types +# Just string is provided: +# ERROR: Malformed UTF-8 near byte 81 at line 1 col 2 +# TYPE: X::AdHoc + +# ERROR: Stringification of a Buf is not done with 'Stringy'. The 'decode' +# method should be used to convert a Buf to a Str. +# TYPE: X::Buf::AsStr diff --git a/lib/Hyperlink-Redirect.rakumod b/lib/Hyperlink-Redirect.rakumod index c542e18..ffc8b7f 100644 --- a/lib/Hyperlink-Redirect.rakumod +++ b/lib/Hyperlink-Redirect.rakumod @@ -4,6 +4,7 @@ use Humming-Bird::Advice; use Template::Mustache; use Base64; use Libarchive::Filter :gzip; +use Helpers; # Normally would 'use' local libs here for Controller and Model and # what not but keeping it simple for now... @@ -25,7 +26,7 @@ $router.get(-> $request, $response { }); $router.post(-> $request, $response { - my Str $return-url = $request.content; + my Str $return-url = fix-protocol($request.content); my Bool $meta-refresh = $request.content.defined; my Str $url-scheme = $request.headers || 'http'; my Str $url-host = $request.headers; @@ -52,6 +53,7 @@ $router.get('/--meta-refresh/**', -> $request, $response { $router.get('/**', -> $request, $response { my Str $return-url = $request.path.substr(1); # Omits the leading slash + my Str $redirect-url = gunzip(decode-base64($return-url, :bin)); $response.redirect($redirect-url);