in reply to LWP is there any way to get "real" outgoing headers?

Oops! I misunderstood what the OP wanted. My answer below works for Incoming headers not Outgoing*

The following works:

use warnings; use strict; use LWP::UserAgent; my $ua = LWP::UserAgent->new; my $url = 'http://www.google.com'; print $ua->head($url)->as_string;
OUTPUT:
HTTP/1.1 200 OK Cache-Control: private, max-age=0 Connection: close Date: Sat, 24 May 2014 04:17:59 GMT Server: gws Content-Type: text/html; charset=ISO-8859-1 Expires: -1 Alternate-Protocol: 80:quic Client-Date: Sat, 24 May 2014 04:16:04 GMT Client-Peer: 174.194.08.94:80 Client-Response-Num: 1 P3P: CP="This is not a P3P policy! See http://www.google.com/support/a +ccounts/bin/answer.py?hl=en&answer=151657 for more info." Set-Cookie: PREF=ID=6be73c938c0eb2c2:FF=0:TM=1400905079:LM=1400905079: +S=d_WzZRSOQ6IZBvFA; expires=Mon, 23-May-2016 04:17:59 GMT; path=/; do +main=.google.com.ng Set-Cookie: NID=67=bU9SctXcLKJvZuBUQclTeWSIIJPWwD579z8_VsFNdP9AtU2dVx_ +5_rpEj_AGQIvcXVqeV3xka5H9aGSX_SN62h-bQ70smhmQ77HRB3o0uTsdUFnNeNU0u--x +2IYvBj8c; expires=Sun, 23-Nov-2014 04:17:59 GMT; path=/; domain=.goog +le.com.ng; HttpOnly X-Frame-Options: SAMEORIGIN X-XSS-Protection: 1; mode=block

* Update

If you tell me, I'll forget.
If you show me, I'll remember.
if you involve me, I'll understand.
--- Author unknown to me

Replies are listed 'Best First'.
Re^2: LWP is there any way to get "real" outgoing headers?
by Anonymous Monk on May 24, 2014 at 04:23 UTC
    Thank you, but I guess, you don't understand my question or didn't read it :(
    I can't get outgoing headers, not incoming. My code I posted above (and actually almost any code) perfectly catch incoming headers.
      YOU control OUTGOING headers. There's NO guesswork involved. Just send what you damn well please. It's as simple as that.
      I even illustrated that in my first response to you.

      Your question makes no sense.

      ¡λɐp ʇɑəɹ⅁ ɐ əʌɐɥ puɐ ʻꜱdləɥ ꜱᴉɥʇ ədoH

        > Your question makes no sense.
        Well. taint, with all due respect, your reply (all 3 of them) make even less sense than my question. Since you replying on something different.
        And once again - I'm not here to insult someone, that's pointless. I'm just trying to solve issue I have. But according to replies above that's not possible with LWP itself (I'll need to use another modules or hack original ones).

        I'm clearly asking how to get outgoing headers, generated by LWP, not how to modify/change them (I know how to do that and successfully doing that for years in my code).
        Now I need to log them.
        The problem is - LWP return headers different to headers which he sent out.

        Headers I can get from LWP, for example using $response->request()->as_string():

        GET http://example.com/ User-Agent: libwww-perl/6.05

        Headers LWP sent out (catched using sniffer):
        GET / HTTP/1.1 Host: example.com User-Agent: libwww-perl/6.05 Connection: keep-alive

        Of course both from same HTTP session. And I posted those logs in my original question. You see the difference?

        You could read edited reply from InfiniteSilence above.

        "I'm looking for a way to get "real" outgoing headers, generated by LWP (I need them for logging/debugging purpose)."
        So, what exactly wrong with my question? (except bad English)

        P.S. And just for your info, you can't control all headers, using code you posted above. In code, I posted as example in my initial question you will see how you can control Connection (to avoid sending "TE, close" instead of "keep-alive") and how to change HTTP version to 1.0 / 1.1 (in case you need that).