httpperllwplwp-useragenthar

How can I convert .har requests to HTTP string?


I'd like to convert requests in .har file (see here) to their string version for use with LWP. Is there a tool that does it already?

Specifically I'd like to be able to generate the string in order to parse it like this:

my $str = har_to_string($har);
my $r = HTTP::Request->parse( $str ) 

See docs here.

I could probably roll my own har_to_string in Perl, but I'd like a reference to test against.


Solution

  • Archive::Har has an entries() method which returns a list of Archive::Har::Entry objects. Each Archive::Har::Entry object has a request() method which returns a Archive::Har::Entry::Request containing details of the request that was made.

    It's not the string representation that you ask for, but I expect you could use the various methods on Archive::Har::Entry::Request to generate the HTTP::Request object that you want.

    (I haven't tried this, I'm just browsing through documentation.)