-
Notifications
You must be signed in to change notification settings - Fork 2.2k
feat(android,ios): add request headers support #363
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -98,7 +98,7 @@ | |
} | ||
}; | ||
|
||
module.exports = function (strUrl, strWindowName, strWindowFeatures, callbacks) { | ||
module.exports = function (strUrl, strWindowName, strWindowFeatures, windowHeaders, callbacks) { | ||
// Don't catch calls that write to existing frames (e.g. named iframes). | ||
if (window.frames && window.frames[strWindowName]) { | ||
var origOpenFunc = modulemapper.getOriginalSymbol(window, 'open'); | ||
|
@@ -116,10 +116,29 @@ | |
var cb = function (eventname) { | ||
iab._eventHandler(eventname); | ||
}; | ||
|
||
var strWindowHeaders = ''; | ||
if (windowHeaders) { | ||
if (typeof windowHeaders === 'string' || windowHeaders instanceof String) { | ||
strWindowHeaders = windowHeaders.replace(/@/gi, '@a'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what exactly is the reason for all the replacements of Wouldn't it be more readable and clearer to pass in a JSON object and then use Android's included JSONObject support to create a HashMap and iOS' included NSJSONSerialization? |
||
} else { | ||
var first = true; | ||
for (var k in windowHeaders) { | ||
if (windowHeaders.hasOwnProperty(k)) { | ||
var key = k.replace(/@/gi, '@a').replace(/,/gi, '@c').replace(/=/gi, '@e'); | ||
var value = windowHeaders[k].toString().replace(/@/gi, '@a').replace(/,/gi, '@c').replace(/=/gi, '@e'); | ||
if (first) { | ||
first = false; | ||
} else { | ||
strWindowHeaders += ','; | ||
} | ||
strWindowHeaders += key + '=' + value; | ||
} | ||
} | ||
} | ||
} | ||
strWindowFeatures = strWindowFeatures || ''; | ||
|
||
exec(cb, cb, 'InAppBrowser', 'open', [strUrl, strWindowName, strWindowFeatures]); | ||
exec(cb, cb, 'InAppBrowser', 'open', [strUrl, strWindowName, strWindowFeatures, strWindowHeaders]); | ||
return iab; | ||
}; | ||
})(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why all those changes to the
loadUrl
calls if we don't actually change the method signature ourselves? Couldn't we just keep these as they are and only add theheaders
in the places where we need it?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this was to explicitely mark headers were null for easier code navigation