Skip to content

Commit

Permalink
Merge branch 'master' of git@github.com:miyagawa/Plack into impl-prefork
Browse files Browse the repository at this point in the history
  • Loading branch information
kazuho committed Oct 1, 2009
2 parents d9e4502 + c23530c commit 0b8a70d
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Makefile.PL
Expand Up @@ -10,7 +10,7 @@ requires 'LWP'; # HTTP::Status, HTTP::Headers and HTTP::Request
requires 'HTTP::Body';
requires 'URI';
requires 'HTTP::Request::AsCGI';
requires 'HTTP::Parser::XS', 0.02;
requires 'HTTP::Parser::XS', 0.03;
requires 'CGI::Simple::Cookie'; # Plack::Response
requires 'Pod::Usage'; # plackup

Expand Down
3 changes: 2 additions & 1 deletion eg/dot-psgi/frameworks/Maypole.psgi
@@ -1,4 +1,5 @@
use BeerDB;
use Maypole::PSGI;

my $handler = sub { Maypole::PSGI->run('BeerDB', @_) };
my $app = Maypole::PSGI->new('BeerDB');
my $handler = sub { $app->run(@_) };
5 changes: 5 additions & 0 deletions eg/dot-psgi/frameworks/Mojo.psgi
@@ -0,0 +1,5 @@
use MyMojoApp;
use Mojo::Server::PSGI;

$ENV{MOJO_APP} = 'MyMojoApp';
my $handler = sub { Mojo::Server::PSGI->new->run(@_) };
1 change: 1 addition & 0 deletions lib/Plack/HTTPParser/PP.pm
Expand Up @@ -49,6 +49,7 @@ sub _parse_header {

$env->{REQUEST_METHOD} = $method;
$env->{SERVER_PROTOCOL} = "HTTP/$major.$minor";
$env->{REQUEST_URI} = $uri;

my($path, $query) = ( $uri =~ /^([^?]*)(?:\?(.*))?$/s );
$env->{PATH_INFO} = URI::Escape::uri_unescape($path);
Expand Down
2 changes: 1 addition & 1 deletion lib/Plack/Server/CGI.pm
Expand Up @@ -10,7 +10,7 @@ sub run {
my ($self, $app) = @_;
my %env;
while (my ($k, $v) = each %ENV) {
next unless $k =~ qr/^(?:REQUEST_METHOD|SCRIPT_NAME|PATH_INFO|QUERY_STRING|SERVER_NAME|SERVER_PORT|SERVER_PROTOCOL|CONTENT_LENGTH|CONTENT_TYPE|REMOTE_ADDR)$|^HTTP_/;
next unless $k =~ qr/^(?:REQUEST_METHOD|SCRIPT_NAME|PATH_INFO|QUERY_STRING|SERVER_NAME|SERVER_PORT|SERVER_PROTOCOL|CONTENT_LENGTH|CONTENT_TYPE|REMOTE_ADDR|REQUEST_URI)$|^HTTP_/;
$env{$k} = $v;
}
$env{'HTTP_COOKIE'} ||= $ENV{COOKIE};
Expand Down
61 changes: 61 additions & 0 deletions lib/Plack/Server/FCGI.pm
Expand Up @@ -126,3 +126,64 @@ sub daemon_detach {
}

1;

__END__
=head1 SYNOPSIS
my $server = Plack::Server::FCGI->new(
nproc => $num_proc,
listen => $listen,
detach => 1,
);
$server->run($app);
Starts the FastCGI server. If C<$listen> is set, then it specifies a
location to listen for FastCGI requests;
=head2 OPTIONS
=over 4
=item listen
listen => '/path/to/socket'
listen => ':8080'
Listen on a socket path, hostname:port, or :port.
=item port
listen via TCP on port on all interfaces (Same as C<< listen => ":$port" >>)
=item leave_umask
Set to 1 to disable setting umask to 0 for socket open
=item nointr
Do not allow the listener to be interrupted by Ctrl+C
=item nproc
Specify a number of processes for FCGI::ProcManager
=item pidfile
Specify a filename for the pid file
=item manager
Specify a FCGI::ProcManager sub-class
=item detach
Detach from console
=item keep_stderr
Send STDERR to STDOUT instead of the webserver
=back
=cut
2 changes: 2 additions & 0 deletions lib/Plack/Server/Mojo.pm
Expand Up @@ -3,6 +3,7 @@ use strict;
use warnings;
use base qw(Mojo::Base);
use Plack::Util;
use URI;
use URI::Escape;

__PACKAGE__->attr([ 'host', 'port' ]);
Expand Down Expand Up @@ -39,6 +40,7 @@ sub handler {
my %env;
$env{REQUEST_METHOD} = $tx->req->method;
$env{SCRIPT_NAME} = "";
$env{REQUEST_URI} = URI->new($tx->req->url)->path_query;
$env{PATH_INFO} = URI::Escape::uri_unescape($tx->req->url->path);
$env{QUERY_STRING} = $tx->req->url->query->to_string;
$env{SERVER_NAME} = $mojo_daemon->address;
Expand Down
2 changes: 1 addition & 1 deletion lib/Plack/Server/ServerSimple.pm
Expand Up @@ -33,7 +33,7 @@ sub handler {

my %env;
while (my ($k, $v) = each %ENV) {
next unless $k =~ qr/^(?:REQUEST_METHOD|PATH_INFO|QUERY_STRING|SERVER_NAME|SERVER_PORT|SERVER_PROTOCOL|CONTENT_LENGTH|CONTENT_TYPE|REMOTE_ADDR)$|^HTTP_/;
next unless $k =~ qr/^(?:REQUEST_METHOD|PATH_INFO|QUERY_STRING|REQUEST_URI|SERVER_NAME|SERVER_PORT|SERVER_PROTOCOL|CONTENT_LENGTH|CONTENT_TYPE|REMOTE_ADDR)$|^HTTP_/;
$env{$k} = $v;
}
$env{'CONTENT_LENGTH'} = $ENV{CONTENT_LENGTH};
Expand Down
17 changes: 17 additions & 0 deletions lib/Plack/Test/Suite.pm
Expand Up @@ -446,6 +446,23 @@ our @TEST = (
ok ! defined $res->header('transfer_encoding'), "No Transfer-Encoding";
},
],
[
'REQUEST_URI is set',
sub {
my $port = $_[0] || 80;
HTTP::Request->new(
GET => "http://127.0.0.1:$port/foo/bar%20baz?x=a",
);
},
sub {
my $env = shift;
return [ 200, [ 'Content-Type' => 'text/plain' ], [ $env->{REQUEST_URI} ] ];
},
sub {
my $res = shift;
is $res->content, '/foo/bar%20baz?x=a';
},
],
);

for my $test (@TEST) {
Expand Down

0 comments on commit 0b8a70d

Please sign in to comment.