From f7dd150728c0fdb8a0da30a1203f19047a15194b Mon Sep 17 00:00:00 2001 From: worm Date: Mon, 13 Nov 2023 16:46:19 -0800 Subject: [PATCH] https now automatically added if not present --- lib/Helpers.rakumod | 19 +++++++++++++++++++ lib/Hyperlink-Redirect.rakumod | 6 ++++-- 2 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 lib/Helpers.rakumod diff --git a/lib/Helpers.rakumod b/lib/Helpers.rakumod new file mode 100644 index 0000000..b096e72 --- /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..2e1904f 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,7 +53,8 @@ $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)); + my Str $redirect-url = gunzip(decode-base64($return-url, :bin)); + $response.redirect($redirect-url); });