Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: How to remove HTTP Keep-Alive 300 header from LWP::UserAgent request

by Anonymous Monk
on Apr 27, 2018 at 02:18 UTC ( [id://1213657]=note: print w/replies, xml ) Need Help??


in reply to How to remove HTTP Keep-Alive 300 header from LWP::UserAgent request

Hi

Well, since you responded to jeffenstein, here you go Veltro

LWP header -> Re: LWP is there any way to get "real" outgoing headers?

#!/usr/bin/perl -- use strict; use warnings; use LWP; use Data::Dump(); sub LWP::Protocol::http::SocketMethods::format_request { package LWP::Protocol::http::SocketMethods; my( $socket, $method, $fullpath, @h ) = @_; #~ my $req_buf = $socket->Net::HTTP::Methods::format_request($meth +od, $fullpath, @h, 'Keep-Alive',666); ## fail, adds another header my $req_buf = $socket->Net::HTTP::Methods::format_request($method, + $fullpath, @h ); $req_buf =~ s{Keep-Alive: 300}{Keep-Alive: 30}g; ## win, removes e +xisting header Data::Dump::dd( $req_buf ); return $req_buf; } LWP::UserAgent->new( keep_alive=>1 )->get( q{http://127.0.0.1:80/} )-> +dump; __END__ "GET / HTTP/1.1\r\nTE: deflate,gzip;q=0.3\r\nKeep-Alive: 30\r\nConnect +ion: Keep-Alive, TE\r\nHost: 127.0.0.1:80\r\nUser- Agent: libwww-perl/6.15\r\n\r\n" HTTP/0.9 200 Assumed OK Client-Date: Tue, 24 Apr 2018 23:25:20 GMT Client-Peer: 127.0.0.1:80 Client-Response-Num: 1 Echo: GET / HTTP/1.1\r Echo: TE: deflate,gzip;q=0.3\r Echo: Keep-Alive: 30\r Echo: Connection: Keep-Alive, TE\r Echo: Host: 127.0.0.1:80\r Echo: User-Agent: libwww-perl/6.15\r Echo: \r\n
  • Comment on Re: How to remove HTTP Keep-Alive 300 header from LWP::UserAgent request
  • Download Code

Replies are listed 'Best First'.
Re^2: How to remove HTTP Keep-Alive 300 header from LWP::UserAgent request
by Veltro (Hermit) on May 01, 2018 at 22:10 UTC
    Thanks for showing how to override format_request. Very useful for introspection. I have also posted my reply to jeffenstein with different solution here for more details
      Neat, thanks. I hope I can count on your vote, and I hope you enjoy the pastrami on rye.
        ++ ;)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1213657]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (7)
As of 2024-04-24 20:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found