diff options
author | Marius Halden <marius.h@lden.org> | 2015-08-26 13:43:10 +0200 |
---|---|---|
committer | Marius Halden <marius.h@lden.org> | 2015-08-26 13:43:10 +0200 |
commit | cc0acdd34052e79f3df368ac1f524de31df19a1b (patch) | |
tree | 505f561b5f16c5b78f07514e8c2b2bdc18fef51d /perllib/FixMyStreet/App.pm | |
parent | 1c5c685d0b0904e7ddc6e764e58e8fae08632d1d (diff) | |
parent | 6b84622fb7d58531baa7943abdcc7620999c34ee (diff) |
Merge tag 'v1.6.1' into fiksgatami-dev
Diffstat (limited to 'perllib/FixMyStreet/App.pm')
-rw-r--r-- | perllib/FixMyStreet/App.pm | 60 |
1 files changed, 54 insertions, 6 deletions
diff --git a/perllib/FixMyStreet/App.pm b/perllib/FixMyStreet/App.pm index 769a6bb8f..787755a05 100644 --- a/perllib/FixMyStreet/App.pm +++ b/perllib/FixMyStreet/App.pm @@ -89,15 +89,15 @@ __PACKAGE__->config( # Start the application __PACKAGE__->setup(); -# Due to some current issues with proxyings, need to manually -# tell the code we're secure if we are. +# If your site is secure but running behind a proxy, you might need to set the +# SECURE_PROXY_SSL_HEADER configuration variable so this can be spotted. after 'prepare_headers' => sub { my $self = shift; my $base_url = $self->config->{BASE_URL}; + my $ssl_header = $self->config->{SECURE_PROXY_SSL_HEADER}; my $host = $self->req->headers->header('Host'); - $self->req->secure( 1 ) if $base_url eq 'https://www.zueriwieneu.ch'; - $self->req->secure( 1 ) if $base_url eq 'https://www.fixmystreet.com' - && ( $host eq 'fix.bromley.gov.uk' || $host eq 'www.fixmystreet.com' ); + $self->req->secure(1) if $ssl_header && ref $ssl_header eq 'ARRAY' + && @$ssl_header == 2 && $self->req->header($ssl_header->[0]) eq $ssl_header->[1]; }; # set up DB handle for old code @@ -195,7 +195,7 @@ sub setup_request { Memcached::set_namespace( FixMyStreet->config('FMS_DB_NAME') . ":" ); - FixMyStreet::Map::set_map_class( $cobrand->map_type || $c->req->param('map_override') ); + FixMyStreet::Map::set_map_class( $cobrand->map_type || $c->get_param('map_override') ); unless ( FixMyStreet->config('MAPIT_URL') ) { my $port = $c->req->uri->port; @@ -529,6 +529,54 @@ sub is_abuser { return $c->model('DB::Abuse')->search( { email => [ $email, $domain ] } )->first; } +=head2 get_param + + $param = $c->get_param('name'); + +Return the parameter passed in the request, or undef if not present. Like +req->param() in a scalar context, this will return the first parameter if +multiple were provided; unlike req->param it will always return a scalar, +never a list, in order to avoid possible security issues. + +=cut + +sub get_param { + my ($c, $param) = @_; + my $value = $c->req->params->{$param}; + return $value->[0] if ref $value; + return $value; +} + +=head2 get_param_list + + @params = $c->get_param_list('name'); + +Return the parameters passed in the request, as a list. This will always return +a list, with an empty list if no parameter is present. + +=cut + +sub get_param_list { + my ($c, $param) = @_; + my $value = $c->req->params->{$param}; + return @$value if ref $value; + return ($value) if defined $value; + return (); +} + +=head2 set_param + + $c->set_param('name', 'My Name'); + +Sets the query parameter to the passed variable. + +=cut + +sub set_param { + my ($c, $param, $value) = @_; + $c->req->params->{$param} = $value; +} + =head1 SEE ALSO L<FixMyStreet::App::Controller::Root>, L<Catalyst> |