Subject: | Content-Type in default_headers seems to be overwritten by POST and PUT |
This is easier to show with Mechanize:
my $mech = WWW::Mechanize->new(
default_headers => HTTP::Headers->new(
Content_Type => 'application/json',
Accept => 'application/json',
)
);
$mech->post('http://localhost:6000/',
Content => encode_json({
user => 'test',
password => 'password'
}),
);
I have determined that 'default_headers' is correctly forwarded to LWP here.
LWP::UserAgent::new([...]/LWP/UserAgent.pm:28):
28: my $agent = delete $cnf{agent};
DB<1> x %cnf
0 'default_headers'
1 HTTP::Headers=HASH(0xebe47f0)
'accept' => 'application/json'
'content-type' => 'application/json'
2 'cookie_jar'
3 HASH(0xec817e8)
empty hash
4 'agent'
5 'WWW-Mechanize/1.75'
A tcpdump of this transaction shows that Content-Type was set to application/x-www-form-urlencoded:
POST / HTTP/1.1
TE: deflate,gzip;q=0.3
Connection: TE, close
Accept: application/json
Accept-Encoding: gzip
Host: localhost:6000
User-Agent: WWW-Mechanize/1.75
Content-Length: 37
Content-Type: application/x-www-form-urlencoded
{"password":"password","user":"test"}
This is also true of PUT, but I exemplified POST because Mechanize inherits this directly from LWP without interference, so I can be sure of the source of the issue.