NAME
HTTP::Request::FromFetch - turn a Javascript fetch() statement into HTTP::Request
SYNOPSIS
my $ua = LWP::UserAgent->new();
my $req = HTTP::Request::FromFetch->new(<<'JS')->as_request;
await fetch("https://www.example.com/index.html", {
"credentials": "include",
"headers": {
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:74.0) Gecko/20100101 Firefox/74.0",
"Accept": "text/javascript, text/html, application/xml, text/xml, */*",
"Accept-Language": "de,en-US;q=0.7,en;q=0.3",
"X-CSRF-Token": "secret",
"X-Requested-With": "XMLHttpRequest"
},
"referrer": "https://www.example.com/",
"method": "GET",
"mode": "cors"
});
JS
$ua->request( $req );
DESCRIPTION
This module parses a call to the Javascript Fetch API and returns an object that you can turn into a HTTP::Request to use with LWP::UserAgent or other user agents to perform a largely identical HTTP request.
The parsing of the Javascript stanza is done through a regular expression, so the test must largely follow the pattern shown in the synopsis. Usually, the fetch()
stanzas come from a browsers "Copy as fetch" context menu, so there is no problem parsing these.
This is mostly a factory class for HTTP::Request::CurlParameters objects.
SEE ALSO
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.