iOS: XHR response headers missing
See original GitHub issueBug Report
This appears to be opposite end of the problem in #951, the response headers from my API server are not accessible via the XMLHttpRequest instance running the request. Perhaps there’s some middle layer (isn’t there a local webserver that proxies requests?) that does not pipe the response to JS verbatim.
Capacitor Version
`npx cap doctor` output:
💊 Capacitor Doctor 💊
Latest Dependencies:
@capacitor/cli: 1.5.0
@capacitor/core: 1.5.0
@capacitor/android: 1.5.0
@capacitor/ios: 1.5.0
Installed Dependencies:
@capacitor/android not installed
@capacitor/cli 1.5.0
@capacitor/core 1.5.0
@capacitor/ios 1.5.0
Found 0 Capacitor plugins for ios:
[success] iOS looking great! 👌
Affected Platform(s)
- Android
- iOS
- Electron
- Web
Current Behavior
Currently, requests made via XMLHttpRequest
only read back Content-Length
and Content-Type
headers, despite numerous other headers being sent.
Expected Behavior
Expect access to all the response headers that a web browser would allow. Providing access to response headers would need to take care to hide some of the private headers (like Set-Cookie
I believe), but I specifically need to access my API’s custom X-Header-Name
type headers.
Reproduction Steps
- Use XMLHttpRequest to make a request:
https://jsonplaceholder.typicode.com/todos/1
- Use the xhr instance to pull a custom header
xhr.getResponseHeader("x-powered-by")
- Expect to see
"Express"
, but receivenull
Issue Analytics
- State:
- Created 4 years ago
- Comments:9 (3 by maintainers)
Top Results From Across the Web
Headers missing from XMLHttpRequest on iOS UIWebView
For some reason this XMLHttpRequest returns only a subset of the Response Headers when queried using request.
Read more >XMLHttpRequest.getAllResponseHeaders() - Web APIs | MDN
The XMLHttpRequest method getAllResponseHeaders() returns all the response headers, separated by CRLF, as a string, or returns null if no ...
Read more >CORS Errors: Cross-Origin Resource Sharing - Ionic Framework
CORS errors happen in web apps if requests are made and servers don't return required headers. Read about Cross-Origin Resource Sharing in Ionic ......
Read more >Enabling CORS for a REST API resource - Amazon API Gateway
Usually this just means manually modifying the integration response to return the Access-Control-Allow-Origin header. Enabling CORS support for Lambda or HTTP ...
Read more >7 Keys to the Mystery of a Missing Cookie - Medium
Solution tip: Modify your client code, so the XHR request has an option ... OPTIONS response headers instructs a browser how to compose...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
If not a full app, at least the XHR code you used instead of saying “do a XHR call”, or providing a line of code where you where do do the fetch call instead of showing an image where you do it so I don’t have to type the code from the image.
But I’ve typed your same code from the image and I get the same 4 headers, so I still don’t think it’s a bug. And when doing a XHR call from Chrome, I get the
Refused to get unsafe header "x-powered-by"
. My googling skills tell me that’s a server configuration problem, not a Capacitor problem.And even if it was, it’s a WKWebView problem, not a Capacitor issue. We don’t do anything to XHR/fetch, and there is nothing we can do about it. You can wait for the HTTP plugin https://github.com/ionic-team/capacitor/pull/2495
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.