Skip Menu |

This queue is for tickets about the Net-Async-HTTP CPAN distribution.

Report information
The Basics
Id: 131040
Status: resolved
Priority: 0/
Queue: Net-Async-HTTP

People
Owner: Nobody in particular
Requestors: TEAM [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: 0.45



Subject: Non-canonical headers
In an ideal world, these would never be needed, but... https://metacpan.org/pod/HTTP::Headers#NON-CANONICALIZED-FIELD-NAMES Sometimes a header like `api_key` is needed. You can set this up in a custom HTTP::Request - $req->header(':api_key' => '...'); but due to the use of `->scan` in Net::Async::HTTP::Connection, this goes through as the literal `:api_key` value, rather than stripping out the `:` prefix: https://metacpan.org/release/Net-Async-HTTP/source/lib/Net/Async/HTTP/Connection.pm#L301 `$_[0]` there would need to be something like `$_[0] =~ s{^:}{}r` instead.
On Thu Nov 21 10:35:23 2019, TEAM wrote: Show quoted text
> `$_[0]` there would need to be something like `$_[0] =~ s{^:}{}r` > instead.
Probably safest to unpack @_ then mutate my own lexicals, in case ->scan is aliasing something existing in there. -- Paul Evans
Subject: rt131040.patch
=== modified file 'lib/Net/Async/HTTP/Connection.pm' --- old/lib/Net/Async/HTTP/Connection.pm 2019-02-17 14:13:09 +0000 +++ new/lib/Net/Async/HTTP/Connection.pm 2019-11-26 09:28:01 +0000 @@ -298,7 +298,11 @@ my $protocol = $req->protocol || "HTTP/1.1"; my @headers = ( "$method $path $protocol" ); - $headers->scan( sub { push @headers, "$_[0]: $_[1]" } ); + $headers->scan( sub { + my ( $name, $value ) = @_; + $name =~ s/^://; # non-canonical header + push @headers, "$name: $value"; + } ); $stall_timer->start if $stall_timer; $stall_timer->reason = "writing request" if $stall_timer; === modified file 't/01request.t' --- old/t/01request.t 2018-10-12 17:47:11 +0000 +++ new/t/01request.t 2019-11-26 09:28:01 +0000 @@ -568,4 +568,20 @@ expect_error => 1, ); +do_test_req( "Non-canonical header", + req => HTTP::Request->new( GET => "/", [ ":other_hdr" => "value" ] ), + host => "myhost", + + expect_req_firstline => "GET / HTTP/1.1", + expect_req_headers => { + other_hdr => "value", + }, + + response => "HTTP/1.1 200 OK$CRLF" . + "Content-Length: 0$CRLF" . + $CRLF, + + expect_res_code => 200, +); + done_testing;