Ginger
view release on metacpan or search on metacpan
lib/Ginger/Reference/Request/IO/Mongrel2.pm view on Meta::CPAN
my $rman = $self->{'request_man'};
my $incoming = $self->{'incoming'};
my $outgoing = $self->{'outgoing'};
#my $sid = $server->{'id'};
#print "Server: $sid - $tid\n";
my $buffer = '';
while( 1 ) {
my $part;
zmq_recv( $incoming, $part, 32768 ); # TODO: the size should be configurable
$buffer .= $part;
my $rc = zmq_getsockopt( $incoming, ZMQ_RCVMORE );
last if( !$rc );
print "Extra part; size of part1 = " . length( $part ) . "\n";
}
#print "Sid: $sid\n";
$buffer =~ m/^([^ ]+) ([^ ]+) ([^ ]+) (.+)$/s;
my $sender = $1;
my $id = $2;
my $path = $3;
my $data = $4;
my $type = 'get';
#print "Sending: $sender Id $id\n";
# $data =~ s/\0*$//; remove the null from the end for printing more easily
$data =~ m/^([0-9]+):/;
my $tnetlen = $1;
my $lenlen = length( $tnetlen );
my $extra = length( $data ) - ( $tnetlen + $lenlen + 2 );
my $post = '';
my $postvars = {};
if( $extra > 0 ) {
my $xstr = substr( $data, $tnetlen + $lenlen + 2 );
$xstr =~ s/,\0*$//;
if( $xstr eq '0:' ) {
}
elsif( $xstr eq '21:{"type":"disconnect"}' ) {
$type = "disconnect_notice";
#print "Disconnect of $id\n";
return; # TODO; pass notice on to routing to potentially terminate long running reports
}
else {
$post = $xstr;
$post =~ s/^([0-9]+)://;
}
}
my $hash = decode_tnetstrings( $data );
my $queryhash = 0;
if( $hash && defined $hash->{'QUERY'} ) {
$queryhash = url2hash( $hash->{'QUERY'} );
}
my $content_type = $hash->{'content-type'};
if( $content_type && $content_type =~ m|^multipart/form-data; boundary=(.+)$| ) {
my $bound = "--$1";#\r\n
if( $hash->{'x-mongrel2-upload-start'} ) {
if( ! $hash->{'x-mongrel2-upload-done'} ) {
$type = "largepost_notice";#$hash->{'x-mongrel2-upload-start'};
my $postid;
if( $queryhash && ( $postid = $queryhash->{'postid'} ) ) {
# store off the temp file location with the postid so that it can be retrieved by a later status check
# TODO
}
# potentially it is pointless to pass the upload start notice on to routing,
# but current we are doing so, comment out the following line to avoid passing it on
# next;
}
else {
$type = "largepost";
# open the file and parse it
my $tmpfile = $hash->{'x-mongrel2-upload-start'};
process_postfile( $postvars, $bound, $tmpfile );
}
}
else {
$type = 'post';
my @postarr = split( $bound, $post );
shift @postarr;
while( @postarr ) {
my $part = shift @postarr;
last if( $part =~ m"^--" );
my $parthash = process_multipart( $part );
my $partname = $parthash->{'name'};
if( !@{$parthash->{'headers'}} ) {
$postvars->{ $partname } = $parthash->{'body'};
}
else {
$postvars->{ $partname } = $parthash;
}
}
}
}
elsif( $hash->{'METHOD'} eq 'POST' ) {
$type = 'post';
$postvars = url2hash( $post );
}
my $session = 0;
my $r = $rman->new_request(
path => $path,
query => $queryhash,
postvars => $postvars,
id => $id,
ip => $hash->{'x-forwarded-for'},
type => $type # either 'post', 'get', or 'disconnect_notice'
);
$log->{'r'} = $r;
$log->note( text => "Recieved request to $path");
my $cookieman = $r->get_mod( mod => 'cookie_man' );
( run in 2.203 seconds using v1.01-cache-2.11-cpan-524268b4103 )