How to reorder HTTP request headers sent by Perl LWP?

For the test, I need to make a request to the website - unfortunately, when using perl lwp, a “connection” appears in the b4 header of the host. As a result, the request is filtered through the web application firewall. All I need to do is delete or move the connection string in the header. When I make requests using a script:

use warnings; use IO::Socket; use LWP::UserAgent; use LWP::Protocol::http; use HTTP::Request; my $ua = LWP::UserAgent->new(); push(@LWP::Protocol::http::EXTRA_SOCK_OPTS, SendTE => 0, PeerHTTPVersion => "1.1"); $ua->default_header(Cookie => 'XXX', User-Agent => 'whateva'); my $request = $ua->get('https://www.test.com/test.html?...'); .... 

The title is as follows:

 GET /test.html?... HTTP/1.1 Connection: close Host: www.test.com User-Agent: whateva Cookie: XXXX 

BUT this should look like this to work (conenction appears after the host):

 GET /test.html?... HTTP/1.1 Host: www.test.com Connection: close User-Agent: whateva Cookie: XXXX 

How do I get rid of this connection line in LWP? I just need to repeat it ... Not that it had to be completely removed; I will gladly add it later where

 # $userAgent->default_header ("Connection" => "keep-alive");.. 

thanks a lot in advance!

+4
source share
1 answer

To work around the error in your firewall *, change

 return _bytes(join($CRLF, "$method $uri HTTP/$ver", @h2, @h, "", $content)); 

in Net/HTTP.pm until

 my @h3 = ( @h2, @h ); if (my ($idx) = grep /^Host:/, 0..$#h3) { unshift(@h3, splice(@h3, $idx, 1)); } return _bytes(join($CRLF, "$method $uri HTTP/$ver", @h3, "", $content)); 



* - According to the HTTP / 1.1 specification, RFC 2616, "the order in which header fields with different field names are received does not matter."

+3
source

All Articles