-
-
Save hesco/05b03e5c63951678d254 to your computer and use it in GitHub Desktop.
Can anyone clue me in please how it is I am misusing the AccessLog plugin for Mojo?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
----------------------- | |
This morning's test -- | |
----------------------- | |
$ perl t/17-log-referrer-header.t | |
Use of uninitialized value in concatenation (.) or string at lib/TFC/LandingPages.pm line 25. | |
ok 1 - GET / | |
not ok 2 - We found additional references to our referrer in the log | |
# Failed test 'We found additional references to our referrer in the log' | |
# at t/17-log-referrer-header.t line 38. | |
# '0' | |
# > | |
# '0' | |
1..2 | |
# Looks like you failed 1 test of 2. | |
----- | |
$ ls -lht log | |
total 220K | |
-rw-rw-r-- 1 hesco hesco 13K Aug 11 08:19 access.log | |
-rw-rw-r-- 1 hesco hesco 0 Aug 11 08:19 referrer_test.log | |
-rw-rw-r-- 1 hesco hesco 156K Aug 11 01:30 dev.log | |
----- | |
$ tail -n3 log/access.log | |
127.0.0.1 - - [11/Aug/2014:01:46:07 -0400] "GET / HTTP/1.1" 200 2316 "-" "Mojolicious (Perl)" | |
127.0.0.1 - - [11/Aug/2014:08:13:33 -0400] "GET / HTTP/1.1" 200 2316 "-" "Mojolicious (Perl)" | |
127.0.0.1 - - [11/Aug/2014:08:19:02 -0400] "GET / HTTP/1.1" 200 2316 "-" "Mojolicious (Perl)" | |
----- | |
#!/usr/bin/env perl | |
use Env qw( MOJO_MODE ); | |
use Carp; | |
use Data::Dumper; | |
use lib qw{ lib local/lib/perl5 }; | |
use Test::More; | |
use Test::Mojo::More; | |
use Mojo::Headers; | |
my $header = Mojo::Headers->new(); | |
my $t = Test::Mojo::More->new('TFC'); | |
# print Dumper( $t->ua->server->app ); | |
my $count_before = 0; | |
$MOJO_MODE = 'referrer_test'; | |
my $log = "log/$MOJO_MODE.log"; | |
`touch $log`; | |
my $referrer = 'http://www.google.com'; | |
open('LOG','<',$log) or croak "Unable to read $log"; | |
while(<LOG>){ | |
if($_ =~ m/$referrer/){ $count_before++; } | |
} | |
close('LOG'); | |
$header->referrer( $referrer ); | |
# I have tried multiple variations on this theme | |
# $t->tx->req->header->referrer( $referrer ); | |
$t->get_ok('/'); | |
my $count_after = 0; | |
open('LOG','<',$log) or croak "Unable to read $log"; | |
while(<LOG>){ | |
if($_ =~ m/$referrer/){ $count_after++; } | |
} | |
close('LOG'); | |
cmp_ok($count_after,'>',$count_before,'We found additional references to our referrer in the log'); | |
# unlink $log; | |
done_testing; | |
--------------------- | |
Last night's tests -- | |
---------------------- | |
In MyApp->startup I have: | |
$self->plugin( AccessLog => { log => 'log/access.log', | |
format => '%h %l %u %t "%r" %>s %b "%{Referer}i" "%{User-Agent}i"' }); | |
----- | |
on another site I created a link to the application I am building. | |
after following that link, I get this in the logs: | |
68.230.170.174 - - [10/Aug/2014:22:54:25 -0400] "GET / HTTP/1.1" 200 2317 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.125 Safari/537.36" | |
but no Referer, only "-". | |
Can anyone clue me in please how it is I am misusing the AccessLog plugin for Mojo? | |
----- | |
Trying this another way, I added this to my controller: | |
my $headers = Mojo::Headers->new; | |
$self->app->log->debug('TRACE: entering ->please_check_back_soon(), mode: ' . TFC::mojo_mode . ', for: ' . $self->tx->remote_address . ', referred by: ' . $headers->referrer ); | |
which generated this in the logs: | |
[Sun Aug 10 23:09:33 2014] [debug] TRACE: entering ->please_check_back_soon(), mode: dev, for: 68.230.170.174, referred by: | |
and still no Referrer. What gives? | |
----- | |
And in context; . . . | |
sub please_check_back_soon { | |
my $self = shift; | |
my $headers = Mojo::Headers->new; | |
$self->app->log->debug('TRACE: entering ->please_check_back_soon(), mode: ' . TFC::mojo_mode . ', for: ' . $self->tx->remote_address . ', referred by: ' . $headers->referrer); | |
$self->app->log->debug('TRACE: exiting ->please_check_back_soon() for: ' . $self->tx->remote_address); | |
return $self->render( template => 'landing_pages/please_check_back_soon', format => 'html' ); | |
$self->app->log->debug('TRACE: exiting ->please_check_back_soon() having failed to route to please_check_back_soon page for: ' . $self->tx->remote_address); | |
return; | |
} | |
I'm guessing that $header here has no relationship with the request which is a part of $self. But I have no idea how to create that relationship. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment