Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@polettix
Last active August 29, 2015 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save polettix/4811572938ecd4103fe6 to your computer and use it in GitHub Desktop.
Save polettix/4811572938ecd4103fe6 to your computer and use it in GitHub Desktop.
Bug in $req->to_string()?
# This is the sample program I'm using. $res->to_string() is called
# only if the URI is something like /<true-value>, and is not
# called when the URI is /
use Mojolicious::Lite;
hook after_dispatch => sub {
my ($c) = @_;
my $res = $c->res();
$res->to_string() if $c->stash('what');
$res->headers->header(Server => 'AnotherServer');
};
sub oneans { shift ->render(text => "hi\n"); };
get '/' => \&oneans;
get '/*what' => \&oneans;
app->secrets(['whatever']);
app->start();
# Let's call it with a "false" value, note that Server header is changed
# as expected
me@host $ ./prova get -v /0
[Thu Apr 30 14:33:46 2015] [debug] GET "/0"
[Thu Apr 30 14:33:46 2015] [debug] Routing to a callback
[Thu Apr 30 14:33:46 2015] [debug] 200 OK (0.002724s, 367.107/s)
GET /0 HTTP/1.1
Accept-Encoding: gzip
Connection: keep-alive
User-Agent: Mojolicious (Perl)
Host: 127.0.0.1:24340
Content-Length: 0
HTTP/1.1 200 OK
Content-Length: 3
Content-Type: text/html;charset=UTF-8
Connection: keep-alive
Server: AnotherServer
Date: Thu, 30 Apr 2015 12:33:46 GMT
hi
# Now we call it with a true value, and Server header is not changed any more
me@host$ ./prova get -v /1
[Thu Apr 30 14:34:07 2015] [debug] GET "/1"
[Thu Apr 30 14:34:07 2015] [debug] Routing to a callback
[Thu Apr 30 14:34:07 2015] [debug] 200 OK (0.001376s, 726.744/s)
GET /1 HTTP/1.1
Connection: keep-alive
Content-Length: 0
Accept-Encoding: gzip
User-Agent: Mojolicious (Perl)
Host: 127.0.0.1:38747
HTTP/1.1 200 OK
Content-Length: 3
Date: Thu, 30 Apr 2015 12:34:07 GMT
Content-Type: text/html;charset=UTF-8
Server: Mojolicious (Perl)
hi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment