HTTP-Promise
view release on metacpan or search on metacpan
METHODS
The following methods are available. This interface provides similar
interface as LWP::UserAgent while providing more granular control.
accept_encoding
String. Sets or gets whether we should accept compressed data.
You can set it to "none" to disable it. By default, this is "auto", and
it will set the "Accept-Encoding" "HTTP" header to all the supported
encoding based on the availability of associated modules.
You can also set this to a comma-separated list of known encoding,
typically: "bzip2,deflate,gzip,rawdeflate,brotli"
See HTTP::Promise::Stream for more details.
Returns a scalar object of the current value.
accept_language
An array of acceptable language. This will be used to set the
"Accept-Language" header.
See also HTTP::Promise::Headers::AcceptLanguage
agent
This is a string.
Sets or gets the agent id used to identify when making the server
connection.
It defaults to "HTTP-Promise/v0.1.0"
my $p = HTTP::Promise->new( agent => 'MyBot/1.0' );
$p->agent( 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:99.0) Gecko/20100101 Firefox/99.0' );
The "User-Agent" header field is only set to this provided value if it
is not already set.
accept_language
Sets or gets an array of acceptable response content languages.
For example:
$http->accept_language( [qw( fr-FR ja-JP en-GB en )] );
Would result into an "Accept-Language" header set to
"fr-FR;q=0.9,ja-JP;q=0.8,en-GB;q=0.7,en;q=0.6"
The "Accept-Language" header would only be set if it is not set already.
auto_switch_https
Boolean. If set to a true value, or if left to "undef" (default value),
this will set the "Upgrade-Insecure-Requests" header field to 1
buffer_size
The size of the buffer to use when reading data from the filehandle or
socket.
connection_header
Sets or gets the value for the header "Connection". It can be "close" or
"keep-alive"
If it is let "undef", this module will try to guess the proper value
based on the "protocol" in HTTP::Promise::Request and "version" in
HTTP::Promise::Request used.
For protocol "HTTP/1.0", "Connection" value would be "close", but above
"HTTP/1.1" the connection can be set to "keep-alive" and thus be
re-used.
cookie_jar
Sets or gets the Cookie jar class object to use. This is typically
Cookie::Jar or maybe HTTP::Cookies
This defaults to Cookie::Jar
use Cookie::Jar;
my $jar = Cookie::Jar->new;
my $p = HTTP::Promise->new( cookie_jar => $jar );
$p->cookie_jar( $jar );
decodable
This calls "decodable" in HTTP::Promise::Stream passing it whatever
arguments that were provided.
default_header
Sets one more default headers. This is a shortcut to
"$p->default_headers->header"
$p->default_header( $field );
$p->default_header( $field => $value );
$p->default_header( 'Accept-Encoding' => scalar( HTTP::Promise->decodable ) );
$p->default_header( 'Accept-Language' => 'fr, en, ja' );
default_headers
Sets or gets the default header object, which is set to "undef" by
default.
This can be either an HTTP::Promise::Headers or HTTP::Headers object.
use HTTP::Promise::Headers;
my $headers = HTTP::Promise::Headers->new(
'Accept-Encoding' => scalar( HTTP::Promise->decodable ),
'Accept-Language' => 'fr, en, ja',
);
my $p = HTTP::Promise->new( default_headers => $headers );
default_protocol
Sets or gets the default protocol to use. For example: "HTTP/1.1"
delete
Provided with an "uri" and an optional hash of header name/value pairs,
and this will issue a "DELETE" http request to the given "uri".
It returns a promise, which can be used to call one or more then and
catch
# or $p->delete( $uri, $field1 => $value1, $field2 => $value2 )
$p->delete( $uri )->then(sub
{
my( $resolve, $reject ) = @$_;
# an HTTP::Promise::Response is returned
my $resp = shift( @_ );
# Do something with the $resp object
})->catch(sub
{
my $ex = shift( @_ );
# An HTTP::Promise::Exception object is passed with an error code
( run in 0.673 second using v1.01-cache-2.11-cpan-71847e10f99 )