package WebGUI::Session::Request; use strict; use parent qw(Plack::Request); use WebGUI::Session::Response; use HTTP::BrowserDetect; =head1 SYNOPSIS my $session = WebGUI::Session->open(...); my $request = $session->request; =head1 DESCRIPTION WebGUI's PSGI request utility class. Sub-classes L. An instance of this object is created automatically when the L is created. =head1 METHODS =cut #------------------------------------------------------------------- =head2 browser Returns a HTTP::BrowserDetect object for the request. =cut sub browser { my $self = shift; return $self->env->{'webgui.browser'} ||= HTTP::BrowserDetect->new($self->user_agent); } #------------------------------------------------------------------- =head2 clientIsSpider ( ) Returns true is the client/agent is a spider/indexer or some other non-human interface, determined by checking the user agent against a list of known spiders. =cut sub clientIsSpider { my $self = shift; return 1 if $self->user_agent eq '' || $self->user_agent =~ /^wre/ || $self->browser->robot; return 0; } #------------------------------------------------------------------- =head2 callerIsSearchSite ( ) Returns true if the remote address matches a site which is a known indexer or spider. =cut sub callerIsSearchSite { my $self = shift; my $remoteAddress = $self->address; return 1 if $remoteAddress =~ /203\.87\.123\.1../ # Blaiz Enterprise Rawgrunt search || $remoteAddress =~ /123\.113\.184\.2../ # Unknown Yahoo Robot || $remoteAddress == ''; return 0; } #------------------------------------------------------------------- =head2 new_response () Creates a new L object. N.B. A L object is automatically created when L is instantiated, so in most cases you will not need to call this method. See L =cut sub new_response { my $self = shift; return WebGUI::Session::Response->new(@_); } #------------------------------------------------------------------- =head2 requestNotViewed ( ) Returns true is the client/agent is a spider/indexer or some other non-human interface =cut sub requestNotViewed { my $self = shift; return $self->clientIsSpider(); # || $self->callerIsSearchSite(); # this part is currently left out because # it has minimal effect and does not manage # IPv6 addresses. it may be useful in the # future though } # This is only temporary sub TRACE { shift->env->{'psgi.errors'}->print(join '', @_, "\n"); } 1;