Jelajahi Sumber

use a more reliable header parser

George Baugh 3 tahun lalu
induk
melakukan
df443fac38
2 mengubah file dengan 4 tambahan dan 5 penghapusan
  1. 1 1
      Makefile.PL
  2. 3 4
      lib/TCMS.pm

+ 1 - 1
Makefile.PL

@@ -51,7 +51,7 @@ WriteMakefile(
     'IO::Compress::Brotli'   => '0',
     'IO::Compress::Gzip'     => '0',
     'IO::Compress::Deflate'  => '0',
-    'HTTP::HeaderParser::XS' => '0',
+    'HTTP::Parser::XS' => '0',
   },
   test => {TESTS => 't/*.t'}
 );

+ 3 - 4
lib/TCMS.pm

@@ -18,7 +18,7 @@ use CGI::Cookie ();
 use File::Basename();
 use IO::Compress::Gzip();
 use Time::HiRes qw{gettimeofday tv_interval};
-use HTTP::HeaderParser::XS;
+use HTTP::Parser::XS qw{HEADERS_AS_HASHREF};
 
 #Grab our custom routes
 use lib 'lib';
@@ -238,14 +238,13 @@ sub _static($path,$start,$last_fetch=0) {
             last if $_ eq "\n";
             $headers .= $_;
         }
-        my $hdrs = HTTP::HeaderParser::XS->new(\$headers);
-        my $headers_parsed = $hdrs->getHeaders();
+        my(undef, undef, $status, undef, $headers_parsed) = HTTP::Parser::XS::parse_http_response("$headers\n", HEADERS_AS_HASHREF);
 
         #XXX need to put this into the file itself
         my $mt = (stat($fh))[9];
         my @gm = gmtime($mt);
         my $now_string = strftime( "%a, %d %b %Y %H:%M:%S GMT", @gm );
-        my $code = $mt > $last_fetch ? $hdrs->getStatusCode() : 304;
+        my $code = $mt > $last_fetch ? $status : 304;
         $headers_parsed->{"Last-Modified"} = $now_string;
 
         # Append server-timing headers