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

AddCustomHeader #1045

Open
tcunay opened this issue Feb 13, 2024 · 8 comments
Open

AddCustomHeader #1045

tcunay opened this issue Feb 13, 2024 · 8 comments

Comments

@tcunay
Copy link

tcunay commented Feb 13, 2024

Hello. Thanks for the great tool!
I have a question: The "AddCustomHeader" method removes all other headers. Is it possible to add a title without deleting the rest?

@tcunay
Copy link
Author

tcunay commented Feb 13, 2024

My code
image

@KojiNakamaru
Copy link
Member

I introduced #1046 and #1047 and updated binaries. I haven't tested it yet, but theoretically existing headers are added for API level 21 or later.

@tcunay
Copy link
Author

tcunay commented Feb 14, 2024

Dont work(

@tcunay
Copy link
Author

tcunay commented Feb 14, 2024

Headers with AddCustomHeader
image

@tcunay
Copy link
Author

tcunay commented Feb 14, 2024

Headers Without AddCustomHeader()
image

@KojiNakamaru
Copy link
Member

I've uploaded a modified sample app under:

https://github.com/gree/unity-webview/tree/example-for-1045/sample

which can be directly opened and built with 2020.3.48f1. Its code is modified as below:

da2d83c

You can see headers by tapping the link of https://httpbin.org/headers . It seems working at least on my device (OSCAL Pad 8, Android 11).

@tcunay
Copy link
Author

tcunay commented Feb 14, 2024

If you add two custom headers, the previous one will not be removed. But for some reason other headers are removed.
image

image

@KojiNakamaru
Copy link
Member

Okay, I also tested the case in which no AddCustomHeader() was called:

{ 
  "headers": {
    "Accept": "text/html, application/xhtml+ml,application/xml;q=0.9, image/avif, image/webp, image/apng,*/*;q=0.8,application/signed-exchange;v=b3; q=0. 7",
    "Accept-Encoding": "gzip, deflate, br"
    "Accept-Language": "en-US, en; q=0.9, ja-JP; q=0.8, ja;q=0.7",
    "Host": "httpbin.org"
    "Sec-Ch-Ua": "\"Not A(Brand\";v=\"99\", \"Android WebView\";v=\"121\", \"Chromium\";v=\"121\"",
    "Sec-Ch-Ua-Mobile": "?0"
    "Sec-Ch-Ua-Platform": "\"Android\"",
    "Sec-Fetch-Dest": "document"
    "Sec-Fetch-Mode": "navigate"
    "Sec-Fetch-Site": "cross-site"
    "Sec-Fetch-User": "?1"
    "Upgrade-Insecure-Requests": "1"
    "User-Agent": "Mozilla/5.0 (Linux; Android 11; Pad 8 Build/RP1A. 201005.001; WV) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/121. 0.6167.144 Safari/537.36"
    "X-Amzn-Trace-Id": "Root=1-65cccf41-70eebc4743f3b6c7aff32ac",
    "X-Requested-With": "net.gree.webview. sample"
  }
}

On the other hand, if AddCustomHeader("x-auth", ...) was called:

{ 
  "headers": {
    "Accept": "text/html, application/xhtml+ml,application/xml;q=0.9, image/avif, image/webp, image/apng,*/*;q=0.8, application/signed-exchange; v=b3; q=0. 7",
    "Accept-Encoding": "gzip",
    "Host": "httpbin.org"
    "Sec-Ch-Ua": "\"Not A(Brand\";v=\"99\", \"Android WebView\";v=\"121\", \"Chromium\";v=\"121\"",
    "Sec-Ch-Ua-Mobile": "?0"
    "Sec-Ch-Ua-Platform": "\"Android\""
    "Upgrade- Insecure-Requests": "1"
    "User-Agent": "Mozilla/5.0 (Linux; Android 11; Pad 8 Build/RP1A. 201005.001; WV) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/121.0.6167.144 Safari/537.36",
    "X-Amzn-Trace-Id": "Root=1-65cccfe2-506af9962ddb4b5d03a7f634",
    "X-Auth": "Bearer 0123456789abcdef"
  }
}

If we use the plugin before #1046 / #1047 and AddCustomHeader("x-auth", ...) was called:

{ 
  "headers": {
    "Accept-Encoding": "gzip",
    "Host": "httpbin.org"
    "User-Agent": "Mozilla/5.0 (Linux; Android 11; Pad 8 Build/RP1A.201005.001; WV) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/121.0.6167.144 Safari/537.36"
    "X-Amzn-Trace-Id": "Root=1-65ccd589-1868cada29dba578253daf36",
    "X-Auth": "Bearer 0123456789abcdef"
  }
}

Thus #1046 / #1047 reduces the issue, but incomplete. The implementation utilizes https://developer.android.com/reference/android/webkit/WebViewClient#shouldInterceptRequest(android.webkit.WebView,%20android.webkit.WebResourceRequest) and retrieves existing headers from a WebResourceRequest argument. This WebResourceRequest seems not to have every header, unfortunately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants