Compare commits

..

2 Commits

Author SHA1 Message Date
Sefa Ilkimen
c387e52ea3 release v2.0.1 2018-09-04 02:20:15 +02:00
Sefa Ilkimen
f87afa2217 - fix #136: Content-Type header not overwritable on browser platform
- remove obsolete methods "enableSSLPinning" and "acceptAllCerts"
2018-09-04 01:56:17 +02:00
4 changed files with 30 additions and 11 deletions

View File

@@ -1,5 +1,9 @@
# Changelog
## 2.0.1
- Fixed #136: Content-Type header non-overwritable on browser platform
## 2.0.0
- Feature #103: implement HTTP SSL cert modes

View File

@@ -1,6 +1,6 @@
{
"name": "cordova-plugin-advanced-http",
"version": "2.0.0",
"version": "2.0.1",
"description": "Cordova / Phonegap plugin for communicating with HTTP servers using SSL pinning",
"scripts": {
"updatecert": "node ./scripts/update-test-cert.js",

View File

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<plugin xmlns="http://www.phonegap.com/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android" id="cordova-plugin-advanced-http" version="2.0.0">
<plugin xmlns="http://www.phonegap.com/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android" id="cordova-plugin-advanced-http" version="2.0.1">
<name>Advanced HTTP plugin</name>
<description>
Cordova / Phonegap plugin for communicating with HTTP servers using SSL pinning

View File

@@ -74,9 +74,27 @@ function createXhrFailureObject(xhr) {
return obj;
}
function getHeaderValue(headers, headerName) {
let result = null;
Object.keys(headers).forEach(function(key) {
if (key.toLowerCase() === headerName.toLowerCase()) {
result = headers[key];
}
});
return result;
}
function setDefaultContentType(headers, contentType) {
if (getHeaderValue(headers, 'Content-Type') === null) {
headers['Content-Type'] = contentType;
}
}
function setHeaders(xhr, headers) {
Object.keys(headers).forEach(function(key) {
if (key === 'Cookie') return;
if (key.toLowerCase() === 'cookie') return;
xhr.setRequestHeader(key, headers[key]);
});
@@ -101,7 +119,7 @@ function sendRequest(method, withData, opts, success, failure) {
switch (serializer) {
case 'json':
xhr.setRequestHeader('Content-Type', 'application/json; charset=utf8');
setDefaultContentType(headers, 'application/json; charset=utf8');
processedData = serializeJsonData(data);
if (processedData === null) {
@@ -111,12 +129,12 @@ function sendRequest(method, withData, opts, success, failure) {
break;
case 'utf8':
xhr.setRequestHeader('Content-Type', 'text/plain; charset=utf8');
setDefaultContentType(headers, 'text/plain; charset=utf8');
processedData = data.text;
break;
case 'urlencoded':
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
setDefaultContentType(headers, 'application/x-www-form-urlencoded');
processedData = serializeParams(data);
break;
}
@@ -166,11 +184,8 @@ var browserInterface = {
downloadFile: function (success, failure, opts) {
return failure('advanced-http: function "downloadFile" not supported on browser platform');
},
enableSSLPinning: function (success, failure, opts) {
return failure('advanced-http: function "enableSSLPinning" not supported on browser platform');
},
acceptAllCerts: function (success, failure, opts) {
return failure('advanced-http: function "acceptAllCerts" not supported on browser platform');
setSSLCertMode: function (success, failure, opts) {
return failure('advanced-http: function "setSSLCertMode" not supported on browser platform');
},
disableRedirect: function (success, failure, opts) {
return failure('advanced-http: function "disableRedirect" not supported on browser platform');