Travis Build Status AppVeyor Build Status

NAME

HTTP::Request::FromCurl - create a HTTP::Request from a curl command line

SYNOPSIS

my $req = HTTP::Request::FromCurl->new(
    # Note - curl itself may not appear
    argv => ['https://example.com'],
);

my $req = HTTP::Request::FromCurl->new(
    command => 'https://example.com',
);

my $req = HTTP::Request::FromCurl->new(
    command_curl => 'curl -A mycurl/1.0 https://example.com',
);

my @requests = HTTP::Request::FromCurl->new(
    command_curl => 'curl -A mycurl/1.0 https://example.com https://www.example.com',
);
# Send the requests
for my $r (@requests) {
    $ua->request( $r->as_request )
}

METHODS

->new

my $req = HTTP::Request::FromCurl->new(
    # Note - curl itself may not appear
    argv => ['--agent', 'myscript/1.0', 'https://example.com'],
);

my $req = HTTP::Request::FromCurl->new(
    # Note - curl itself may not appear
    command => '--agent myscript/1.0 https://example.com',
);

The constructor returns one or more HTTP::Request::CurlParameters objects that encapsulate the parameters. If the command generates multiple requests, they will be returned in list context. In scalar context, only the first request will be returned.

my $req = HTTP::Request::FromCurl->new(
    command => '--data-binary @/etc/passwd https://example.com',
    read_files => 1,
);

Options

->squash_uri( $uri )

my $uri = HTTP::Request::FromCurl->squash_uri(
    URI->new( 'https://example.com/foo/bar/..' )
);
# https://example.com/foo/

Helper method to clean up relative path elements from the URI the same way that curl does.

GLOBAL VARIABLES

%default_headers

Contains the default headers added to every request

@option_spec

Contains the Getopt::Long specification of the recognized command line parameters.

The following curl options are recognized but ignored:

LIVE DEMO

https://corion.net/curl2lwp.psgi

KNOWN DIFFERENCES

Until somebody writes a robust Netscape cookie file parser and proper loading and storage for HTTP::CookieJar, this module will not be able to load and save files in the format that Curl uses.

You're expected to instruct your UA to load/save cookie jars:

use Path::Tiny;
use HTTP::CookieJar::LWP;

if( my $cookies = $r->cookie_jar ) {
    $ua->cookie_jar( HTTP::CookieJar::LWP->new()->load_cookies(
        path($cookies)->lines
    ));
};

Different Content-Length for POST requests

Different delimiter for form data

The delimiter is built by HTTP::Message, and curl uses a different mechanism to come up with a unique data delimiter. This results in differences in the raw body content and the Content-Length header.

MISSING FUNCTIONALITY

SEE ALSO

LWP::Curl

LWP::Protocol::Net::Curl

LWP::CurlLog

HTTP::Request::AsCurl - for the inverse function

REPOSITORY

The public repository of this module is http://github.com/Corion/HTTP-Request-FromCurl.

SUPPORT

The public support forum of this module is https://perlmonks.org/.

BUG TRACKER

Please report bugs in this module via the RT CPAN bug queue at https://rt.cpan.org/Public/Dist/Display.html?Name=HTTP-Request-FromCurl or via mail to filter-signatures-Bugs@rt.cpan.org.

AUTHOR

Max Maischein corion@cpan.org

COPYRIGHT (c)

Copyright 2018 by Max Maischein corion@cpan.org.

LICENSE

This module is released under the same terms as Perl itself.