Implement meta refresh

This commit is contained in:
Daniel Bowling 2023-11-03 01:04:45 -04:00
parent 92bf9c75ed
commit 190a148b9c
3 changed files with 10 additions and 15 deletions

View file

@ -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.<meta-refresh> ?? 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.<hyperlink>;
my Bool $meta-refresh = $request.content.<meta-refresh>.defined;
my Str $url-scheme = $request.headers.<X-Forwarded-Proto> || 'http';
my Str $url-host = $request.headers.<Host>;
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);
});

View file

@ -2,9 +2,9 @@
<html lang="en">
<head>
<title>{{title}}</title>
{{#meta-refresh}}
{{#redirect-url}}
<meta http-equiv="Refresh" content="0; url='{{redirect-url}}'">
{{/meta-refresh}}
{{/redirect-url}}
</head>
<body>
<h1>{{title}}</h1>

View file

@ -1,5 +1,5 @@
{{> header}}
{{^meta-refresh}}
{{^redirect-url}}
{{#hyperlink}}
<p>Your hyperlink is: <a href="{{hyperlink}}">{{hyperlink}}</a></p>
{{/hyperlink}}
@ -13,5 +13,5 @@
<input id="meta-refresh" name="meta-refresh" type="checkbox">
<button type="submit">Process</button>
</form>
{{/meta-refresh}}
{{/redirect-url}}
{{> footer}}