Remove Session::Env, migrate code to Plack::Request object in Session, and WebGUI::Session::Request
This commit is contained in:
parent
005b9da1ac
commit
e0177dc666
27 changed files with 131 additions and 285 deletions
|
|
@ -850,7 +850,7 @@ sub www_inviteUser {
|
|||
|
||||
$var->{'submit_button' } = WebGUI::Form::submit($session,{});
|
||||
$var->{'form_footer' } = WebGUI::Form::formFooter($session, {});
|
||||
$var->{'back_url' } = $session->env->get("HTTP_REFERER") || $var->{'view_inbox_url'};
|
||||
$var->{'back_url' } = $session->request->referer || $var->{'view_inbox_url'};
|
||||
|
||||
#Add common template variable for displaying the inbox
|
||||
$self->appendCommonVars($var);
|
||||
|
|
@ -1099,7 +1099,7 @@ sub www_sendMessage {
|
|||
my $messageId = $form->get("messageId");
|
||||
my $userId = $form->get("userId");
|
||||
my $pageUrl = $session->url->page;
|
||||
my $backUrl = $session->env->get("HTTP_REFERER") || $var->{'view_inbox_url'};
|
||||
my $backUrl = $session->request->referer || $var->{'view_inbox_url'};
|
||||
my $errorMsg = "";
|
||||
|
||||
if($messageId) {
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ sub countClick {
|
|||
my $session = shift;
|
||||
my $id = shift;
|
||||
my ($url) = $session->db->quickArray("select url from advertisement where adId=?",[$id]);
|
||||
return $url if $session->env->requestNotViewed();
|
||||
return $url if $session->request->requestNotViewed();
|
||||
$session->db->write("update advertisement set clicks=clicks+1 where adId=?",[$id]);
|
||||
return $url;
|
||||
}
|
||||
|
|
@ -119,7 +119,7 @@ A boolean that tells the ad system not to count this impression if true.
|
|||
sub displayImpression {
|
||||
my $self = shift;
|
||||
my $dontCount = shift;
|
||||
return '' if $self->session->env->requestNotViewed();
|
||||
return '' if $self->session->request->requestNotViewed();
|
||||
my ($id, $ad, $priority, $clicks, $clicksBought, $impressions, $impressionsBought) = $self->session->db->quickArray("select adId, renderedAd, priority, clicks, clicksBought, impressions, impressionsBought from advertisement where adSpaceId=? and isActive=1 order by nextInPriority asc limit 1",[$self->getId]);
|
||||
unless ($dontCount) {
|
||||
my $isActive = 1;
|
||||
|
|
|
|||
|
|
@ -588,8 +588,8 @@ to SSL.
|
|||
sub checkView {
|
||||
my $self = shift;
|
||||
return $self->session->privilege->noAccess() unless $self->canView;
|
||||
my ($conf, $env, $var, $http) = $self->session->quick(qw(config env var http));
|
||||
if ($conf->get("sslEnabled") && $self->get("encryptPage") && ! $env->sslRequest) {
|
||||
my ($conf, $var, $http) = $self->session->quick(qw(config var http));
|
||||
if ($conf->get("sslEnabled") && $self->get("encryptPage") && ! $self->session->request->secure) {
|
||||
# getUrl already changes url to https if 'encryptPage'
|
||||
$http->setRedirect($self->getUrl);
|
||||
$http->sendHeader;
|
||||
|
|
@ -1726,7 +1726,7 @@ sub getWwwCacheKey {
|
|||
my $session = $self->session;
|
||||
my $method = shift;
|
||||
my $cacheKey = join '_', @_, $self->getId;
|
||||
if ($session->env->sslRequest) {
|
||||
if ($session->request->secure) {
|
||||
$cacheKey .= '_ssl';
|
||||
}
|
||||
return $cacheKey;
|
||||
|
|
|
|||
|
|
@ -697,7 +697,7 @@ sub processCommentEditForm {
|
|||
;
|
||||
|
||||
my $visitorIp = $session->user->isVisitor
|
||||
? $session->env->get("REMOTE_ADDR")
|
||||
? $session->request->remote_host
|
||||
: undef
|
||||
;
|
||||
|
||||
|
|
|
|||
|
|
@ -350,7 +350,7 @@ sub hasRated {
|
|||
|
||||
my $hasRated = $self->session->db->quickScalar("select count(*) from MatrixListing_rating where
|
||||
((userId=? and userId<>'1') or (userId='1' and ipAddress=?)) and listingId=?",
|
||||
[$session->user->userId,$session->env->get("HTTP_X_FORWARDED_FOR"),$self->getId]);
|
||||
[$session->user->userId,$session->request->env->{"HTTP_X_FORWARDED_FOR"}, $self->getId]);
|
||||
return $hasRated;
|
||||
|
||||
}
|
||||
|
|
@ -372,7 +372,7 @@ sub incrementCounter {
|
|||
my $db = $self->session->db;
|
||||
my $counter = shift;
|
||||
|
||||
my $currentIp = $self->session->env->get("HTTP_X_FORWARDED_FOR");
|
||||
my $currentIp = $self->session->request->env->{"HTTP_X_FORWARDED_FOR"};
|
||||
|
||||
unless ($self->get($counter."LastIp") && ($self->get($counter."LastIp") eq $currentIp)) {
|
||||
$self->update({
|
||||
|
|
@ -528,7 +528,7 @@ sub setRatings {
|
|||
$db->write("insert into MatrixListing_rating
|
||||
(userId, category, rating, timeStamp, listingId, ipAddress, assetId) values (?,?,?,?,?,?,?)",
|
||||
[$session->user->userId,$category,$ratings->{$category},time(),$self->getId,
|
||||
$session->env->get("HTTP_X_FORWARDED_FOR"),$matrixId]);
|
||||
$session->request->env->{"HTTP_X_FORWARDED_FOR"}, $matrixId]);
|
||||
}
|
||||
my $sql = "from MatrixListing_rating where listingId=? and category=?";
|
||||
my $sum = $db->quickScalar("select sum(rating) $sql", [$self->getId,$category]);
|
||||
|
|
|
|||
|
|
@ -310,7 +310,7 @@ sub view {
|
|||
return $self->processTemplate({},$self->templateId)
|
||||
unless ($proxiedUrl ne "");
|
||||
|
||||
my $requestMethod = $self->session->env->get("REQUEST_METHOD") || "GET";
|
||||
my $requestMethod = $self->session->request->method || "GET";
|
||||
|
||||
### Do we have cached content to get?
|
||||
my $cache = $self->session->cache;
|
||||
|
|
@ -328,7 +328,7 @@ sub view {
|
|||
REDIRECT: for my $redirect (0..4) { # We follow max 5 redirects to prevent bouncing/flapping
|
||||
|
||||
my $userAgent = new LWP::UserAgent;
|
||||
$userAgent->agent($self->session->env->get("HTTP_USER_AGENT"));
|
||||
$userAgent->agent($self->session->request->user_agent);
|
||||
$userAgent->timeout($self->timeout);
|
||||
$userAgent->env_proxy;
|
||||
|
||||
|
|
|
|||
|
|
@ -1044,7 +1044,7 @@ sub www_drawGanttChart {
|
|||
}
|
||||
|
||||
#Adjust top for MSIE
|
||||
my $isMSIE = ($session->env->get("HTTP_USER_AGENT") =~ /msie/i);
|
||||
my $isMSIE = ($session->env->request->user_agent =~ /msie/i);
|
||||
my $divTop = $isMSIE ? 45 : 45;
|
||||
#Start at 45 px and add 20px as the start of the new task
|
||||
#Set the propert mutiplier
|
||||
|
|
|
|||
|
|
@ -101,7 +101,7 @@ sub _logLogin {
|
|||
$_[1],
|
||||
time(),
|
||||
$self->session->request->address,
|
||||
$self->session->env->get("HTTP_USER_AGENT"),
|
||||
$self->session->request->user_agent,
|
||||
$self->session->getId,
|
||||
time(),
|
||||
]
|
||||
|
|
@ -539,7 +539,7 @@ sub displayLogin {
|
|||
) {
|
||||
my $returnUrl
|
||||
= $self->session->form->get('returnUrl')
|
||||
|| $self->session->url->page( $self->session->env->get('QUERY_STRING') )
|
||||
|| $self->session->url->page( $self->session->request->env->{'QUERY_STRING'} )
|
||||
;
|
||||
$self->session->scratch->set("redirectAfterLogin", $returnUrl);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ The content handler for this package.
|
|||
|
||||
sub handler {
|
||||
my ($session) = @_;
|
||||
if ($session->env->get("HTTP_X_MOZ") eq "prefetch") { # browser prefetch is a bad thing
|
||||
if ($session->request->env->{"HTTP_X_MOZ"} eq "prefetch") { # browser prefetch is a bad thing
|
||||
$session->http->setStatus(403);
|
||||
}
|
||||
return undef;
|
||||
|
|
|
|||
|
|
@ -158,10 +158,9 @@ sub toHtml {
|
|||
my $self = shift;
|
||||
|
||||
if ($self->session->setting->get('useRecaptcha')) {
|
||||
my $env = $self->session->env;
|
||||
my $pubKey = $self->session->setting->get('recaptchaPublicKey');
|
||||
my $server = "http://api.recaptcha.net";
|
||||
if ($env->sslRequest) {
|
||||
if ($self->session->request->secure) {
|
||||
$server = "https://api-secure.recaptcha.net";
|
||||
}
|
||||
return
|
||||
|
|
|
|||
|
|
@ -32,7 +32,8 @@ then undef will be returned.
|
|||
#-------------------------------------------------------------------
|
||||
sub process {
|
||||
my $session = shift;
|
||||
return $session->env->get(shift);
|
||||
my $key = shift;
|
||||
return $session->request->env->{$key};
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
|
|||
|
|
@ -79,18 +79,18 @@ sub process {
|
|||
# A hidden field with the current URL
|
||||
my $returnUrl = $session->url->page;
|
||||
if ( !$session->form->get("op") eq "auth" ) {
|
||||
$returnUrl .= '?' . $session->env->get( "QUERY_STRING" );
|
||||
$returnUrl .= '?' . $session->request->env->{ "QUERY_STRING" };
|
||||
}
|
||||
$var{'form.returnUrl'}
|
||||
= WebGUI::Form::hidden( $session, {
|
||||
name => 'returnUrl',
|
||||
value => $session->url->page($session->env->get("QUERY_STRING")),
|
||||
value => $session->url->page($session->request->env->{"QUERY_STRING"}),
|
||||
});
|
||||
|
||||
# Fix box size
|
||||
my $boxSize = $param[0];
|
||||
$boxSize = 12 unless ($boxSize);
|
||||
if (index(lc($session->env->get("HTTP_USER_AGENT")),"msie") < 0) {
|
||||
if (index(lc($session->request->user_agent),"msie") < 0) {
|
||||
$boxSize = int($boxSize=$boxSize*2/3);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ sub process {
|
|||
my $append = 'op=makePrintable';
|
||||
$temp = $session->url->page($append);
|
||||
$temp =~ s/\/\//\//;
|
||||
$temp = $session->url->append($temp,$session->env->get("QUERY_STRING"));
|
||||
$temp = $session->url->append($temp,$session->request->env->{"QUERY_STRING"});
|
||||
if ($param[1] ne "") {
|
||||
$temp = $session->url->append($temp,'styleId='.$param[1]);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,7 +26,6 @@ use WebGUI::Config;
|
|||
use WebGUI::SQL;
|
||||
use WebGUI::User;
|
||||
use WebGUI::Session::DateTime;
|
||||
use WebGUI::Session::Env;
|
||||
use WebGUI::Session::ErrorHandler;
|
||||
use WebGUI::Session::Form;
|
||||
use WebGUI::Session::Http;
|
||||
|
|
@ -66,7 +65,6 @@ B<NOTE:> It is important to distinguish the difference between a WebGUI session
|
|||
$session->datetime
|
||||
$session->db
|
||||
$session->dbSlave
|
||||
$session->env
|
||||
$session->log
|
||||
$session->form
|
||||
$session->http
|
||||
|
|
@ -171,7 +169,7 @@ sub close {
|
|||
|
||||
# Kill circular references. The literal list is so that the order
|
||||
# can be explicitly shuffled as necessary.
|
||||
foreach my $key (qw/_asset _datetime _icon _slave _db _env _form _http _id _output _privilege _scratch _setting _stow _style _url _user _var _cache _errorHandler _response _request/) {
|
||||
foreach my $key (qw/_asset _datetime _icon _slave _db _form _http _id _output _privilege _scratch _setting _stow _style _url _user _var _cache _errorHandler _response _request/) {
|
||||
delete $self->{$key};
|
||||
}
|
||||
}
|
||||
|
|
@ -308,23 +306,6 @@ sub duplicate {
|
|||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 env ( )
|
||||
|
||||
Returns a WebGUI::Session::Env object.
|
||||
|
||||
=cut
|
||||
|
||||
sub env {
|
||||
my $self = shift;
|
||||
unless (exists $self->{_env}) {
|
||||
$self->{_env} = WebGUI::Session::Env->new($self);
|
||||
}
|
||||
return $self->{_env};
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 errorHandler ( )
|
||||
|
|
@ -486,6 +467,7 @@ sub open {
|
|||
if (! $env) {
|
||||
my $url = 'http://' . $config->get('sitename')->[0];
|
||||
my $request = HTTP::Request::Common::GET($url);
|
||||
$request->headers->user_agent('WebGUI');
|
||||
$env = $request->to_psgi;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,179 +0,0 @@
|
|||
package WebGUI::Session::Env;
|
||||
|
||||
=head1 LEGAL
|
||||
|
||||
-------------------------------------------------------------------
|
||||
WebGUI is Copyright 2001-2009 Plain Black Corporation.
|
||||
-------------------------------------------------------------------
|
||||
Please read the legal notices (docs/legal.txt) and the license
|
||||
(docs/license.txt) that came with this distribution before using
|
||||
this software.
|
||||
-------------------------------------------------------------------
|
||||
http://www.plainblack.com info@plainblack.com
|
||||
-------------------------------------------------------------------
|
||||
|
||||
=cut
|
||||
|
||||
use strict;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Package WebGUI::Session::Env
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
This package allows you to reference environment variables.
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
$env = WebGUI::Session::Env->new;
|
||||
|
||||
$value = $env->get('REMOTE_ADDR');
|
||||
|
||||
return 'not gonna see it' if $env->requestNotViewed() ;
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
These methods are available from this package:
|
||||
|
||||
=cut
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=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->getIp;
|
||||
|
||||
return 1 if $remoteAddress =~ /203\.87\.123\.1../ # Blaiz Enterprise Rawgrunt search
|
||||
|| $remoteAddress =~ /123\.113\.184\.2../ # Unknown Yahoo Robot
|
||||
|| $remoteAddress == '';
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=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;
|
||||
my $userAgent = $self->get('HTTP_USER_AGENT');
|
||||
|
||||
return 1 if $userAgent eq ''
|
||||
|| $userAgent =~ m<(^wre\/| # the WRE wget's http://localhost/ every 2-3 minutes 24 hours a day...
|
||||
^morpheus|
|
||||
libwww|
|
||||
s[pb]ider|
|
||||
bot|
|
||||
robo|
|
||||
sco[ou]t|
|
||||
crawl|
|
||||
miner|
|
||||
reaper|
|
||||
finder|
|
||||
search|
|
||||
engine|
|
||||
download|
|
||||
fetch|
|
||||
scan|
|
||||
slurp)>ix;
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 get( varName )
|
||||
|
||||
Retrieves the current value of an environment variable.
|
||||
|
||||
=head3 varName
|
||||
|
||||
The name of the variable.
|
||||
|
||||
=cut
|
||||
|
||||
sub get {
|
||||
my $self = shift;
|
||||
my $var = shift;
|
||||
return $$self->{$var};
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 new ( )
|
||||
|
||||
Constructor. Returns an env object.
|
||||
|
||||
=cut
|
||||
|
||||
sub new {
|
||||
my $class = shift;
|
||||
my $session = shift;
|
||||
my $env;
|
||||
if ($session->request) {
|
||||
$env = $session->request->env;
|
||||
}
|
||||
else {
|
||||
$env = {};
|
||||
}
|
||||
return bless \$env, $class;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=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
|
||||
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 sslRequest ( )
|
||||
|
||||
Returns true if a https request was made.
|
||||
|
||||
HTTP_SSLPROXY is set by mod_proxy in the WRE so that WebGUI knows that the original request
|
||||
was made via SSL.
|
||||
|
||||
=cut
|
||||
|
||||
sub sslRequest {
|
||||
my $self = shift;
|
||||
return $self->get('psgi.url_scheme') eq 'https';
|
||||
}
|
||||
|
||||
|
||||
1;
|
||||
|
||||
|
|
@ -17,6 +17,68 @@ is created.
|
|||
|
||||
=head1 METHODS
|
||||
|
||||
=cut
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=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;
|
||||
my $userAgent = $self->user_agent;
|
||||
|
||||
return 1 if $userAgent eq ''
|
||||
|| $userAgent =~ m<(^wre\/| # the WRE wget's http://localhost/ every 2-3 minutes 24 hours a day...
|
||||
^morpheus|
|
||||
libwww|
|
||||
s[pb]ider|
|
||||
bot|
|
||||
robo|
|
||||
sco[ou]t|
|
||||
crawl|
|
||||
miner|
|
||||
reaper|
|
||||
finder|
|
||||
search|
|
||||
engine|
|
||||
download|
|
||||
fetch|
|
||||
scan|
|
||||
slurp)>ix;
|
||||
|
||||
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<WebGUI::Session::Response> object.
|
||||
|
|
@ -32,9 +94,29 @@ sub new_response {
|
|||
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;
|
||||
1;
|
||||
|
|
|
|||
|
|
@ -131,7 +131,7 @@ sub useMobileStyle {
|
|||
if (! $session->setting->get('useMobileStyle')) {
|
||||
return $self->{_useMobileStyle} = 0;
|
||||
}
|
||||
my $ua = $session->env->get('HTTP_USER_AGENT');
|
||||
my $ua = $session->request->user_agent;
|
||||
for my $mobileUA (@{ $self->session->config->get('mobileUserAgents') }) {
|
||||
if ($ua =~ m/$mobileUA/) {
|
||||
return $self->{_useMobileStyle} = 1;
|
||||
|
|
|
|||
|
|
@ -136,7 +136,7 @@ sub extras {
|
|||
my $cdnCfg = $self->session->config->get('cdn');
|
||||
if ( $cdnCfg and $cdnCfg->{'enabled'} and $cdnCfg->{'extrasCdn'} ) {
|
||||
unless ( $path and grep $path =~ m/$_/, @{ $cdnCfg->{'extrasExclude'} } ) {
|
||||
if ($cdnCfg->{'extrasSsl'} && $self->session->env->sslRequest) {
|
||||
if ($cdnCfg->{'extrasSsl'} && $self->session->request->secure) {
|
||||
$url = $cdnCfg->{'extrasSsl'};
|
||||
}
|
||||
else {
|
||||
|
|
@ -258,7 +258,7 @@ Returns the URL of the page this request was refered from (no gateway, no query
|
|||
|
||||
sub getRefererUrl {
|
||||
my $self = shift;
|
||||
my $referer = $self->session->env->get("HTTP_REFERER");
|
||||
my $referer = $self->session->request->referer;
|
||||
return undef unless ($referer);
|
||||
my $url = $referer;
|
||||
my $gateway = $self->session->config->get("gateway");
|
||||
|
|
@ -289,20 +289,20 @@ is not passed in, it will attempt to get one from the L<page> method, or finally
|
|||
sub forceSecureConnection {
|
||||
my $self = shift;
|
||||
my $url = shift;
|
||||
my ($conf, $env, $http) = $self->session->quick(qw(config env http));
|
||||
my ($conf, $http) = $self->session->quick(qw(config http));
|
||||
|
||||
if ($conf->get("sslEnabled") && !$env->sslRequest){
|
||||
if ($conf->get("sslEnabled") && ! $self->session->request->secure){
|
||||
|
||||
$url = $self->session->url->page if(! $url);
|
||||
$url = $env->get('QUERY_STRING') if(! $url);
|
||||
my $query_string = $self->session->request->env->{'QUERY_STRING'};
|
||||
$url = $url || $self->page || $query_string;
|
||||
|
||||
my $siteURL = $self->getSiteURL();
|
||||
|
||||
if($url !~ /^$siteURL/i){
|
||||
$url = $siteURL . $url;
|
||||
}
|
||||
if($env->get('QUERY_STRING')){
|
||||
$url .= "?". $env->get('QUERY_STRING');
|
||||
if($query_string){
|
||||
$url .= "?". $query_string;
|
||||
}
|
||||
if($url =~ /^http/i) {
|
||||
$url =~ s/^https?/https/i;
|
||||
|
|
@ -347,14 +347,14 @@ sub getSiteURL {
|
|||
unless ($self->{_siteUrl}) {
|
||||
my $site = "";
|
||||
my $sitenames = $self->session->config->get("sitename");
|
||||
my ($http_host,$currentPort) = split(':', $self->session->env->get("HTTP_HOST"));
|
||||
my ($http_host,$currentPort) = split(':', $self->session->request->env->{"HTTP_HOST"});
|
||||
if ($self->session->setting->get("hostToUse") eq "HTTP_HOST" and isIn($http_host,@{$sitenames})) {
|
||||
$site = $http_host;
|
||||
} else {
|
||||
$site = $sitenames->[0];
|
||||
}
|
||||
my $proto = "http://";
|
||||
if ($self->session->env->sslRequest) {
|
||||
if ($self->session->request->secure) {
|
||||
$proto = "https://";
|
||||
}
|
||||
my $port = "";
|
||||
|
|
|
|||
|
|
@ -1284,7 +1284,7 @@ sub getUrl {
|
|||
and -e $self->getPath . '/.cdn' )
|
||||
{
|
||||
my $sep = '/'; # separator, if not already present trailing
|
||||
if ($cdnCfg->{'sslAlt'} && $self->session->env->sslRequest) {
|
||||
if ($cdnCfg->{'sslAlt'} && $self->session->request->secure) {
|
||||
if ( $cdnCfg->{'sslUrl'} ) {
|
||||
substr( $cdnCfg->{'sslUrl'}, -1 ) eq '/' and $sep = '';
|
||||
$url = $cdnCfg->{'sslUrl'} . $sep . $self->getDirectoryId;
|
||||
|
|
|
|||
|
|
@ -206,7 +206,7 @@ sub new {
|
|||
}
|
||||
my $i18n = WebGUI::International->new($session);
|
||||
my $cancelJS = 'history.go(-1);';
|
||||
if (my $cancelURL = $session->env->get('HTTP_REFERER')) {
|
||||
if (my $cancelURL = $session->request->referer) {
|
||||
$cancelJS = sprintf q{window.location.href='%s';}, $cancelURL;
|
||||
}
|
||||
my $cancel = WebGUI::Form::button($session,{
|
||||
|
|
|
|||
|
|
@ -57,15 +57,6 @@ my $uncommittedThread = $collab->addChild($props, @addArgs);
|
|||
# Test for a sane object type
|
||||
isa_ok($thread, 'WebGUI::Asset::Post::Thread');
|
||||
|
||||
my $env = $session->env;
|
||||
$env = Test::MockObject::Extends->new($env);
|
||||
|
||||
my %mockEnv = (
|
||||
REMOTE_ADDR => '192.168.0.2',
|
||||
);
|
||||
|
||||
$env->mock('get', sub { return $mockEnv{$_[1]}});
|
||||
|
||||
$session->user({userId => 3});
|
||||
$thread->rate(1);
|
||||
$thread->trash;
|
||||
|
|
|
|||
|
|
@ -144,6 +144,7 @@ cmp_bag(
|
|||
dateStamp => ignore(),
|
||||
message => 'work time',
|
||||
username => 'red',
|
||||
department => 'No Department',
|
||||
},
|
||||
ignore(), ignore(), ignore(), ignore(),
|
||||
],
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ $session->user({userId=>1});
|
|||
##known user agent. Since it usually contains a reference to %ENV,
|
||||
##you can't just modify that hash since it's protected
|
||||
my $env = $session->request->env;
|
||||
$env->{'HTTP_USER_AGENT'} = 'mozilla';
|
||||
$session->request->headers->user_agent('mozilla');
|
||||
$env->{'QUERY_STRING'} = 'func=search';
|
||||
|
||||
my $i18n = WebGUI::International->new($session,'Macro_L_loginBox');
|
||||
|
|
@ -102,7 +102,7 @@ is($vars{'form.footer'}, WebGUI::Form::formFooter($session), 'form.footer');
|
|||
is( $vars{'form.returnUrl'},
|
||||
WebGUI::Form::hidden( $session, {
|
||||
name => 'returnUrl',
|
||||
value => $session->url->page($session->env->get("QUERY_STRING")),
|
||||
value => $session->url->page($session->request->env->{"QUERY_STRING"}),
|
||||
}),
|
||||
'form.returnUrl'
|
||||
);
|
||||
|
|
@ -119,7 +119,7 @@ like($vars{'username.form'}, qr/size="16"/, 'boxSize set in username.form');
|
|||
like($vars{'password.form'}, qr/size="16"/, 'boxSize set in password.form');
|
||||
|
||||
##Change browser to be MSIE like and watch boxSize change
|
||||
$env->{'HTTP_USER_AGENT'} = 'msie';
|
||||
$session->request->headers->user_agent('msie');
|
||||
|
||||
$output = WebGUI::Macro::L_loginBox::process($session,24,'Log In',$template->getId);
|
||||
%vars = simpleTextParser($output);
|
||||
|
|
|
|||
|
|
@ -185,9 +185,9 @@ sub testCount {
|
|||
plan tests => testCount() ;
|
||||
|
||||
foreach my $testSet (@testArray) {
|
||||
$session->request->env->{HTTP_USER_AGENT} = $testSet->{agent};
|
||||
$session->request->headers->user_agent($testSet->{agent});
|
||||
$session->request->env->{REMOTE_ADDR} = $testSet->{address} || '69.42.78.32';
|
||||
my $output = $session->env->requestNotViewed;
|
||||
my $output = $session->request->requestNotViewed;
|
||||
is($output, $testSet->{output}, $testSet->{comment});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,28 +0,0 @@
|
|||
#-------------------------------------------------------------------
|
||||
# WebGUI is Copyright 2001-2009 Plain Black Corporation.
|
||||
#-------------------------------------------------------------------
|
||||
# Please read the legal notices (docs/legal.txt) and the license
|
||||
# (docs/license.txt) that came with this distribution before using
|
||||
# this software.
|
||||
#-------------------------------------------------------------------
|
||||
# http://www.plainblack.com info@plainblack.com
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
use FindBin;
|
||||
use strict;
|
||||
use lib "$FindBin::Bin/../lib";
|
||||
|
||||
use WebGUI::Test;
|
||||
use WebGUI::Session;
|
||||
|
||||
use Test::More tests => 2; # increment this value for each test you create
|
||||
|
||||
my $session = WebGUI::Test->session;
|
||||
|
||||
|
||||
cmp_ok($session->env->get("REMOTE_ADDR"), 'ne', "", "get() one valid entry");
|
||||
|
||||
my $env = $session->env;
|
||||
$session->request->env->{REMOTE_ADDR} = '192.168.0.2';
|
||||
#is ($env->getIp, '192.168.0.2', 'getIp');
|
||||
|
||||
|
|
@ -50,7 +50,7 @@ my @getRefererUrlTests = (
|
|||
);
|
||||
|
||||
use Test::More;
|
||||
plan tests => 83 + scalar(@getRefererUrlTests);
|
||||
plan tests => 82 + scalar(@getRefererUrlTests);
|
||||
|
||||
my $session = WebGUI::Test->session;
|
||||
my $request = $session->request;
|
||||
|
|
@ -242,12 +242,8 @@ $session->asset($sessionAsset);
|
|||
#
|
||||
#######################################
|
||||
|
||||
$env->{'HTTP_REFERER'} = 'test';
|
||||
|
||||
is($session->env->get('HTTP_REFERER'), 'test', 'testing overridden ENV');
|
||||
|
||||
foreach my $test (@getRefererUrlTests) {
|
||||
$env->{HTTP_REFERER} = $test->{input};
|
||||
$session->request->referer($test->{input});
|
||||
is($session->url->getRefererUrl, $test->{output}, $test->{comment});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -216,6 +216,7 @@ sub newEnv {
|
|||
? HTTP::Request::Common::POST( $url, [ %$form ] )
|
||||
: HTTP::Request::Common::GET( $url )
|
||||
;
|
||||
$request->headers->user_agent('WebGUI');
|
||||
}
|
||||
return $request->to_psgi;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue