Skip to content

Instantly share code, notes, and snippets.

@kits
Created February 25, 2012 00:28
Show Gist options
  • Save kits/1904869 to your computer and use it in GitHub Desktop.
Save kits/1904869 to your computer and use it in GitHub Desktop.
Mojolicious redirect
#!/usr/bin/env perl
use Mojolicious::Lite;
get '/' => sub {
my $self = shift;
$self->redirect_to('/foo');
};
app->start;
$ telnet localhost 3000
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
GET / HTTP/1.0
Host: 127.0.0.1
HTTP/1.1 302 Found
Connection: close
X-Powered-By: Mojolicious (Perl)
Location: http://127.0.0.1/foo
Date: Sat, 25 Feb 2012 00:27:30 GMT
Content-Length: 0
Server: Mojolicious (Perl)
Connection closed by foreign host.
$
$ telnet localhost 3000
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
GET / HTTP/1.0
Host: hoge.fuga
HTTP/1.1 302 Found
Connection: close
X-Powered-By: Mojolicious (Perl)
Location: http://hoge.fuga/foo
Date: Sat, 25 Feb 2012 02:44:01 GMT
Content-Length: 0
Server: Mojolicious (Perl)
Connection closed by foreign host.
$
# request時のHostヘッダの値が、そのままLocationヘッダのURLの
# ホスト名として使われるようです。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment