the headers attribute on Mojo::Message is currently defined as
|
sub headers { shift->content->headers } |
Which has the effect of ignoring any arguments passed to headers.
Is this intentional? The docs mention that message->headers is the same as message->content->headers
Reproducer:
use Mojo::UserAgent;
use Mojo::Headers;
use Data::Dumper;
my $ua = Mojo::UserAgent->new;
my $tx = $ua->build_tx("GET" => "example.com");
my $new_headers = Mojo::Headers->new;
$new_headers->accept_encoding("br");
$new_headers->user_agent("req->headers");
$tx->req->headers($new_headers);
print Dumper($tx->req->headers); # Notice headers not updated
$new_headers = Mojo::Headers->new;
$new_headers->accept_encoding("br");
$new_headers->user_agent("req->content->headers");
$tx->req->content->headers($new_headers);
print Dumper($tx->req->content->headers);
Actual Output:
$VAR1 = bless( {
'headers' => {
'accept-encoding' => [
'gzip'
],
'user-agent' => [
'Mojolicious (Perl)'
]
}
}, 'Mojo::Headers' );
$VAR1 = bless( {
'headers' => {
'accept-encoding' => [
'br'
],
'user-agent' => [
'req->content->headers'
]
}
}, 'Mojo::Headers' );
Expected Output:
$VAR1 = bless( {
'headers' => {
'accept-encoding' => [
'br'
],
'user-agent' => [
'req->headers'
]
}
}, 'Mojo::Headers' );
$VAR1 = bless( {
'headers' => {
'accept-encoding' => [
'br'
],
'user-agent' => [
'req->content->headers'
]
}
}, 'Mojo::Headers' );
If this behaviour is not intentional, then maybe headers should be defined as follows
sub headers { shift->content->headers(@_) }
the headers attribute on
Mojo::Messageis currently defined asmojo/lib/Mojo/Message.pm
Line 126 in 19fc4f1
Which has the effect of ignoring any arguments passed to
headers.Is this intentional? The docs mention that
message->headersis the same asmessage->content->headersReproducer:
Actual Output:
Expected Output:
If this behaviour is not intentional, then maybe headers should be defined as follows