Skip to content

Commit

Permalink
build for WKWebview updating
Browse files Browse the repository at this point in the history
  • Loading branch information
ianwith committed Sep 7, 2017
1 parent 2eefd0e commit 3f06eec
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions lib/rexxarFetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var isAndroid = navigator ? /android/i.test(navigator.userAgent.toLowerCase()) :
/**
* `rexxarFetch` wraps whatwg-fetch function. Use rexxarFetch like using the normal fetch API.
* However, there are some limitation, rexxarFetch does not support Request object as
* argument when you are using for POST in Android, and `application/x-www-form-urlencoded`
* argument when you are using for HTTP POST, and `application/x-www-form-urlencoded`
* must be specified as content-type.
*
* @param {string|object} input Url string or a Request object
Expand All @@ -34,32 +34,32 @@ function rexxarFetch(input, init) {

if (Request.prototype.isPrototypeOf(input) && !init) {
request = input;
if (request.method === 'POST' && isAndroid) {
throw new Error('Please use `rexxarFetch(input, init)` for HTTP POST in Android');
if (request.method === 'POST') {
throw new Error('rexxarFetch POST error: please use `rexxarFetch(input, init)` for HTTP POST');
}
} else {
request = new Request(input, init);
}

if (request.method === 'POST' && isAndroid) {
if (request.method === 'POST') {
var contentType = request.headers.get('content-type');
var body = init.body;

if (!contentType && !body) {
input = (input + '&_rexxar_method=POST').replace(/[&?]/, '?');
promise = (0, _isomorphicFetch2.default)(input);
} else if (contentType && contentType.indexOf('application/x-www-form-urlencoded') > -1) {
if (window && 'URLSearchParams' in window && URLSearchParams.prototype.isPrototypeOf(body)) {
if (window && 'URLSearchParams' in window && window.URLSearchParams.prototype.isPrototypeOf(body)) {
body = body.toString();
}
if ((0, _utils.getType)(body) === 'String') {
input = (input + '&' + body + '&_rexxar_method=POST').replace(/[&?]/, '?');
promise = (0, _isomorphicFetch2.default)(input);
} else {
throw new Error('rexxarFetch for Android Cannot handle this body type');
throw new Error('rexxarFetch POST error: cannot handle this body type');
}
} else {
throw new Error('rexxarFetch for Android only supports `application/x-www-form-urlencoded` as content-type');
throw new Error('rexxarFetch POST error: only supports `application/x-www-form-urlencoded` as content-type');
}
} else {
promise = (0, _isomorphicFetch2.default)(request);
Expand Down

0 comments on commit 3f06eec

Please sign in to comment.