]> bicyclesonthemoon.info Git - yplom/proxy/commitdiff
Fixed header processing.
authorb <b@05ce6ebb-7522-4a6e-a768-0026ae12be9f>
Fri, 13 Nov 2015 18:13:10 +0000 (18:13 +0000)
committerb <b@05ce6ebb-7522-4a6e-a768-0026ae12be9f>
Fri, 13 Nov 2015 18:13:10 +0000 (18:13 +0000)
git-svn-id: svn://botcastle1b/yplom/proxy@7 05ce6ebb-7522-4a6e-a768-0026ae12be9f

proxy.1.pl

index ad41fa31aae43a121f7feb65cb235b0cfc40d637..e86d433b68aeeee1416038198eaf1691dda2c8df 100755 (executable)
@@ -85,7 +85,6 @@ sub proxy {
                $uppath=$temppath.'u';
        } while (( -e $headpath) or ( -e $downpath) or ( -e $uppath));
        
-       # @curl_arg=(CURL_PATH,'-o',$downpath,'-D',$headpath); #-s
        @curl_arg=(CURL_PATH,'-i','-#'); #-s
 
        if ($ENV{'REQUEST_METHOD'} eq 'HEAD'){
@@ -104,32 +103,44 @@ sub proxy {
                        }
                }
                close ($upfile);
+               $craetedup=1;
                
                push @curl_arg, '--data-binary';
                push @curl_arg, '@'.$uppath;
        }
+       
        foreach $envk (keys %ENV) { 
-               if ($envk =~ /^(HTTP_[A-Z_]+)$/) {
+               if ($envk =~ /^(HTTP_[A-Z0-9_]+)$/) {
                        $headname=formatheader($1);
-                       if ($ENV{$envk} =~ /^([\x20-\x7e]*)$/) {
-                               $headval=$1;
-                       }
-                       if(lc($headname) =~ REQUEST_HEADER_BLOCK) {
-                               next;
-                       }
-                       unless (exists $ENV{'HTTP_USER_AGENT'}) {
-                               push @curl_arg, '-H';
-                               push @curl_arg, 'User-Agent:';
-                       }
-                       unless (exists $ENV{'HTTP_ACCEPT'}) {
-                               push @curl_arg, '-H';
-                               push @curl_arg, 'ACCEPT:';
-                       }
-                       $headval=~ s/[\r\n]//g;
-                       $headarg=$headname.(($headval eq '')?';':': '.$headval);
-                       push @curl_arg, '-H';
-                       push @curl_arg, $headarg;
                }
+               elsif ($envk =~ /^(CONTENT_[A-Z0-9_]+)$/) {
+                       $headname=formatheader($1);
+               }
+               else {
+                       next;
+               }
+               if ($ENV{$envk} =~ /^([\x20-\x7e]*)$/) {
+                       $headval=$1;
+               }
+               else {
+                       next;
+               }
+               if(lc($headname) =~ REQUEST_HEADER_BLOCK) {
+                       next;
+               }
+               
+               $headarg=$headname.(($headval eq '')?';':': '.$headval);
+               
+               push @curl_arg, '-H';
+               push @curl_arg, $headarg;
+       }
+       unless (exists $ENV{'HTTP_USER_AGENT'}) {
+               push @curl_arg, '-H';
+               push @curl_arg, 'User-Agent:';
+       }
+       unless (exists $ENV{'HTTP_ACCEPT'}) {
+               push @curl_arg, '-H';
+               push @curl_arg, 'ACCEPT:';
        }
        
        push @curl_arg, $URL;
@@ -274,6 +285,10 @@ sub proxy {
        close(STDREAD);
        close(ERRREAD);
        
+       if ($createdup) {
+               unlink $uppath;
+       }
+       
        if($safeerror){
                return fail("Status: 500 Internal Server Error\n","500 Internal Server Error",$errormsg);
        }