HTTP-Promise
view release on metacpan or search on metacpan
lib/HTTP/Promise/Headers.pm view on Meta::CPAN
return if( !defined( $ctype_raw ) || !length( "$ctype_raw" ) );
$self->{_ctype_cached} = $ctype_raw;
# There is nothing, but the mime-type itself, so no need to bother
if( index( $ctype_raw, ';' ) == -1 )
{
$self->{type} = $ctype_raw;
$self->{boundary} = '';
}
else
{
# Content-Type: application/json; encoding=utf-8
my $ct = $self->new_field( 'Content-Type' => $ctype_raw );
return( $self->pass_error ) if( !defined( $ct ) );
# Accept: application/json; version=1.0; charset=utf-8
$self->{type} = lc( $ct->type );
my $charset = $ct->charset;
$charset = lc( $charset ) if( defined( $charset ) );
$self->{charset} = $charset;
$self->{boundary} = $ct->boundary if( $ct->boundary );
}
}
return( $self->{type} );
}
# <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Upgrade>
sub upgrade { return( shift->_set_get_multi( 'Upgrade', @_ ) ); }
# <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Upgrade-Insecure-Requests>
sub upgrade_insecure_requests { return( shift->_set_get_one( 'Upgrade-Insecure-Requests', @_ ) ); }
sub uri_escape_utf8 { return( URI::Escape::XS::uri_escape( Encode::encode( 'UTF-8', $_[1] ) ) ); }
# NOTE: user_agent() is inherited
# <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/User-Agent>
sub user_agent { return( shift->_set_get_one( 'user_agent', @_ ) ); }
# <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Vary>
sub vary { return( shift->_set_get_multi( 'Vary', @_ ) ); }
# <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Via>
sub via { return( shift->_set_get_multi( 'Via', @_ ) ); }
# <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Want-Digest>
sub want_digest { return( shift->_set_get_multi( 'Want-Digest', @_ ) ); }
# <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Warning>
sub warning { return( shift->_set_get_one( 'Warning', @_ ) ); }
# NOTE: www_authenticate() is superseded
# <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/WWW-Authenticate>
sub www_authenticate { return( shift->_set_get_one( 'WWW-Authenticate', @_ ) ); }
sub x { return( shift->_set_get_one( 'X-' . $_[0], @_ ) ); }
# <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Content-Type-Options>
sub x_content_type_options { return( shift->_set_get_one( 'X-Content-Type-Options', @_ ) ); }
# <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-DNS-Prefetch-Control>
sub x_dns_prefetch_control { return( shift->_set_get_one( 'X-DNS-Prefetch-Control', @_ ) ); }
# <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-For>
sub x_forwarded_for { return( shift->_set_get_one( 'X-Forwarded-For', @_ ) ); }
# <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-Host>
sub x_forwarded_host { return( shift->_set_get_one( 'X-Forwarded-Host', @_ ) ); }
# <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-Proto>
sub x_forwarded_proto { return( shift->_set_get_one( 'X-Forwarded-Proto', @_ ) ); }
# <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Frame-Options>
sub x_frame_options { return( shift->_set_get_one( 'X-Frame-Options', @_ ) ); }
# <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-XSS-Protection>
sub x_xss_protection { return( shift->_set_get_one( 'X-XSS-Protection', @_ ) ); }
sub _basic_auth
{
my $self = shift( @_ );
my $field = shift( @_ );
return( $self->error( "No field provided to get its basic authentication value." ) ) if( !defined( $field ) || !length( $field ) );
$self->_load_class( 'Crypt::Misc' ) || return( $self->pass_error );
if( @_ )
{
my( $user, $pwd ) = @_;
return( $self->error( "Basic authorisation user name cannot contain ':'." ) ) if( index( $user, ':' ) != -1 );
$pwd = '' if( !defined( $pwd ) );
$self->header( $field => sprintf( 'Basic %s', Crypt::Misc::encode_b64( "${user}:${pwd}" ) ) );
return( "${user}:${pwd}" );
}
else
{
my $v = $self->header( $field );
return( $v ) if( !defined( $v ) && !want( 'OBJECT' ) );
if( defined( $v ) && $v =~ /^[[:blank:]\h]*Basic[[:blank:]\h]+(.+?)$/ )
{
$v = Crypt::Misc::decode_b64( $1 );
}
return( wantarray() ? split( /:/, "$v" ) : $self->new_scalar( $v ) );
}
}
sub _date_header
{
my $self = shift( @_ );
my $f = shift( @_ );
return( $self->error( "No field was provided to get or set its value." ) ) if( !defined( $f ) || !length( "$f" ) );
if( @_ )
{
my $this = shift( @_ );
return( $self->remove_header( "$f" ) ) if( !defined( $this ) );
my $opts = $self->_get_args_as_hash( @_ );
$opts->{time_zone} = 'GMT' if( !defined( $opts->{time_zone} ) || !length( $opts->{time_zone} ) );
require Module::Generic::DateTime;
require DateTime::Format::Lite;
if( ref( $this ) && Scalar::Util::blessed( $this ) && $this->isa( 'Module::Generic::DateTime' ) )
{
# Ok, pass through
}
elsif( ref( $this ) && Scalar::Util::blessed( $this ) && ( $this->isa( 'DateTime::Lite' ) || $this->isa( 'DateTime' ) ) )
{
$this = Module::Generic::DateTime->new( $this );
}
lib/HTTP/Promise/Headers.pm view on Meta::CPAN
Warning: 110 anderson/1.3.37 "Response is stale"
See also L<rfc7234, section 5.5|https://tools.ietf.org/html/rfc7234#section-5.5> and L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Warning>
=head2 www_authenticate
This sets or gets the C<WWW-Authenticate> header value. It takes a string value.
Example:
WWW-Authenticate: Basic realm="Access to the staging site", charset="UTF-8"
WWW-Authenticate: Digest
realm="http-auth@example.org",
qop="auth, auth-int",
algorithm=SHA-256,
nonce="7ypf/xlj9XXwfDPEoM4URrv/xwf94BcCAzFZH4GiTo0v",
opaque="FQhe/qaU925kfnzjCev0ciny7QMkPqMAFRtzCUYo5tdS"
WWW-Authenticate: Digest
realm="http-auth@example.org",
qop="auth, auth-int",
algorithm=MD5,
nonce="7ypf/xlj9XXwfDPEoM4URrv/xwf94BcCAzFZH4GiTo0v",
opaque="FQhe/qaU925kfnzjCev0ciny7QMkPqMAFRtzCUYo5tdS"
See also L<rfc7235, section 4.1|https://tools.ietf.org/html/rfc7235#section-4.1> and L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/WWW-Authenticate>
=head2 x
Sets or gets an arbitrary C<X-*> header. For example:
$h->x( 'Spip-Cache' => 3600 );
would set the C<X-Spip-Cache> header value to C<3600>
my $value = $h->x( 'Spip-Cache' );
=head2 x_content_type_options
This sets or gets the C<X-Content-Type-Options> header value. It takes a string value.
Example:
X-Content-Type-Options: nosniff
See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Content-Type-Options>
=head2 x_dns_prefetch_control
This sets or gets the C<X-DNS-Prefetch-Control> header value. It takes a string value.
Example:
X-DNS-Prefetch-Control: on
X-DNS-Prefetch-Control: off
See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-DNS-Prefetch-Control>
=head2 x_forwarded_for
This sets or gets the C<X-Forwarded-For> header value. It takes a string value.
Example:
X-Forwarded-For: 2001:db8:85a3:8d3:1319:8a2e:370:7348
X-Forwarded-For: 203.0.113.195
X-Forwarded-For: 203.0.113.195, 2001:db8:85a3:8d3:1319:8a2e:370:7348
See also L</host>, L</forwarded>, L</x_forwarded_host>, L</x_forwarded_proto>, L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-For>
=head2 x_forwarded_host
This sets or gets the C<X-Forwarded-Host> header value. It takes a string value.
Example:
X-Forwarded-Host: id42.example-cdn.com
See also L</host>, L</forwarded>, L</x_forwarded_for>, L</x_forwarded_proto>, L<https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-Host>
=head2 x_forwarded_proto
This sets or gets the C<X-Forwarded-Proto> header value. It takes a string value.
Example:
X-Forwarded-Proto: https
See also L</host>, L</forwarded>, L</x_forwarded_for>, L</x_forwarded_host>, L<https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-Proto>
=head2 x_frame_options
This sets or gets the C<X-Frame-Options> header value. It takes a string value.
Example:
X-Frame-Options: DENY
X-Frame-Options: SAMEORIGIN
See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Frame-Options>
=head2 x_xss_protection
This sets or gets the C<X-XSS-Protection> header value. It takes a string value.
Example:
X-XSS-Protection: 0
X-XSS-Protection: 1
X-XSS-Protection: 1; mode=block
X-XSS-Protection: 1; report=https://example.org/some/where
See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-XSS-Protection>
=for Pod::Coverage STORABLE_thaw_post_processing
=head1 THREAD-SAFETY
This module is thread-safe for all operations, as it operates on per-object state and uses thread-safe external libraries.
=head1 AUTHOR
Jacques Deguest E<lt>F<jack@deguest.jp>E<gt>
=head1 SEE ALSO
L<Mozilla documentation on HTTP headers|https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers>
L<HTTP::Promise::Headers::AcceptEncoding>, L<HTTP::Promise::Headers::AcceptLanguage>, L<HTTP::Promise::Headers::Accept>, L<HTTP::Promise::Headers::AltSvc>, L<HTTP::Promise::Headers::CacheControl>, L<HTTP::Promise::Headers::ClearSiteData>, L<HTTP::Pro...
( run in 2.908 seconds using v1.01-cache-2.11-cpan-437f7b0c052 )