Changeset 13398
- Timestamp:
- 06/07/08 20:00:14 (5 years ago)
- Location:
- lang/perl/HTTP-Engine/branches/lazy_request/lib/HTTP/Engine
- Files:
-
- 3 modified
-
Request.pm (modified) (6 diffs)
-
RequestBuilder.pm (modified) (6 diffs)
-
Types/Core.pm (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lang/perl/HTTP-Engine/branches/lazy_request/lib/HTTP/Engine/Request.pm
r13397 r13398 8 8 use HTTP::Request; 9 9 10 sub BUILD { 11 my ( $self, $param ) = @_; 12 13 foreach my $field qw(base path) { 14 if ( my $val = $param->{$field} ) { 15 $self->$field($val); 16 } 17 } 18 } 19 10 20 has request_builder => ( 11 21 isa => "HTTP::Engine::RequestBuilder", … … 49 59 is => 'rw', 50 60 isa => 'HashRef', 51 default => sub { {} }, 52 ); 61 lazy_build => 1, 62 ); 63 64 sub _build_query_parameters { 65 my $self = shift; 66 $self->uri->query_form_hash; 67 } 53 68 54 69 # https or not? … … 63 78 isa => Uri, 64 79 coerce => 1, 65 ); 80 lazy_build => 1, 81 handles => [qw(base path)], 82 ); 83 84 sub _build_uri { 85 my $self = shift; 86 87 if ( my $rb = $self->request_builder ) { 88 $rb->_build_uri($self); 89 } else { 90 URI::WithBase->new; 91 } 92 } 66 93 67 94 has user => ( is => 'rw', ); … … 93 120 # Contains the URI base. This will always have a trailing slash. 94 121 # If your application was queried with the URI C<http://localhost:3000/some/path> then C<base> is C<http://localhost:3000/>. 95 has base => (96 is => 'rw',97 isa => Uri,98 trigger => sub {99 my $self = shift;100 101 if ( $self->uri ) {102 $self->path; # clear cache.103 }104 },105 );106 122 107 123 has hostname => ( … … 181 197 $self->parameters->{$field} = [@_]; 182 198 } 183 }184 185 186 sub path {187 my ($self, $params) = @_;188 189 if ($params) {190 $self->uri->path($params);191 } else {192 return $self->{path} if $self->{path};193 }194 195 my $path = $self->uri->path;196 my $location = $self->base->path;197 $path =~ s/^(\Q$location\E)?//;198 $path =~ s/^\///;199 $self->{path} = $path;200 201 return $path;202 199 } 203 200 … … 267 264 268 265 unless ($location =~ m!^https?://!) { 269 my $base = $self->base; 270 my $url = sprintf '%s://%s', $base->scheme, $base->host; 271 unless (($base->scheme eq 'http' && $base->port eq '80') || 272 ($base->scheme eq 'https' && $base->port eq '443')) { 273 $url .= ':' . $base->port; 274 } 275 $url .= $base->path; 276 $location = URI->new_abs($location, $url); 277 } 278 $location; 266 return URI->new( $location )->abs( $self->base ); 267 } else { 268 return $location; 269 } 279 270 } 280 271 -
lang/perl/HTTP-Engine/branches/lazy_request/lib/HTTP/Engine/RequestBuilder.pm
r13397 r13398 37 37 38 38 # do build. 39 for my $method (qw( connection query_parameters pathbody parameters uploads )) {39 for my $method (qw( connection body parameters uploads )) { 40 40 my $method = "_prepare_$method"; 41 41 $self->$method($context); … … 55 55 $req->secure(1) if $ENV{HTTPS} && uc $ENV{HTTPS} eq 'ON'; 56 56 $req->secure(1) if $ENV{SERVER_PORT} == 443; 57 }58 59 sub _prepare_query_parameters {60 my($self, $c) = @_;61 my $query_string = $ENV{QUERY_STRING};62 return unless63 defined $query_string && length($query_string);64 65 # replace semi-colons66 $query_string =~ s/;/&/g;67 68 my $uri = URI->new('', 'http');69 $uri->query($query_string);70 for my $key ( $uri->query_param ) {71 my @vals = $uri->query_param($key);72 $c->req->query_parameters->{$key} = @vals > 1 ? [@vals] : $vals[0];73 }74 57 } 75 58 … … 103 86 } 104 87 105 sub _prepare_path { 106 my($self, $c) = @_; 107 108 my $req = $c->req; 88 sub _build_uri { 89 my($self, $req) = @_; 109 90 110 91 my $scheme = $req->secure ? 'https' : 'http'; … … 132 113 # sanitize the URI 133 114 $uri = $uri->canonical; 134 $req->uri($uri);135 115 136 116 # set the base URI … … 139 119 my $base = $uri->clone; 140 120 $base->path_query($base_path); 141 $c->req->base($base); 121 122 return URI::WithBase->new($uri, $base); 142 123 } 143 124 … … 153 134 $req->http_body( HTTP::Body->new($type, $self->read_length) ); 154 135 $req->http_body->{tmpdir} = $self->upload_tmp if $self->upload_tmp; 136 137 $self->_read_to_end($c); 138 } 139 140 sub _read_to_end { 141 my ( $self, $c ) = @_; 155 142 156 143 if ($self->read_length > 0) { -
lang/perl/HTTP-Engine/branches/lazy_request/lib/HTTP/Engine/Types/Core.pm
r13357 r13398 8 8 use Class::MOP; 9 9 use URI; 10 use URI::WithBase; 11 use URI::QueryParam; 10 12 use HTTP::Headers; 11 13 … … 27 29 }; 28 30 29 class_type Uri, { class => "URI " };31 class_type Uri, { class => "URI::WithBase" }; 30 32 31 coerce Uri, from Str => via { URI ->new($_) };33 coerce Uri, from Str => via { URI::WithBase->new($_) }; 32 34 33 35 class_type Header, { class => "HTTP::Headers" };
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)