mirror of
https://github.com/silkimen/cordova-plugin-advanced-http.git
synced 2026-01-31 00:00:03 +08:00
feat: #158 support removing headers which were previously set via "setHeader"
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
|
||||
## 3.0.0
|
||||
|
||||
- Feature #158: support removing headers which were previously set via "setHeader"
|
||||
|
||||
- :warning: **Breaking Change**: Dropped support for Android < 5.1
|
||||
- :warning: **Breaking Change**: Removed "disableRedirect", use "setFollowRedirect" instead
|
||||
- :warning: **Breaking Change**: Removed "setSSLCertMode", use "setServerTrustMode" instead
|
||||
|
||||
@@ -49,6 +49,13 @@ describe('Advanced HTTP public interface', function () {
|
||||
http.getHeaders('*').myKey.should.equal('myValue');
|
||||
});
|
||||
|
||||
it('clears global headers correctly when value is undefined', () => {
|
||||
http.setHeader('*', 'myKey', 'myValue');
|
||||
http.setHeader('*', 'myKey', null);
|
||||
should.equal(undefined, http.getHeaders('*').myKey);
|
||||
Object.keys(http.getHeaders('*')).length.should.be.equal(0);
|
||||
});
|
||||
|
||||
it('sets host headers correctly #24', () => {
|
||||
http.setHeader('www.google.de', 'myKey', 'myValue');
|
||||
http.getHeaders('www.google.de').myKey.should.equal('myValue');
|
||||
|
||||
@@ -187,7 +187,9 @@ module.exports = function init(global, jsUtil, cookieHandler, messages, base64,
|
||||
}
|
||||
|
||||
function checkForInvalidHeaderValue(value) {
|
||||
if (jsUtil.getTypeOf(value) !== 'String') {
|
||||
var type = jsUtil.getTypeOf(value);
|
||||
|
||||
if (type !== 'String' && type !== 'Null') {
|
||||
throw new Error(messages.INVALID_HEADER_VALUE);
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ module.exports = {
|
||||
INVALID_DATA_SERIALIZER: 'advanced-http: invalid serializer, supported serializers are:',
|
||||
INVALID_DOWNLOAD_FILE_PATH: 'advanced-http: invalid "filePath" value, needs to be a string, <filePath: string>',
|
||||
INVALID_FOLLOW_REDIRECT_VALUE: 'advanced-http: invalid follow redirect value, needs to be a boolean value, <followRedirect: boolean>',
|
||||
INVALID_HEADER_VALUE: 'advanced-http: invalid header value, needs to be a string, <header: string>',
|
||||
INVALID_HEADER_VALUE: 'advanced-http: invalid header value, needs to be a string or null, <header: string | null>',
|
||||
INVALID_HTTP_METHOD: 'advanced-http: invalid HTTP method, supported methods are:',
|
||||
INVALID_RESPONSE_TYPE: 'advanced-http: invalid response type, supported types are:',
|
||||
INVALID_SSL_CERT_MODE: 'advanced-http: invalid SSL cert mode, supported modes are:',
|
||||
|
||||
@@ -58,7 +58,12 @@ module.exports = function init(exec, cookieHandler, urlUtil, helpers, globalConf
|
||||
helpers.checkForInvalidHeaderValue(value);
|
||||
|
||||
globalConfigs.headers[host] = globalConfigs.headers[host] || {};
|
||||
globalConfigs.headers[host][header] = value;
|
||||
|
||||
if (value === null) {
|
||||
delete globalConfigs.headers[host][header];
|
||||
} else {
|
||||
globalConfigs.headers[host][header] = value;
|
||||
}
|
||||
}
|
||||
|
||||
function getDataSerializer() {
|
||||
|
||||
Reference in New Issue
Block a user