From 190a148b9ce087653cc3d2d7f3c3bb140473ba9c Mon Sep 17 00:00:00 2001 From: Daniel Bowling Date: Fri, 3 Nov 2023 01:04:45 -0400 Subject: [PATCH] Implement meta refresh --- lib/Hyperlink-Redirect.rakumod | 17 ++++++----------- templates/header.mustache | 4 ++-- templates/index.mustache | 4 ++-- 3 files changed, 10 insertions(+), 15 deletions(-) diff --git a/lib/Hyperlink-Redirect.rakumod b/lib/Hyperlink-Redirect.rakumod index a330c14..830a4cf 100644 --- a/lib/Hyperlink-Redirect.rakumod +++ b/lib/Hyperlink-Redirect.rakumod @@ -25,10 +25,10 @@ $router.get(-> $request, $response { }); $router.post(-> $request, $response { - my Str $return-url = $request.content.{'hyperlink'}; - my Bool $meta-refresh = $request.content. ?? True !! False; - my Str $url-scheme = $request.headers.{'X-Forwarded-Proto'} || 'http'; - my Str $url-host = $request.headers.{'Host'}; + my Str $return-url = $request.content.; + my Bool $meta-refresh = $request.content..defined; + my Str $url-scheme = $request.headers. || 'http'; + my Str $url-host = $request.headers.; my (Str $base-url, Str $hyperlink, Str %stash); $base-url = $meta-refresh @@ -37,21 +37,16 @@ $router.post(-> $request, $response { $hyperlink = $base-url ~ encode-base64(gzip($return-url), :str); - %stash = - title => 'New hyperlink created', - hyperlink => $hyperlink; + %stash = title => 'New hyperlink created', :$hyperlink; $response.html($template.render: 'index', %stash); }); - # Process the hyperlink $router.get('/--meta-refresh/**', -> $request, $response { my Str $return-url = $request.path.subst: /^ '/--meta-refresh/'/, Empty; my Str $redirect-url = gunzip(decode-base64($return-url, :bin)); - my Str %stash = - title => 'Hyperlinking...', - redirect-url => $redirect-url; + my Str %stash = title => 'Hyperlinking...', :$redirect-url; $response.html($template.render: 'index', %stash); }); diff --git a/templates/header.mustache b/templates/header.mustache index 207564f..e0895b1 100644 --- a/templates/header.mustache +++ b/templates/header.mustache @@ -2,9 +2,9 @@ {{title}} - {{#meta-refresh}} + {{#redirect-url}} - {{/meta-refresh}} + {{/redirect-url}}

{{title}}

diff --git a/templates/index.mustache b/templates/index.mustache index 90a6456..0510dae 100644 --- a/templates/index.mustache +++ b/templates/index.mustache @@ -1,5 +1,5 @@ {{> header}} -{{^meta-refresh}} +{{^redirect-url}} {{#hyperlink}}

Your hyperlink is: {{hyperlink}}

{{/hyperlink}} @@ -13,5 +13,5 @@ -{{/meta-refresh}} +{{/redirect-url}} {{> footer}}