Skip to content

Commit

Permalink
Add the original headers to the custom request (iOS only for now) #10
Browse files Browse the repository at this point in the history
  • Loading branch information
EddyVerbruggen committed Mar 16, 2018
1 parent 80bfde8 commit ffc398d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nativescript-webview-utils",
"version": "2.0.2",
"version": "2.0.3",
"description": "Add custom headers to a NativeScript WebView. Perhaps more utils later.",
"main": "webview-utils",
"typings": "index.d.ts",
Expand Down
16 changes: 16 additions & 0 deletions src/webview-utils.ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ class WebviewUtilsWKNavigationDelegateImpl extends NSObject implements WKNavigat
timeoutInterval: 60
});

// add the original headers
for (let i = 0; i < navigationAction.request.allHTTPHeaderFields.count; i++) {
const headerKey = navigationAction.request.allHTTPHeaderFields.allKeys.objectAtIndex(i);
customRequest.setValueForHTTPHeaderField(
navigationAction.request.allHTTPHeaderFields.objectForKey(headerKey),
headerKey);
}

this.headers.forEach((val, key) => {
customRequest.setValueForHTTPHeaderField(val, key);
// the user agent is set as header, but also set this property:
Expand Down Expand Up @@ -148,6 +156,14 @@ export class WebViewUtils extends NSObject implements UIWebViewDelegate {
timeoutInterval: 60
});

// add the original headers
for (let i = 0; i < request.allHTTPHeaderFields.count; i++) {
const headerKey = request.allHTTPHeaderFields.allKeys.objectAtIndex(i);
nsMutableURLRequest.setValueForHTTPHeaderField(
request.allHTTPHeaderFields.objectForKey(headerKey),
headerKey);
}

WebViewUtils.headers.forEach((val, key) => {
nsMutableURLRequest.setValueForHTTPHeaderField(val, key);
if (key.toLowerCase() === "user-agent") {
Expand Down

0 comments on commit ffc398d

Please sign in to comment.