1 package Catalyst::Request;
3 use IO::Socket qw[AF_INET inet_aton];
14 use Catalyst::Exception;
15 use Catalyst::Request::PartData;
18 use namespace::clean -except => 'meta';
20 with 'MooseX::Emulate::Class::Accessor::Fast';
22 has env => (is => 'ro', writer => '_set_env', predicate => '_has_env');
23 # XXX Deprecated crap here - warn?
24 has action => (is => 'rw');
25 # XXX: Deprecated in docs ages ago (2006), deprecated with warning in 5.8000 due
26 # to confusion between Engines and Plugin::Authentication. Remove in 5.8100?
27 has user => (is => 'rw');
28 sub snippets { shift->captures(@_) }
30 has _read_position => (
31 # FIXME: work around Moose bug RT#75367
34 writer => '_set_read_position',
38 # FIXME: work around Moose bug RT#75367
43 $self->header('Content-Length') || 0;
48 has address => (is => 'rw');
49 has arguments => (is => 'rw', default => sub { [] });
50 has cookies => (is => 'ro', builder => 'prepare_cookies', lazy => 1);
55 if ( my $header = $self->header('Cookie') ) {
56 return { CGI::Simple::Cookie->parse($header) };
61 has query_keywords => (is => 'rw');
62 has match => (is => 'rw');
63 has method => (is => 'rw');
64 has protocol => (is => 'rw');
65 has query_parameters => (is => 'rw', lazy=>1, default => sub { shift->_use_hash_multivalue ? Hash::MultiValue->new : +{} });
66 has secure => (is => 'rw', default => 0);
67 has captures => (is => 'rw', default => sub { [] });
68 has uri => (is => 'rw', predicate => 'has_uri');
69 has remote_user => (is => 'rw');
72 isa => 'HTTP::Headers',
73 handles => [qw(content_encoding content_length content_type header referer user_agent)],
74 builder => 'prepare_headers',
82 my $headers = HTTP::Headers->new();
84 for my $header (keys %{ $env }) {
85 next unless $header =~ /^(HTTP|CONTENT|COOKIE)/i;
86 (my $field = $header) =~ s/^HTTPS?_//;
88 $headers->header($field => $env->{$header});
101 predicate=>'_has_io_fh',
103 builder=>'_build_io_fh');
107 return $self->env->{'psgix.io'}
109 $self->env->{'net.async.http.server.req'} &&
110 $self->env->{'net.async.http.server.req'}->stream) ## Until I can make ioasync cabal see the value of supportin psgix.io (jnap)
111 || die "Your Server does not support psgix.io";
114 has data_handlers => ( is=>'ro', isa=>'HashRef', default=>sub { +{} } );
119 builder=>'_build_body_data');
121 sub _build_body_data {
124 # Not sure if these returns should not be exceptions...
125 my $content_type = $self->content_type || return;
126 return unless ($self->method eq 'POST' || $self->method eq 'PUT' || $self->method eq 'PATCH');
128 my ($match) = grep { $content_type =~/$_/i }
129 keys(%{$self->data_handlers});
132 my $fh = $self->body;
134 return $self->data_handlers->{$match}->($fh, $self);
136 Catalyst::Exception->throw(
137 sprintf '%s does not have an available data handler. Valid data_handlers are %s.',
138 $content_type, join ', ', sort keys %{$self->data_handlers}
143 has _use_hash_multivalue => (
148 # Amount of data to read from input on each pass
149 our $CHUNKSIZE = 64 * 1024;
152 my ($self, $maxlength) = @_;
153 my $remaining = $self->_read_length - $self->_read_position;
154 $maxlength ||= $CHUNKSIZE;
156 # Are we done reading?
157 if ( $remaining <= 0 ) {
161 my $readlen = ( $remaining > $maxlength ) ? $maxlength : $remaining;
162 my $rc = $self->read_chunk( my $buffer, $readlen );
164 if (0 == $rc) { # Nothing more to read even though Content-Length
165 # said there should be.
168 $self->_set_read_position( $self->_read_position + $rc );
172 Catalyst::Exception->throw(
173 message => "Unknown error reading input: $!" );
179 return $self->env->{'psgi.input'}->read(@_);
182 has body_parameters => (
186 predicate => 'has_body_parameters',
187 builder => 'prepare_body_parameters',
193 default => sub { {} },
199 builder => '_build_parameters',
200 clearer => '_clear_parameters',
204 # - Can we lose the before modifiers which just call prepare_body ?
205 # they are wasteful, slow us down and feel cluttery.
207 # Can we make _body an attribute, have the rest of
208 # these lazy build from there and kill all the direct hash access
209 # in Catalyst.pm and Engine.pm?
211 sub prepare_parameters {
213 $self->_clear_parameters;
214 return $self->parameters;
217 sub _build_parameters {
220 my $body_parameters = $self->body_parameters;
221 my $query_parameters = $self->query_parameters;
223 if($self->_use_hash_multivalue) {
224 return Hash::MultiValue->new($query_parameters->flatten, $body_parameters->flatten);
227 # We copy, no references
228 foreach my $name (keys %$query_parameters) {
229 my $param = $query_parameters->{$name};
230 $parameters->{$name} = ref $param eq 'ARRAY' ? [ @$param ] : $param;
233 # Merge query and body parameters
234 foreach my $name (keys %$body_parameters) {
235 my $param = $body_parameters->{$name};
236 my @values = ref $param eq 'ARRAY' ? @$param : ($param);
237 if ( my $existing = $parameters->{$name} ) {
238 unshift(@values, (ref $existing eq 'ARRAY' ? @$existing : $existing));
240 $parameters->{$name} = @values > 1 ? \@values : $values[0];
247 predicate => '_has_uploadtmp',
253 # If previously applied middleware created the HTTP::Body object, then we
256 if(my $plack_body = $self->_has_env ? $self->env->{'plack.request.http.body'} : undef) {
257 $self->_body($plack_body);
258 $self->_body->cleanup(1);
262 # If there is nothing to read, set body to naught and return. This
263 # will cause all body code to be skipped
265 return $self->_body(0) unless my $length = $self->_read_length;
267 # Unless the body has already been set, create it. Not sure about this
268 # code, how else might it be set, but this was existing logic.
270 unless ($self->_body) {
271 my $type = $self->header('Content-Type');
272 $self->_body(HTTP::Body->new( $type, $length ));
273 $self->_body->cleanup(1);
275 # JNAP: I'm not sure this is doing what we expect, but it also doesn't
276 # seem to be hurting (seems ->_has_uploadtmp is true more than I would
279 $self->_body->tmpdir( $self->_uploadtmp )
280 if $self->_has_uploadtmp;
283 # Ok if we get this far, we have to read psgi.input into the new body
284 # object. Lets play nice with any plack app or other downstream, so
285 # we create a buffer unless one exists.
288 if ($self->env->{'psgix.input.buffered'}) {
289 # Be paranoid about previous psgi middleware or apps that read the
290 # input but didn't return the buffer to the start.
291 $self->env->{'psgi.input'}->seek(0, 0);
293 $stream_buffer = Stream::Buffered->new($length);
296 # Check for definedness as you could read '0'
297 while ( defined ( my $chunk = $self->read() ) ) {
298 $self->prepare_body_chunk($chunk);
299 next unless $stream_buffer;
301 $stream_buffer->print($chunk)
302 || die sprintf "Failed to write %d bytes to psgi.input file: $!", length( $chunk );
305 # Ok, we read the body. Lets play nice for any PSGI app down the pipe
307 if ($stream_buffer) {
308 $self->env->{'psgix.input.buffered'} = 1;
309 $self->env->{'psgi.input'} = $stream_buffer->rewind;
311 $self->env->{'psgi.input'}->seek(0, 0); # Reset the buffer for downstream middleware or apps
314 # paranoia against wrong Content-Length header
315 my $remaining = $length - $self->_read_position;
316 if ( $remaining > 0 ) {
317 Catalyst::Exception->throw("Wrong Content-Length value: $length" );
321 sub prepare_body_chunk {
322 my ( $self, $chunk ) = @_;
324 $self->_body->add($chunk);
327 sub prepare_body_parameters {
328 my ( $self, $c ) = @_;
329 return $self->body_parameters if $self->has_body_parameters;
330 $self->prepare_body if ! $self->_has_body;
332 unless($self->_body) {
333 my $return = $self->_use_hash_multivalue ? Hash::MultiValue->new : {};
334 $self->body_parameters($return);
339 my %part_data = %{$self->_body->part_data};
340 if(scalar %part_data && !$c->config->{skip_complex_post_part_handling}) {
341 foreach my $key (keys %part_data) {
342 my $proto_value = $part_data{$key};
343 my ($val, @extra) = (ref($proto_value)||'') eq 'ARRAY' ? @$proto_value : ($proto_value);
345 $key = $c->_handle_param_unicode_decoding($key)
346 if ($c and $c->encoding and !$c->config->{skip_body_param_unicode_decoding});
349 $params->{$key} = [map { Catalyst::Request::PartData->build_from_part_data($c, $_) } ($val,@extra)];
351 $params->{$key} = Catalyst::Request::PartData->build_from_part_data($c, $val);
355 $params = $self->_body->param;
357 # If we have an encoding configured (like UTF-8) in general we expect a client
358 # to POST with the encoding we fufilled the request in. Otherwise don't do any
359 # encoding (good change wide chars could be in HTML entity style llike the old
362 # so, now that HTTP::Body prepared the body params, we gotta 'walk' the structure
363 # and do any needed decoding.
365 # This only does something if the encoding is set via the encoding param. Remember
366 # this is assuming the client is not bad and responds with what you provided. In
367 # general you can just use utf8 and get away with it.
369 # I need to see if $c is here since this also doubles as a builder for the object :(
371 if($c and $c->encoding and !$c->config->{skip_body_param_unicode_decoding}) {
372 $params = $c->_handle_unicode_decoding($params);
376 my $return = $self->_use_hash_multivalue ?
377 Hash::MultiValue->from_mixed($params) :
380 $self->body_parameters($return) unless $self->has_body_parameters;
384 sub prepare_connection {
387 my $env = $self->env;
389 $self->address( $env->{REMOTE_ADDR} );
390 $self->hostname( $env->{REMOTE_HOST} )
391 if exists $env->{REMOTE_HOST};
392 $self->protocol( $env->{SERVER_PROTOCOL} );
393 $self->remote_user( $env->{REMOTE_USER} );
394 $self->method( $env->{REQUEST_METHOD} );
395 $self->secure( $env->{'psgi.url_scheme'} eq 'https' ? 1 : 0 );
398 # XXX - FIXME - method is here now, move this crap...
399 around parameters => sub {
400 my ($orig, $self, $params) = @_;
402 if ( !ref $params ) {
404 "Attempt to retrieve '$params' with req->params(), " .
405 "you probably meant to call req->param('$params')"
409 return $self->$orig($params);
420 return $self->path if $self->has_uri;
425 is => 'rw', clearer => '_clear_body', predicate => '_has_body',
427 # Eugh, ugly. Should just be able to rename accessor methods to 'body'
428 # and provide a custom reader..
431 $self->prepare_body unless $self->_has_body;
432 croak 'body is a reader' if scalar @_;
433 return blessed $self->_body ? $self->_body->body : $self->_body;
442 gethostbyaddr( inet_aton( $self->address ), AF_INET ) || $self->address
446 has _path => ( is => 'rw', predicate => '_has_path', clearer => '_clear_path' );
448 sub args { shift->arguments(@_) }
449 sub body_params { shift->body_parameters(@_) }
450 sub input { shift->body(@_) }
451 sub params { shift->parameters(@_) }
452 sub query_params { shift->query_parameters(@_) }
453 sub path_info { shift->path(@_) }
455 =for stopwords param params
459 Catalyst::Request - provides information about the current client request
464 $req->address eq "127.0.0.1";
470 $req->body_parameters;
471 $req->content_encoding;
472 $req->content_length;
480 $req->query_keywords;
488 $req->query_parameters;
500 See also L<Catalyst>, L<Catalyst::Request::Upload>.
504 This is the Catalyst Request class, which provides an interface to data for the
505 current client request. The request object is prepared by L<Catalyst::Engine>,
506 thus hiding the details of the particular engine implementation.
512 Returns the IP address of the client.
514 =head2 $req->arguments
516 Returns a reference to an array containing the arguments.
518 print $c->request->arguments->[0];
520 For example, if your action was
522 package MyApp::Controller::Foo;
528 and the URI for the request was C<http://.../foo/moose/bah>, the string C<bah>
529 would be the first and only argument.
531 Arguments get automatically URI-unescaped for you.
535 Shortcut for L</arguments>.
539 Contains the URI base. This will always have a trailing slash. Note that the
540 URI scheme (e.g., http vs. https) must be determined through heuristics;
541 depending on your server configuration, it may be incorrect. See $req->secure
544 If your application was queried with the URI
545 C<http://localhost:3000/some/path> then C<base> is C<http://localhost:3000/>.
549 Returns the message body of the request, as returned by L<HTTP::Body>: a string,
550 unless Content-Type is C<application/x-www-form-urlencoded>, C<text/xml>, or
551 C<multipart/form-data>, in which case a L<File::Temp> object is returned.
553 =head2 $req->body_data
555 Returns a Perl representation of POST/PUT body data that is not classic HTML
556 form data, such as JSON, XML, etc. By default, Catalyst will parse incoming
557 data of the type 'application/json' and return access to that data via this
558 method. You may define addition data_handlers via a global configuration
559 setting. See L<Catalyst\DATA HANDLERS> for more information.
561 If the POST is malformed in some way (such as undefined or not content that
562 matches the content-type) we raise a L<Catalyst::Exception> with the error
565 If the POSTed content type does not match an available data handler, this
566 will also raise an exception.
568 =head2 $req->body_parameters
570 Returns a reference to a hash containing body (POST) parameters. Values can
571 be either a scalar or an arrayref containing scalars.
573 print $c->request->body_parameters->{field};
574 print $c->request->body_parameters->{field}->[0];
576 These are the parameters from the POST part of the request, if any.
578 B<NOTE> If your POST is multipart, but contains non file upload parts (such
579 as an line part with an alternative encoding or content type) we do our best to
580 try and figure out how the value should be presented. If there's a specified character
581 set we will use that to decode rather than the default encoding set by the application.
582 However if there are complex headers and we cannot determine
583 the correct way to extra a meaningful value from the upload, in this case any
584 part like this will be represented as an instance of L<Catalyst::Request::PartData>.
586 Patches and review of this part of the code welcomed.
588 =head2 $req->body_params
590 Shortcut for body_parameters.
592 =head2 $req->content_encoding
594 Shortcut for $req->headers->content_encoding.
596 =head2 $req->content_length
598 Shortcut for $req->headers->content_length.
600 =head2 $req->content_type
602 Shortcut for $req->headers->content_type.
606 A convenient method to access $req->cookies.
608 $cookie = $c->request->cookie('name');
609 @cookies = $c->request->cookie;
617 return keys %{ $self->cookies };
624 unless ( exists $self->cookies->{$name} ) {
628 return $self->cookies->{$name};
634 Returns a reference to a hash containing the cookies.
636 print $c->request->cookies->{mycookie}->value;
638 The cookies in the hash are indexed by name, and the values are L<CGI::Simple::Cookie>
643 Shortcut for $req->headers->header.
647 Returns an L<HTTP::Headers> object containing the headers for the current request.
649 print $c->request->headers->header('X-Catalyst');
651 =head2 $req->hostname
653 Returns the hostname of the client. Use C<< $req->uri->host >> to get the hostname of the server.
657 Alias for $req->body.
659 =head2 $req->query_keywords
661 Contains the keywords portion of a query string, when no '=' signs are
664 http://localhost/path?some+keywords
666 $c->request->query_keywords will contain 'some keywords'
670 This contains the matching part of a Regex action. Otherwise
671 it returns the same as 'action', except for default actions,
672 which return an empty string.
676 Contains the request method (C<GET>, C<POST>, C<HEAD>, etc).
680 Returns GET and POST parameters with a CGI.pm-compatible param method. This
681 is an alternative method for accessing parameters in $c->req->parameters.
683 $value = $c->request->param( 'foo' );
684 @values = $c->request->param( 'foo' );
685 @params = $c->request->param;
687 Like L<CGI>, and B<unlike> earlier versions of Catalyst, passing multiple
688 arguments to this method, like this:
690 $c->request->param( 'foo', 'bar', 'gorch', 'quxx' );
692 will set the parameter C<foo> to the multiple values C<bar>, C<gorch> and
693 C<quxx>. Previously this would have added C<bar> as another value to C<foo>
694 (creating it if it didn't exist before), and C<quxx> as another value for
697 B<NOTE> this is considered a legacy interface and care should be taken when
698 using it. C<< scalar $c->req->param( 'foo' ) >> will return only the first
699 C<foo> param even if multiple are present; C<< $c->req->param( 'foo' ) >> will
700 return a list of as many are present, which can have unexpected consequences
701 when writing code of the form:
705 baz => $c->req->param( 'baz' ),
708 If multiple C<baz> parameters are provided this code might corrupt data or
709 cause a hash initialization error. For a more straightforward interface see
710 C<< $c->req->parameters >>.
712 B<NOTE> Interfaces like this, which are based on L<CGI> and the C<param> method
713 are known to cause demonstrated exploits. It is highly recommended that you
714 avoid using this method, and migrate existing code away from it. Here's a
715 whitepaper of the exploit:
717 L<http://blog.gerv.net/2014/10/new-class-of-vulnerability-in-perl-web-applications/>
719 B<NOTE> Further discussion on IRC indicate that the L<Catalyst> core team from 'back then'
720 were well aware of this hack and this is the main reason we added the new approach to
721 getting parameters in the first place.
723 Basically this is an exploit that takes advantage of how L<\param> will do one thing
724 in scalar context and another thing in list context. This is combined with how Perl
725 chooses to deal with duplicate keys in a hash definition by overwriting the value of
726 existing keys with a new value if the same key shows up again. Generally you will be
727 vulnerable to this exploit if you are using this method in a direct assignment in a
728 hash, such as with a L<DBIx::Class> create statement. For example, if you have
731 user?user=123&foo=a&foo=user&foo=456
733 You could end up with extra parameters injected into your method calls:
735 $c->model('User')->create({
736 user => $c->req->param('user'),
737 foo => $c->req->param('foo'),
740 Which would look like:
742 $c->model('User')->create({
744 foo => qw(a user 456),
747 (or to be absolutely clear if you are not seeing it):
749 $c->model('User')->create({
754 Possible remediations include scrubbing your parameters with a form validator like
755 L<HTML::FormHandler> or being careful to force scalar context using the scalar
758 $c->model('User')->create({
759 user => scalar($c->req->param('user')),
760 foo => scalar($c->req->param('foo')),
763 Upcoming versions of L<Catalyst> will disable this interface by default and require
764 you to positively enable it should you require it for backwards compatibility reasons.
772 return keys %{ $self->parameters };
775 # If anything in @_ is undef, carp about that, and remove it from
778 my @params = grep { defined($_) ? 1 : do {carp "You called ->params with an undefined value"; 0} } @_;
780 if ( @params == 1 ) {
782 defined(my $param = shift @params) ||
783 carp "You called ->params with an undefined value 2";
785 unless ( exists $self->parameters->{$param} ) {
786 return wantarray ? () : undef;
789 if ( ref $self->parameters->{$param} eq 'ARRAY' ) {
791 ? @{ $self->parameters->{$param} }
792 : $self->parameters->{$param}->[0];
796 ? ( $self->parameters->{$param} )
797 : $self->parameters->{$param};
800 elsif ( @params > 1 ) {
801 my $field = shift @params;
802 $self->parameters->{$field} = [@params];
806 =head2 $req->parameters
808 Returns a reference to a hash containing GET and POST parameters. Values can
809 be either a scalar or an arrayref containing scalars.
811 print $c->request->parameters->{field};
812 print $c->request->parameters->{field}->[0];
814 This is the combination of C<query_parameters> and C<body_parameters>.
818 Shortcut for $req->parameters.
822 Returns the path, i.e. the part of the URI after $req->base, for the current request.
824 http://localhost/path/foo
826 $c->request->path will contain 'path/foo'
828 =head2 $req->path_info
830 Alias for path, added for compatibility with L<CGI>.
835 my ( $self, @params ) = @_;
838 $self->uri->path(@params);
841 elsif ( $self->_has_path ) {
845 my $path = $self->uri->path;
846 my $location = $self->base->path;
847 $path =~ s/^(\Q$location\E)?//;
855 =head2 $req->protocol
857 Returns the protocol (HTTP/1.0 or HTTP/1.1) used for the current request.
859 =head2 $req->query_parameters
861 =head2 $req->query_params
863 Returns a reference to a hash containing query string (GET) parameters. Values can
864 be either a scalar or an arrayref containing scalars.
866 print $c->request->query_parameters->{field};
867 print $c->request->query_parameters->{field}->[0];
869 =head2 $req->read( [$maxlength] )
871 Reads a chunk of data from the request body. This method is intended to be
872 used in a while loop, reading $maxlength bytes on every call. $maxlength
873 defaults to the size of the request if not specified.
875 =head2 $req->read_chunk(\$buff, $max)
879 You have to set MyApp->config(parse_on_demand => 1) to use this directly.
883 Shortcut for $req->headers->referer. Returns the referring page.
887 Returns true or false, indicating whether the connection is secure
888 (https). The reliability of $req->secure may depend on your server
889 configuration; Catalyst relies on PSGI to determine whether or not a
890 request is secure (Catalyst looks at psgi.url_scheme), and different
891 PSGI servers may make this determination in different ways (as by
892 directly passing along information from the server, interpreting any of
893 several HTTP headers, or using heuristics of their own).
895 =head2 $req->captures
897 Returns a reference to an array containing captured args from chained
898 actions or regex captures.
900 my @captures = @{ $c->request->captures };
904 A convenient method to access $req->uploads.
906 $upload = $c->request->upload('field');
907 @uploads = $c->request->upload('field');
908 @fields = $c->request->upload;
910 for my $upload ( $c->request->upload('field') ) {
911 print $upload->filename;
920 return keys %{ $self->uploads };
927 unless ( exists $self->uploads->{$upload} ) {
928 return wantarray ? () : undef;
931 if ( ref $self->uploads->{$upload} eq 'ARRAY' ) {
933 ? @{ $self->uploads->{$upload} }
934 : $self->uploads->{$upload}->[0];
938 ? ( $self->uploads->{$upload} )
939 : $self->uploads->{$upload};
945 while ( my ( $field, $upload ) = splice( @_, 0, 2 ) ) {
947 if ( exists $self->uploads->{$field} ) {
948 for ( $self->uploads->{$field} ) {
949 $_ = [$_] unless ref($_) eq "ARRAY";
950 push( @$_, $upload );
954 $self->uploads->{$field} = $upload;
962 Returns a reference to a hash containing uploads. Values can be either a
963 L<Catalyst::Request::Upload> object, or an arrayref of
964 L<Catalyst::Request::Upload> objects.
966 my $upload = $c->request->uploads->{field};
967 my $upload = $c->request->uploads->{field}->[0];
971 Returns a L<URI> object for the current request. Stringifies to the URI text.
973 =head2 $req->mangle_params( { key => 'value' }, $appendmode);
975 Returns a hashref of parameters stemming from the current request's params,
976 plus the ones supplied. Keys for which no current param exists will be
977 added, keys with undefined values will be removed and keys with existing
978 params will be replaced. Note that you can supply a true value as the final
979 argument to change behavior with regards to existing parameters, appending
980 values rather than replacing them.
984 # URI query params foo=1
985 my $hashref = $req->mangle_params({ foo => 2 });
986 # Result is query params of foo=2
990 # URI query params foo=1
991 my $hashref = $req->mangle_params({ foo => 2 }, 1);
992 # Result is query params of foo=1&foo=2
994 This is the code behind C<uri_with>.
999 my ($self, $args, $append) = @_;
1001 carp('No arguments passed to mangle_params()') unless $args;
1003 foreach my $value ( values %$args ) {
1004 next unless defined $value;
1005 for ( ref $value eq 'ARRAY' ? @$value : $value ) {
1011 my %params = %{ $self->uri->query_form_hash };
1012 foreach my $key (keys %{ $args }) {
1013 my $val = $args->{$key};
1016 if($append && exists($params{$key})) {
1018 # This little bit of heaven handles appending a new value onto
1019 # an existing one regardless if the existing value is an array
1020 # or not, and regardless if the new value is an array or not
1022 ref($params{$key}) eq 'ARRAY' ? @{ $params{$key} } : $params{$key},
1023 ref($val) eq 'ARRAY' ? @{ $val } : $val
1027 $params{$key} = $val;
1031 # If the param wasn't defined then we delete it.
1032 delete($params{$key});
1040 =head2 $req->uri_with( { key => 'value' } );
1042 Returns a rewritten URI object for the current request. Key/value pairs
1043 passed in will override existing parameters. You can remove an existing
1044 parameter by passing in an undef value. Unmodified pairs will be
1047 You may also pass an optional second parameter that puts C<uri_with> into
1050 $req->uri_with( { key => 'value' }, { mode => 'append' } );
1052 See C<mangle_params> for an explanation of this behavior.
1057 my( $self, $args, $behavior) = @_;
1059 carp( 'No arguments passed to uri_with()' ) unless $args;
1062 if((ref($behavior) eq 'HASH') && defined($behavior->{mode}) && ($behavior->{mode} eq 'append')) {
1066 my $params = $self->mangle_params($args, $append);
1068 my $uri = $self->uri->clone;
1069 $uri->query_form($params);
1074 =head2 $req->remote_user
1076 Returns the value of the C<REMOTE_USER> environment variable.
1078 =head2 $req->user_agent
1080 Shortcut to $req->headers->user_agent. Returns the user agent (browser)
1085 Returns a psgix.io bidirectional socket, if your server supports one. Used for
1086 when you want to jailbreak out of PSGI and handle bidirectional client server
1087 communication manually, such as when you are using cometd or websockets.
1089 =head1 SETUP METHODS
1091 You should never need to call these yourself in application code,
1092 however they are useful if extending Catalyst by applying a request role.
1094 =head2 $self->prepare_headers()
1096 Sets up the C<< $res->headers >> accessor.
1098 =head2 $self->prepare_body()
1100 Sets up the body using L<HTTP::Body>
1102 =head2 $self->prepare_body_chunk()
1104 Add a chunk to the request body.
1106 =head2 $self->prepare_body_parameters()
1108 Sets up parameters from body.
1110 =head2 $self->prepare_cookies()
1112 Parse cookies from header. Sets up a L<CGI::Simple::Cookie> object.
1114 =head2 $self->prepare_connection()
1116 Sets up various fields in the request like the local and remote addresses,
1117 request method, hostname requested etc.
1119 =head2 $self->prepare_parameters()
1121 Ensures that the body has been parsed, then builds the parameters, which are
1122 combined from those in the request and those in the body.
1124 If parameters have already been set will clear the parameters and build them again.
1128 Access to the raw PSGI env.
1136 Catalyst Contributors, see Catalyst.pm
1140 This library is free software. You can redistribute it and/or modify
1141 it under the same terms as Perl itself.
1145 __PACKAGE__->meta->make_immutable;