mirror of
https://github.com/tenrok/axios.git
synced 2026-06-20 20:00:40 +03:00
+10
-2
@@ -20,8 +20,16 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
if (utils.isObject(data) && !utils.isFile(data) && !utils.isBlob(data)) {
|
if (utils.isObject(data) && !utils.isFile(data) && !utils.isBlob(data)) {
|
||||||
// Set application/json if no Content-Type has been specified
|
// Set application/json if no Content-Type has been specified
|
||||||
if (!utils.isUndefined(headers) && utils.isUndefined(headers['Content-Type'])) {
|
if (!utils.isUndefined(headers)) {
|
||||||
headers['Content-Type'] = 'application/json;charset=utf-8';
|
utils.forEach(headers, function (val, key) {
|
||||||
|
if (key.toLowerCase() === 'content-type') {
|
||||||
|
headers['Content-Type'] = val;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (utils.isUndefined(headers['Content-Type'])) {
|
||||||
|
headers['Content-Type'] = 'application/json;charset=utf-8';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return JSON.stringify(data);
|
return JSON.stringify(data);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,6 +56,29 @@ describe('requests', function () {
|
|||||||
}, 0);
|
}, 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should allow overriding Content-Type header case-insensitive', function (done) {
|
||||||
|
var request, response;
|
||||||
|
var contentType = 'application/vnd.myapp.type+json';
|
||||||
|
|
||||||
|
axios({
|
||||||
|
url: '/foo',
|
||||||
|
method: 'post',
|
||||||
|
data: { prop: 'value' },
|
||||||
|
headers: {
|
||||||
|
'content-type': contentType
|
||||||
|
}
|
||||||
|
}).then(function (res) {
|
||||||
|
response = res;
|
||||||
|
});
|
||||||
|
|
||||||
|
setTimeout(function () {
|
||||||
|
request = jasmine.Ajax.requests.mostRecent();
|
||||||
|
|
||||||
|
expect(request.requestHeaders['Content-Type']).toEqual(contentType);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('should support binary data as array buffer', function (done) {
|
it('should support binary data as array buffer', function (done) {
|
||||||
var request;
|
var request;
|
||||||
var input = new Int8Array(2);
|
var input = new Int8Array(2);
|
||||||
|
|||||||
Reference in New Issue
Block a user