Skip to content

Commit

Permalink
Item1471: major refactorings done. Next step: CGI support.
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.foswiki.org/trunk/HTTPEngineContrib@5694 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
GilmarSantosJr authored and GilmarSantosJr committed Dec 1, 2009
1 parent 9586a42 commit 59c8c07
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 30 deletions.
7 changes: 6 additions & 1 deletion lib/Foswiki/Engine/HTTP.pm
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,12 @@ sub prepareBody {
my ( $this, $req ) = @_;

return unless $this->{args}{headers}->content_length();
$this->{body} = $this->{args}{http}->readBody( $this->{args}{headers} );
$this->{body} = Foswiki::Engine::HTTP::Util::readBody(
$this->{args}{headers},
$this->{args}{input},
$this->{args}{timeleft}
);
delete $this->{args}{input};
}

sub prepareBodyParameters {
Expand Down
50 changes: 29 additions & 21 deletions lib/Foswiki/Engine/HTTP/Native.pm
Original file line number Diff line number Diff line change
@@ -1,36 +1,44 @@
package Foswiki::Engine::HTTP::Native;
use strict;

use Foswiki;
use Foswiki::UI;

my @sorted_actions = ();

$Foswiki::cfg{ScriptUrlPath} =~ s{/+$}{};
BEGIN {
eval {
require Foswiki;
require Foswiki::UI;
};
}

@sorted_actions =
map { { action => $_, path => $Foswiki::cfg{ScriptUrlPaths}{$_} } } sort {
length( $Foswiki::cfg{ScriptUrlPaths}{$b} ) <=>
length( $Foswiki::cfg{ScriptUrlPaths}{$a} )
} keys %{ $Foswiki::cfg{ScriptUrlPaths} }
if exists $Foswiki::cfg{ScriptUrlPaths};
$Foswiki::cfg{ScriptUrlPath} =~ s{/+$}{}
if defined $Foswiki::cfg{ScriptUrlPath};

sub existsAction {
return
defined $Foswiki::cfg{SwitchBoard} && $Foswiki::cfg{SwitchBoard}{ $_[0] };
}

sub shorterUrlPaths {
my @sorted_actions =
map { { action => $_, path => $Foswiki::cfg{ScriptUrlPaths}{$_} } } sort {
length( $Foswiki::cfg{ScriptUrlPaths}{$b} ) <=>
length( $Foswiki::cfg{ScriptUrlPaths}{$a} )
} keys %{ $Foswiki::cfg{ScriptUrlPaths} }
if exists $Foswiki::cfg{ScriptUrlPaths};

return @sorted_actions;
}

sub handleFoswikiAction {
sub new {
my $class = shift;
my $this = bless {@_}, ref($class) || $class;
return $this;
}

sub send_response {
my $this = shift;
my %args = @_; # method, uri_ref, proto, action, headers,
# path_info_ref, query_string_ref

my $engine = $this->{server}{engine_obj};
$engine->{args} = \%args;
$engine->{args}{server_port} = $this->{server}{port};
$engine->{args}{http} = $this;
$engine->{client} = $this->{server}{client};

my $engine = $Foswiki::engine;
$engine->{args} = { %{$this} };
$engine->{client} = shift;
my $req = $engine->prepare();
if ( UNIVERSAL::isa( $req, 'Foswiki::Request' ) ) {
my $res = Foswiki::UI::handleRequest($req);
Expand Down
3 changes: 3 additions & 0 deletions lib/Foswiki/Engine/HTTP/Server.pm
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,9 @@ sub process_request {
path_info_ref => \$path_info,
query_string_ref => \$query_string,
server_port => $this->{server}{port},
input => $this->{foswiki}{input},
timeleft => $this->{foswiki}{timeleft} +
$this->{server}{read_body_timeout},
);
}
elsif ( my @actions = Foswiki::Engine::HTTP::Native::shorterUrlPaths() )
Expand Down
13 changes: 5 additions & 8 deletions lib/Foswiki/Engine/HTTP/Util.pm
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,14 @@ sub readHeader {
}

sub readBody {
my ( $this, $headers ) = @_;
my ( $fd, $headers, $input_ref, $timeleft ) = @_;

my $body = HTTP::Body->new( $headers->header('Content-Type'),
$headers->content_length );
$body->add( $this->{foswiki}{buffer} );
my $bytes_read = length( $this->{foswiki}{buffer} );
delete $this->{foswiki}{buffer};
$body->add( $$input_ref );
my $bytes_read = length( $$input_ref );

my $timeleft =
$this->{server}{read_body_timeout} + $this->{foswiki}{timeleft};
my $sel = IO::Select->new( $this->{server}{client} );
my $sel = IO::Select->new( $fd );

while ( $bytes_read < $headers->content_length && $timeleft >= 0 ) {
my $now = time;
Expand All @@ -110,7 +107,7 @@ sub readBody {
next if $! == EINTR;
throw Error::Simple("EBADF: $!");
}
my $rv = sysread( $this->{server}{client}, my ($buffer), 4096 );
my $rv = sysread( $fd, my ($buffer), 4096 );
unless ( defined $rv ) {
next if $! == EINTR || $! == EAGAIN || $! == EWOULDBLOCK;
throw Error::Simple("EBADF: $!");
Expand Down

0 comments on commit 59c8c07

Please sign in to comment.