Changeset 16396

Show
Ignore:
Timestamp:
03/17/10 17:15:12 (6 months ago)
Author:
gariev
Message:

LJSUP-5445: update parsing post data.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branches/r63.1/cgi-bin/LJ/Request/Apache.pm

    r16394 r16396  
    502502    my $method = $r->method; 
    503503    return unless $method eq 'POST'; 
    504      
     504    my $host = $r->headers_in()->get("Host"); 
     505    my $uri = $r->uri; 
     506     
     507    ## apreq parses only this encoding methods. 
     508    my $content_type = $r->headers_in()->get("Content-Type"); 
     509    if ($content_type !~ m!^application/x-www-form-urlencoded!i && 
     510        $content_type !~ m!^multipart/form-data!i) 
     511    { 
     512        ## hack: if this is a POST request, and App layer asked us 
     513        ## for params, pretend that encoding is default 'application/x-www-form-urlencoded' 
     514        ## Some clients that use flat protocol issue malformed headers, 
     515        ## so don't even make a warn. 
     516        if ($uri ne '/interface/flat') { 
     517            warn "Changing content-type of POST ($host$uri) from $content_type to default"; 
     518        } 
     519        $r->headers_in()->set("Content-Type", "application/x-www-form-urlencoded"); 
     520    } 
     521    
    505522    my $qs = $r->args; 
    506523    $r->args(''); # to exclude GET params from Apache::Request object. 
    507524                  # it allows us to separate GET params and POST params. 
    508525                  # otherwise Apache::Request's "parms" method returns them together. 
    509      
    510     ## apreq parses only this encoding methods. 
    511     my $content_type = $r->headers_in()->get("Content-Type"); 
    512     if ($content_type =~ m!^application/x-www-form-urlencoded!i or 
    513         $content_type =~ m!^multipart/form-data!i 
    514     ){ 
    515         my $parse_res = $instance->{apr}->parse; 
    516         if ($parse_res eq OK){ 
    517             $instance->{post_parsed_successfully} = 1; 
    518         } else { 
    519             $instance->{post_parsed_successfully} = 0; 
    520             warn "Can't parse post data: content-type=" . $r->headers_in()->get("Content-Type") . "  uri=" . $r->uri . "?" . $qs; 
    521         } 
    522     } 
    523      
     526 
     527    my $parse_res = $instance->{apr}->parse; 
    524528    # set original QUERY_STRING back 
    525529    $r->args($qs); 
    526  
    527     unless ($instance->{post_parsed_successfully}) { 
    528         my $r = $instance->{r}; 
    529         my $content_type = $r->headers_in()->get("Content-Type"); 
    530         my $host = $r->headers_in()->get("Host"); 
    531         my $uri = $r->uri;  
    532         warn "App has requested POST params that were not parsed. URI=$host/$uri, Content-Type=$content_type"; 
     530     
     531    if (!$parse_res eq OK) { 
     532        warn "Can't parse POST data ($host$uri), Content-Type=$content_type"; 
    533533        return; 
    534534    } 
    535  
     535     
    536536    my @params = (); 
    537537    foreach my $name ($instance->{apr}->param){ 
     
    540540        } 
    541541    } 
    542  
    543542    return @params; 
    544543}