Skip to content
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

bug: Android: cookie handling for proxied requests + avoid creating a new connection to check the contentType #2831

Closed
1 task
goapilz opened this issue Apr 26, 2020 · 11 comments

Comments

@goapilz
Copy link

goapilz commented Apr 26, 2020

Bug Report

Capacitor Version

master

Affected Platform(s)

  • Android

Current Behavior

When using the "server.url" parameter in the capacitor.config.json to retrieve the app data from an external server incoming cookies are not saved to the CookieManager. Also an additional connection is opened in handleProxyRequest to check the contentType.

see: WebViewLocalServer:handleProxyRequest
see: JSInjector:getInjectedStream

My scenario:
Currently I use capacitor to add a native barcode scanner to my PWA app.
When running as simple PWA, the "browser camera api" is used, but when running in the capacitor app the native barcode scanner should be used.
Therefore capacitor seems to be the perfect framework.
But currently i have the described problem when the authentication cookie should be saved.

I would be happy if my change would be included in the project.

Expected Behavior

save incoming cookies (also when getting text/html files)

Sample Code or Sample Application Repo

see fix.zip

Reproduction Steps

fix.zip

Other Technical Details

Other Information

@jcesarmobile
Copy link
Member

can you send a pull request with the changes?
spotting the proposed changes in a zip file is harder

@goapilz
Copy link
Author

goapilz commented May 4, 2020

can you send a pull request with the changes?
spotting the proposed changes in a zip file is harder

I created a pull request. Hope i made no mistake.

@goapilz
Copy link
Author

goapilz commented May 7, 2020

There is still the needs-reply label on this issue.
Also the push request displays "Review required".
Is there something i must do to get the pull request merged ?

@jcesarmobile jcesarmobile removed the needs reply needs reply from the user label May 7, 2020
@jcesarmobile
Copy link
Member

Sorry, I forgot to remove the label.
Can you provide a sample app where the cookies issue can be reproduced?

@goapilz
Copy link
Author

goapilz commented May 8, 2020

I added a zip with the capacitor config and a test server in node that delivers a simple page that will set and check the cookie.

Because you need a https connection to call this server from the android webview a quick solution is using a "tunneling service" like ngrok.

Download and start ngrok:
https://ngrok.com/download or npm install ngrok -g
start via: ngrok http 3000

Start the node server via: node server.js

Then enter the ngrok https address in capacitor.config.json and build a new android app.
(e.g.: https://f97410f4.ngrok.io/?authToken=secretAuthTokenABC789)

Hope this is enough input.

example.zip

@goapilz
Copy link
Author

goapilz commented May 25, 2020

It is possible to merge the pull request. I think the changes are marginal and will result in a better "connection and cookie handling". Currently for all get requests a new connection is opened to check the contentType for "text/html" This is not really needed because the header of the request still contains the contentType. Also the cookie is saved to the CookieManager when the server sends new cookies via the "Set-Cookie" header.

Due to this bug i must always patch my local installation after a fresh "npm install" which is very inconvenient.

@IlCallo
Copy link

IlCallo commented May 29, 2020

When using the "server.url" parameter in the capacitor.config.json to retrieve the app data from an external server incoming cookies are not saved to the CookieManager

@goapilz do you have any idea about why this happens?
Could #3012 be related?

@goapilz
Copy link
Author

goapilz commented May 29, 2020

@IlCallo yes i think this is the same issue.
The cookie is not stored when the custom handling for a GET request (contentType "text/html") is used.

Please merge my pull request so i can use you great capacitor project without patching ;-)

@jcesarmobile
Copy link
Member

jcesarmobile commented Jun 9, 2020

fixed by #3078 and #3076

thanks for the sample project, was very helpful

@goapilz
Copy link
Author

goapilz commented Jun 10, 2020

Thanks for merging !

@ionitron-bot
Copy link

ionitron-bot bot commented Nov 11, 2022

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Capacitor, please create a new issue and ensure the template is fully filled out.

@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators Nov 11, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
3 participants