Add accept: application/json header if json option is set
@ -55,6 +55,10 @@ function got(url, opts, cb) {
delete opts.timeout;
delete opts.query;
if (json) {
opts.headers.accept = opts.headers.accept || 'application/json';
}
if (body) {
opts.method = opts.method || 'POST';
@ -76,7 +76,7 @@ Default: `false`
_This option and stream mode are mutually exclusive._
If enabled, response body will be parsed with `JSON.parse`.
If enabled, response body will be parsed with `JSON.parse` and `accept` header will be set to `application/json` by default.
###### query
@ -32,6 +32,13 @@ tape('send accept-encoding header by default', function (t) {
});
tape('send accept header with json option', function (t) {
got(s.url, {json: true}, function (err, headers) {
t.equal(headers.accept, 'application/json');
t.end();
tape('send host header by default', function (t) {
got(s.url, function (err, data) {
var headers = JSON.parse(data);