Add meta refresh option
This commit is contained in:
parent
b8208fe50f
commit
92bf9c75ed
|
@ -26,18 +26,36 @@ $router.get(-> $request, $response {
|
||||||
|
|
||||||
$router.post(-> $request, $response {
|
$router.post(-> $request, $response {
|
||||||
my Str $return-url = $request.content.{'hyperlink'};
|
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-scheme = $request.headers.{'X-Forwarded-Proto'} || 'http';
|
||||||
my Str $url-host = $request.headers.{'Host'};
|
my Str $url-host = $request.headers.{'Host'};
|
||||||
my Str $base-url = $url-scheme ~ '://' ~ $url-host ~ '/';
|
my (Str $base-url, Str $hyperlink, Str %stash);
|
||||||
my Str $hyperlink = $base-url ~ encode-base64(gzip($return-url), :str);
|
|
||||||
my Str %stash =
|
$base-url = $meta-refresh
|
||||||
|
?? $url-scheme ~ '://' ~ $url-host ~ '/--meta-refresh/'
|
||||||
|
!! $url-scheme ~ '://' ~ $url-host ~ '/';
|
||||||
|
|
||||||
|
$hyperlink = $base-url ~ encode-base64(gzip($return-url), :str);
|
||||||
|
|
||||||
|
%stash =
|
||||||
title => 'New hyperlink created',
|
title => 'New hyperlink created',
|
||||||
hyperlink => $hyperlink;
|
hyperlink => $hyperlink;
|
||||||
|
|
||||||
$response.html($template.render: 'index', %stash);
|
$response.html($template.render: 'index', %stash);
|
||||||
});
|
});
|
||||||
|
|
||||||
# Try a wildcard to catch 'all' path
|
|
||||||
|
# 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;
|
||||||
|
|
||||||
|
$response.html($template.render: 'index', %stash);
|
||||||
|
});
|
||||||
|
|
||||||
$router.get('/**', -> $request, $response {
|
$router.get('/**', -> $request, $response {
|
||||||
my Str $return-url = $request.path.substr(1); # Omits the leading slash
|
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));
|
||||||
|
|
|
@ -2,6 +2,9 @@
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<title>{{title}}</title>
|
<title>{{title}}</title>
|
||||||
|
{{#meta-refresh}}
|
||||||
|
<meta http-equiv="Refresh" content="0; url='{{redirect-url}}'">
|
||||||
|
{{/meta-refresh}}
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>{{title}}</h1>
|
<h1>{{title}}</h1>
|
||||||
|
|
|
@ -1,11 +1,17 @@
|
||||||
{{> header}}
|
{{> header}}
|
||||||
{{#hyperlink}}
|
{{^meta-refresh}}
|
||||||
<p>Your hyperlink is: <a href="{{hyperlink}}">{{hyperlink}}</a></p>
|
{{#hyperlink}}
|
||||||
{{/hyperlink}}
|
<p>Your hyperlink is: <a href="{{hyperlink}}">{{hyperlink}}</a></p>
|
||||||
<form method="post">
|
{{/hyperlink}}
|
||||||
|
<form method="post">
|
||||||
<label for="hyperlink">Hyperlink</label>
|
<label for="hyperlink">Hyperlink</label>
|
||||||
<input id="hyperlink" name="hyperlink" type="text" minlength="4"
|
<input id="hyperlink" name="hyperlink" type="text" minlength="4"
|
||||||
maxlength="2097152" required>
|
maxlength="2083" required>
|
||||||
|
<label for="meta-refresh">
|
||||||
|
<a href="https://en.wikipedia.org/wiki/Meta_refresh">Meta refresh?</a>
|
||||||
|
</label>
|
||||||
|
<input id="meta-refresh" name="meta-refresh" type="checkbox">
|
||||||
<button type="submit">Process</button>
|
<button type="submit">Process</button>
|
||||||
</form>
|
</form>
|
||||||
|
{{/meta-refresh}}
|
||||||
{{> footer}}
|
{{> footer}}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user