From f7dd150728c0fdb8a0da30a1203f19047a15194b Mon Sep 17 00:00:00 2001 From: worm Date: Mon, 13 Nov 2023 16:46:19 -0800 Subject: [PATCH 1/2] 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); }); From 278924da0d3b9218e88b93bb4255e21df5d99911 Mon Sep 17 00:00:00 2001 From: worm Date: Mon, 13 Nov 2023 17:51:54 -0800 Subject: [PATCH 2/2] change regex spacing for mr. fancy britches from the uptown --- lib/Helpers.rakumod | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Helpers.rakumod b/lib/Helpers.rakumod index b096e72..954a427 100644 --- a/lib/Helpers.rakumod +++ b/lib/Helpers.rakumod @@ -1,7 +1,7 @@ -my $starts-with-protocol = rx:i/ ^https?\:\/\//; +my $starts-with-protocol = rx:i/ ^https? '://'/; sub fix-protocol ($url) is export { - return "https://" ~ $url unless $url ~~ $starts-with-protocol; + return "http://" ~ $url unless $url ~~ $starts-with-protocol; } # I use a dedicated method to remove all debugging messages prior to commit