Changeset 17
- Timestamp:
- 10/30/07 21:17:23 (6 years ago)
- Files:
-
- trunk/lib/Mungo.pm (modified) (3 diffs)
- trunk/lib/Mungo/Cookie.pm (modified) (3 diffs)
- trunk/lib/Mungo/MultipartFormData.pm (modified) (2 diffs)
- trunk/lib/Mungo/Request.pm (modified) (3 diffs)
- trunk/lib/Mungo/Response.pm (modified) (3 diffs)
- trunk/tests/pages/fileupload.asp (modified) (1 diff)
- trunk/tests/pages/qs.asp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/lib/Mungo.pm
r16 r17 7 7 use strict; 8 8 use IO::File; 9 use Apache; 10 use Apache::Constants qw( OK NOT_FOUND ); 9 eval " 10 use Apache2::RequestRec; 11 use Apache2::RequestUtil; 12 use Apache2::Const qw ( OK NOT_FOUND ); 13 "; 14 if($@) { 15 print STDERR "mod_perl2 not found: $@"; 16 eval " 17 use Apache; 18 use Apache::Constants qw( OK NOT_FOUND ); 19 "; 20 die $@ if $@; 21 } 11 22 use MIME::Base64 qw/encode_base64 decode_base64/; 12 23 use Data::Dumper; … … 79 90 if($name =~ /Mungo::FilePage::([^:]+)::__content/) { 80 91 my $filename = decode_base64($1); 81 my $r = Apache->request();92 my $r = $self->{'Apache::Request'}; 82 93 if(UNIVERSAL::can($r, 'document_root')) { 83 94 my $base = $r->document_root(); … … 211 222 sub handler($$) { 212 223 my ($self, $r) = @_; 224 if (ref $self eq 'Apache2::RequestRec') { 225 $r = $self; 226 $self = __PACKAGE__; 227 } 213 228 # Short circuit if we can't fine the file. 214 return NOT_FOUND if(! -r $r->filename);229 return NOT_FOUND() if(! -r $r->filename); 215 230 216 231 $self = $self->new($r) unless(ref $self); trunk/lib/Mungo/Cookie.pm
r2 r17 7 7 use strict; 8 8 use Mungo::Utils; 9 eval "use APR::Table;"; 9 10 10 11 my %reserved = ( … … 28 29 my $class = shift; 29 30 my $arg = shift; 30 my $cstr = (ref $arg && UNIVERSAL::can($arg, 'header_in')) ? # pull from 31 $arg->header_in('Cookie') : # Apache::Request 32 $arg; # or a passed string 31 my $cstr = (ref $arg && UNIVERSAL::can($arg, 'headers_in')) ? # pull from 32 $arg->headers_in->get('Cookie') : # Apache2::RequestRec 33 (ref $arg && UNIVERSAL::can($arg, 'header_in')) ? 34 $arg->header_in('Cookie') : # Apache::Request 35 $arg; # or a passed string 33 36 my $self = bless {}, $class; 34 37 foreach my $cookie (split /;\s*/, $cstr) { # ; seperated cookies … … 99 102 } 100 103 die __PACKAGE__ . 101 "->inject_header requires Apache::Request or Mungo::Response" 102 if(!$r || !UNIVERSAL::can($r, 'header_out')); 104 "->inject_header requires Apache2::RequestRec or Apache::Request or Mungo::Response" 105 if(!$r || (!UNIVERSAL::can($r, 'headers_out') && 106 !UNIVERSAL::can($r, 'header_out'))); 103 107 # $r is our Apache::Request at this point 104 108 while(my ($cname, $info) = each %$self) { 105 $r->header_out('Set-Cookie', $self->make_cookie_string($cname, $info)); 109 my $cookiestr = $self->make_cookie_string($cname, $info); 110 $r->can('headers_out') ? 111 $r->headers_out->add('Set-Cookie', $cookiestr) : 112 $r->header_out('Set-Cookie', $cookiestr); 106 113 } 107 114 return; trunk/lib/Mungo/MultipartFormData.pm
r11 r17 9 9 use Mungo; 10 10 use Mungo::Request; 11 eval "use Apache2::RequestIO;"; 11 12 12 13 sub new { … … 21 22 $self->{$part->{name}} = $part; 22 23 # Make this payload into an IO::Scalar 23 if( $part->{payload}) {24 if(exists($part->{payload})) { 24 25 $part->{handle} = IO::Scalar->new(\$part->{payload}); 25 26 delete $part->{payload}; 26 27 } 27 $part->{handle}->seek(0,0) ;28 $part->{handle}->seek(0,0) if(UNIVERSAL::can($part->{handle}, 'seek')); 28 29 } 29 30 else { trunk/lib/Mungo/Request.pm
r13 r17 8 8 use Mungo::Cookie; 9 9 use Mungo::MultipartFormData; 10 eval "use APR::Table;"; 10 11 our $AUTOLOAD; 11 12 … … 21 22 'Mungo' => $parent, 22 23 ); 23 my $cl = $r->header_in('Content-Length'); 24 my $ct = $r->header_in('Content-Type'); 24 my $cl = $r->can('headers_in') ? $r->headers_in->get('Content-length') : 25 $r->header_in('Content-length'); 26 my $ct = $r->can('headers_in') ? $r->headers_in->get('Content-Type') : 27 $r->header_in('Content-Type'); 25 28 if($r->method eq 'POST' && $cl) { 26 29 $core_data{TotalBytes} = $cl; … … 63 66 sub QueryString { 64 67 my $self = shift; 65 my %qs = $self->{'Mungo'}->{'Apache::Request'}->args; 68 my (@params) = $self->{'Mungo'}->{'Apache::Request'}->args; 69 my %qs; 70 if(@params == 1) { 71 # in mod_perl2 ->args is just a string 72 %qs = (map { (split /=/, $_, 2) } (split /&/, $params[0])); 73 } 74 else { 75 # mod_perl1 splits it up for us 76 %qs = @params; 77 } 66 78 return exists($qs{$_[0]})?$qs{$_[0]}:undef if(@_); 67 79 return %qs if wantarray; trunk/lib/Mungo/Response.pm
r15 r17 69 69 } 70 70 else { 71 $r->header_out('Cache-Control', $self->{CacheControl}); 71 if($r->can('headers_out')) { 72 $r->headers_out->set('Cache-Control' => $self->{CacheControl}); 73 } 74 else { 75 $r->header_out('Cache-Control' => $self->{CacheControl}); 76 } 72 77 } 73 78 $self->{Cookies}->inject_headers($r); 74 79 $r->status($self->{Status}); 75 $r->send_http_header($self->{ContentType}); 80 $r->can('send_http_header') ? 81 $r->send_http_header($self->{ContentType}) : 82 $r->content_type($self->{ContentType});; 76 83 } 77 84 … … 100 107 my $r = $self->{'Apache::Request'}; 101 108 die "Headers already sent." if($self->{'__HEADERS_SENT__'}); 102 $r-> header_out(@_);109 $r->can('headers_out') ? $r->headers_out->set(@_) : $r->header_out(@_); 103 110 } 104 111 sub Cookies { … … 113 120 die "Cannot redirect, headers already sent\n" if($self->{'__HEADERS_SENT__'}); 114 121 $self->{Status} = shift || 302; 115 $self->{'Apache::Request'}->header_out('Location', $url); 122 my $r = $self->{'Apache::Request'}; 123 $r->can('headers_out') ? $r->headers_out->set('Location', $url) : 124 $r->header_out('Location', $url); 116 125 $self->send_http_header(); 117 126 $self->End(); trunk/tests/pages/fileupload.asp
r2 r17 14 14 use Data::Dumper; 15 15 print Dumper($a = $Request->Form()); 16 17 my $up1 = $Request->Form('upfile1'); 18 if($up1) { 19 my $fh = $up1->{handle}; 20 my $length = 0; 21 while(<$fh>) { 22 $length += length($_); 23 } 24 print "Length of upfile1: $length\n"; 25 } 16 26 %> 17 27 </pre> trunk/tests/pages/qs.asp
r2 r17 21 21 print Dumper(%qs_hash); 22 22 23 print "a=".$Request->QueryString('a')."\n";24 23 %> 25 24 </pre>
