Skip to content

feat(android,ios): add request headers support#363

Open
al1lhomme wants to merge 2 commits into
apache:masterfrom
al1lhomme:master
Open

feat(android,ios): add request headers support#363
al1lhomme wants to merge 2 commits into
apache:masterfrom
al1lhomme:master

Conversation

@al1lhomme

@al1lhomme al1lhomme commented Dec 4, 2018

Copy link
Copy Markdown

Platforms affected

android, ios

What does this PR do?

add request headers support

What testing has been done on this change?

automated test still working
test using headers in my app


closes #361
replaces #115

@janpio janpio changed the title (issue-#361) (iOS & Android) add request headers support (iOS & Android) add request headers support Dec 4, 2018
@janpio

This comment has been minimized.

@ehorodyski

Copy link
Copy Markdown

Looking for the same thing, will this become a feature in the short term?

@virtualprodigy

Copy link
Copy Markdown

I would like this feature as well. Any ETAs on this?

@janpio

janpio commented Jan 16, 2019

Copy link
Copy Markdown
Member

You can help by testing this locally (via the fork of @al1lhomme that contains these changes) and reporting back if it worked as expected.

@metju312

Copy link
Copy Markdown

Could I ask for progress? This feature is all I need to download any type of files from my server with authentication Header.

hvaughan3 added a commit to hvaughan3/cordova-plugin-inappbrowser that referenced this pull request Apr 30, 2019
@hvaughan3

hvaughan3 commented May 1, 2019

Copy link
Copy Markdown

@janpio Just merged this into our fork and it seems to be working. It sends headers on the first request and on page reload. Tested on iOS and Android. Did not test using IAB's WKWebView mode.

@timbru31 timbru31 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added some comments.


Could you also rebase your change?

Comment thread www/inappbrowser.js
var strWindowHeaders = '';
if (windowHeaders) {
if (typeof windowHeaders === 'string' || windowHeaders instanceof String) {
strWindowHeaders = windowHeaders.replace(/@/gi, '@a');

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what exactly is the reason for all the replacements of @ and = if you just re-replace it in the corresponding Java/Objective-C code?

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?

@timbru31

timbru31 commented Jul 7, 2019

Copy link
Copy Markdown
Member

This seems the same as PR #115 - but 3 years newer with fewer conflicts.

@BrandOuellette

Copy link
Copy Markdown

If this feature will allow us to override the User-Agent header, it would fulfill our feature request #502

@janpio janpio changed the title (iOS & Android) add request headers support feat(android,ios): add request headers support Jul 8, 2019
@janpio

janpio commented Jul 8, 2019

Copy link
Copy Markdown
Member

Resolved the conflict.

((InAppBrowserClient)inAppWebView.getWebViewClient()).waitForBeforeload = false;
}
inAppWebView.loadUrl(url);
inAppWebView.loadUrl(url, null);

Copy link
Copy Markdown
Member

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 the headers in the places where we need it?

Copy link
Copy Markdown

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

@janpio

janpio commented Jul 8, 2019

Copy link
Copy Markdown
Member

Have to test this for both platforms, and on iOS for both webview types.

Someone have a page handy that shows the headers that were used to call it? Then it should be pretty simple to create a test app.

We should probably also try to add this to the tests somehow.

@BrandOuellette

BrandOuellette commented Jul 8, 2019

Copy link
Copy Markdown

Someone have a page handy that shows the headers that were used to call it?

https://postman-echo.com/headers

@BrandOuellette

BrandOuellette commented Jul 12, 2019

Copy link
Copy Markdown

Any update on this?
I really hope we're not waiting on @al1lhomme because it looks like he hasn't been on github for 9 months.

@janpio

janpio commented Jul 12, 2019

Copy link
Copy Markdown
Member

We will have to find solutions to the comments that are open here. Some questions regarding the code, no new tests, no tested yet.

Anyone who wants to jump in and is not a contributor here (who can edit the fork directly) can just fork at https://github.com/al1lhomme/cordova-plugin-inappbrowser and then create a new PR to this repo and let us know here via a comment.

@jplajpla23

Copy link
Copy Markdown

how can i use the version with custom headers?

@starnetdev0

Copy link
Copy Markdown

Hi, I have tested the PullRequest in Android and it works ok.
I have to add a new header to inappbrowser due to the fact that Google will block Google Sign In on January 4, 2021 from embedded browser frameworks.
https://developers.googleblog.com/2020/08/guidance-for-our-effort-to-block-less-secure-browser-and-apps.html

Surprisingly, adding the new header "Google-Accounts-Check-OAuth-Login:true", Google Sign seems to be working. I am using browserTarget: '_blank'

@BradCB

BradCB commented Nov 24, 2020

Copy link
Copy Markdown

I have tested and used the PullRequest in Android and iOS. Headers are working.

@trafficteam7

Copy link
Copy Markdown

I have tested and used the PullRequest in Android and iOS. Headers are working.

Doesn't work for me. Tested with Cordova Android 9.0.0. Made all changes in InAppBrowser.java, inappbrowser.js and index.js
By the way: I have 3 files with name InAppBrowser.java - which one should I edit?

@Aiuspaktyn

Copy link
Copy Markdown

Any news about this PR?

@laurentperez

Copy link
Copy Markdown

Can confirm this works on Android 10, we did not try to patch iOS because our ionic wrapper uses SafariWebviewController and not InAppBrowser

thx @al1lhomme

@karimaziz

Copy link
Copy Markdown

Helllo guys, any news on this PR? It's been pending since 2018... Being able to pass headers is quite important and useless for several cases...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

adding support for passing request headers