mirror of
https://github.com/silkimen/cordova-plugin-advanced-http.git
synced 2026-02-22 00:00:04 +08:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c387e52ea3 | ||
|
|
f87afa2217 |
@@ -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
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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
|
||||
|
||||
33
src/browser/cordova-http-plugin.js
vendored
33
src/browser/cordova-http-plugin.js
vendored
@@ -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');
|
||||
|
||||
Reference in New Issue
Block a user