At
view release on metacpan or search on metacpan
lib/At/UserAgent.pm view on Meta::CPAN
my $res
= $agent->get( $url . ( defined $req->{content} && keys %{ $req->{content} } ? '?' . $agent->www_form_urlencode( $req->{content} ) : '' ),
{ defined $req->{headers} ? ( headers => $req->{headers} ) : () } );
if ( $res->{headers} ) {
my $nonce;
foreach my $k ( keys %{ $res->{headers} } ) {
if ( lc($k) eq 'dpop-nonce' ) { $nonce = $res->{headers}{$k}; last; }
}
$self->dpop_nonce($nonce) if defined $nonce && $nonce ne '';
}
$res->{content} = JSON::PP::decode_json( $res->{content} ) if $res->{content} && ( $res->{headers}{'content-type'} // '' ) =~ m[json];
unless ( $res->{success} ) {
my $body = $res->{content};
if ( ( $res->{status} == 401 || $res->{status} == 400 ) &&
!ref $body &&
$body =~ /use_dpop_nonce|dpop_nonce|required nonce|nonce in dpop|DPoP.*nonce/i ) {
my $retry_headers = { %{ $req->{headers} // {} } };
$retry_headers->{DPoP} = $self->_generate_dpop_proof( $url, 'GET', $req->{skip_ath} ) if $self->token_type eq 'DPoP';
$res
= $agent->get(
$url . ( defined $req->{content} && keys %{ $req->{content} } ? '?' . $agent->www_form_urlencode( $req->{content} ) : '' ),
{ headers => $retry_headers } );
if ( $res->{headers} ) {
my $nonce = $res->{headers}{'dpop-nonce'} || $res->{headers}{'DPoP-Nonce'} || $res->{headers}{'dpop_nonce'};
$self->dpop_nonce($nonce) if defined $nonce && $nonce ne '';
}
$res->{content} = JSON::PP::decode_json( $res->{content} ) if $res->{content} && ( $res->{headers}{'content-type'} // '' ) =~ m[json];
}
}
unless ( $res->{success} ) {
my $msg = $res->{reason} // 'Unknown error';
if ( ref $res->{content} eq 'HASH' ) {
my $json = $res->{content};
my $details = $json->{error} // '';
if ( $json->{message} && $json->{message} ne $details ) {
$details .= ( $details ? ': ' : '' ) . $json->{message};
}
lib/At/UserAgent.pm view on Meta::CPAN
}
my $res = $agent->post( $url,
{ defined $req->{headers} ? ( headers => $req->{headers} ) : (), defined $content ? ( content => $content ) : () } );
if ( $res->{headers} ) {
my $nonce;
foreach my $k ( keys %{ $res->{headers} } ) {
if ( lc($k) eq 'dpop-nonce' ) { $nonce = $res->{headers}{$k}; last; }
}
$self->dpop_nonce($nonce) if defined $nonce && $nonce ne '';
}
$res->{content} = JSON::PP::decode_json( $res->{content} ) if $res->{content} && ( $res->{headers}{'content-type'} // '' ) =~ m[json];
unless ( $res->{success} ) {
my $body = $res->{content};
if ( ( $res->{status} == 401 || $res->{status} == 400 ) &&
!ref $body &&
$body =~ /use_dpop_nonce|dpop_nonce|required nonce|nonce in dpop|DPoP.*nonce/i ) {
my $retry_headers = { %{ $req->{headers} // {} } };
$retry_headers->{DPoP} = $self->_generate_dpop_proof( $url, 'POST', $req->{skip_ath} ) if $self->token_type eq 'DPoP';
my $retry_content = $content;
$res = $agent->post( $url, { headers => $retry_headers, defined $retry_content ? ( content => $retry_content ) : () } );
if ( $res->{headers} ) {
my $nonce = $res->{headers}{'dpop-nonce'} || $res->{headers}{'DPoP-Nonce'} || $res->{headers}{'dpop_nonce'};
$self->dpop_nonce($nonce) if defined $nonce && $nonce ne '';
}
$res->{content} = JSON::PP::decode_json( $res->{content} ) if $res->{content} && ( $res->{headers}{'content-type'} // '' ) =~ m[json];
}
}
unless ( $res->{success} ) {
my $msg = $res->{reason} // 'Unknown error';
if ( ref $res->{content} eq 'HASH' ) {
my $json = $res->{content};
my $details = $json->{error} // '';
if ( $json->{message} && $json->{message} ne $details ) {
$details .= ( $details ? ': ' : '' ) . $json->{message};
}
( run in 0.878 second using v1.01-cache-2.11-cpan-99fa8243a42 )