| 34 | | # warn "ACCEPT FROM $remote_address, $remote_port"; |
| | 37 | # Filter::HTTPD sometimes generates HTTP::Response objects. |
| | 38 | # They indicate (and contain the response for) errors that occur |
| | 39 | # while parsing the client's HTTP request. It's easiest to send |
| | 40 | # the responses as they are and finish up. |
| | 41 | if ( $request->isa('HTTP::Response') ) { |
| | 42 | $heap->{client}->put($request); |
| | 43 | $kernel->yield('shutdown'); |
| | 44 | return; |
| | 45 | } |
| 36 | | local %ENV = ( |
| 37 | | %init_env, |
| 38 | | SERVER_SOFTWARE => __PACKAGE__, |
| 39 | | GATEWAY_INTERFACE => 'CGI/1.1', |
| 40 | | ); |
| 41 | | |
| 42 | | $ENV{REMOTE_ADDR} = $remote_address; |
| 43 | | $ENV{REMOTE_PORT} = $remote_port; |
| 44 | | |
| 45 | | local *STDIN = $socket; |
| 46 | | local *STDOUT = $socket; |
| 47 | | select STDOUT; |
| 48 | | do { |
| 49 | | my ( $method, $request_uri, $proto ) = HTTP::Server::Simple->parse_request(); |
| 50 | | $proto ||= 'HTTP/0.9'; |
| 51 | | @ENV{qw/REQUEST_METHOD SERVER_PROTOCOL/} = ($method, $proto); |
| 52 | | my @uri_split = ( $request_uri =~ /([^?]*)(?:\?(.*))?/s ); # split at ? |
| 53 | | $ENV{PATH_INFO} = shift @uri_split; |
| 54 | | $ENV{QUERY_STRING} = shift @uri_split if @uri_split && defined $uri_split[0]; |
| 55 | | }; |
| 56 | | do { |
| 57 | | my $headers = HTTP::Server::Simple->parse_headers() or die "bad request"; |
| 58 | | while ( my ( $tag, $value ) = splice @$headers, 0, 2 ) { |
| 59 | | $tag = uc($tag); |
| 60 | | $tag =~ s/^COOKIES$/COOKIE/; |
| 61 | | $tag =~ s/-/_/g; |
| 62 | | $tag = "HTTP_" . $tag |
| 63 | | unless $tag =~ m/^(?:CONTENT_(?:LENGTH|TYPE)|COOKIE)$/; |
| 64 | | |
| 65 | | if ( exists $ENV{$tag} ) { |
| 66 | | $ENV{$tag} .= "; $value"; |
| 67 | | } |
| 68 | | else { |
| 69 | | $ENV{$tag} = $value; |
| 70 | | } |
| 71 | | } |
| 72 | | }; |
| 73 | | $ENV{SERVER_PORT} ||= $self->port; |
| | 47 | # follow is normal workflow. |
| | 48 | my $ascgi = HTTP::Request::AsCGI->new($request)->setup; |