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
net.request response is missing content-type header in 304 responses #27895
Comments
Thanks for reporting this and helping to make Electron better! Would it be possible for you to make a standalone testcase with only the code necessary to reproduce the issue? For example, Electron Fiddle is a great tool for making small test cases and makes it easy to publish your test case to a gist that Electron maintainers can use. Stand-alone test cases make fixing issues go more smoothly: it ensure everyone's looking at the same issue, it removes all unnecessary variables from the equation, and it can also provide the basis for automated regression tests. I'm adding the Thanks in advance! Your help is appreciated. |
No repro example yet, but just to add some details we've found since: |
I just hit the same problem : electron does not repopulate Also, I can confirm that the behaviour was different on electron <= 6 : up to electron6, the 200 seen in this case correctly has |
Here is a standalone testcase : https://gist.github.com/arantes555/99f8976266d340bad42b2894cb50d7d5 This shows that when the server responds with a 200, I also showed the behaviour of Also, with electron@6, everything is correct. |
we never got to the point of setting up our own server to test, but testing against GitHub and GitLab APIs, we only got a repro while we had something in the cache. For whatever reason, when we manually set our own |
Thanks for the standalone repro @arantes555! With that I've been able to confirm that this also happens on macOS, and in 12.x and 13.x. |
This looks like a regression caused by #21552. As an experiment, I tried adding the non-"raw" headers to the internal response object: diff --git a/shell/browser/api/electron_api_url_loader.cc b/shell/browser/api/electron_api_url_loader.cc
index afe48e40c..6a836f7af 100644
--- a/shell/browser/api/electron_api_url_loader.cc
+++ b/shell/browser/api/electron_api_url_loader.cc
@@ -68,6 +68,22 @@ struct Converter<network::mojom::CredentialsMode> {
}
}; // namespace gin
+template <>
+struct Converter<net::HttpResponseHeaders> {
+ static v8::Local<v8::Value> ToV8(
+ v8::Isolate* isolate,
+ const net::HttpResponseHeaders& headers) {
+ gin_helper::Dictionary dict = gin::Dictionary::CreateEmpty(isolate);
+ size_t i = 0;
+ std::string name;
+ std::string value;
+ while (headers.EnumerateHeaderLines(&i, &name, &value)) {
+ dict.Set(name, value);
+ }
+ return dict.GetHandle();
+ }
+};
+
} // namespace gin
namespace electron {
@@ -561,6 +577,8 @@ void SimpleURLLoaderWrapper::OnResponseStarted(
DCHECK(response_head.raw_request_response_info);
dict.Set("rawHeaders",
response_head.raw_request_response_info->response_headers);
+ dict.Set("headers",
+ *response_head.headers);
Emit("response-started", final_url, dict);
}
(NB. above patch is hacky and doesn't allow for repeated headers, it was just enough to let me see whether this theory about raw headers was correct.) The As further confirmation, the above PR was backported to 7.x in v7.1.10. When I run the fiddle on v7.1.9, it works as expected. cc @zcbenz |
We're not exactly sure why (this was reported from end users), but in very rare cases it's clear that this is also happening on non-304 responses as well, and no extra Right now our solution is to play fast and loose with content-type and simply attempt to parse anything missing its content-type as a JSON and see if it works. Hopefully nobody responds with plain-text |
I can confirm this is still happening up to 16.0.0-beta.2 . Also, here is a simplified test-case : https://gist.github.com/arantes555/4849273fe59b87313f0cb472ae65ae5b |
Thanks for checking, @arantes555. For our part, despite our best efforts to work around this problem, we've continued to hear about mysterious proxy issues with users (which may be this exact issue, or an unrelated problem with |
@Mr-Wallet Honestly, that is not a bad way to proceed ^^ the |
Yeah, not to throw shade on such an amazing free (!) project... it seems to me that if other Electron apps were trying to use Certainly, the limited attention available for Electron is going to mostly go with the majority of use cases, and most apps seem to be single-renderer and do absolutely everything from inside that single renderer. We're hoping that by acting more like a "normal" Electron app with regards to networking, we'll sidestep these issues entirely. |
This is still an issue in 18.2.2 (and 19.0.0-beta.5). Any news or plans to fix this? |
I have encountered the same issue while working with GitHub API. |
This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. If you have any new additional information—in particular, if this is still reproducible in the latest version of Electron or in the beta—please include it with your comment! |
bump |
Any news ? |
Right, seems like the problem is that we're using |
Preflight Checklist
Issue Details
10.1.7
Windows 10 Enterprise 1909
When making a request with
net.request
, I can see that my response has acontent-type
header ofapplication/json; charset=utf-8
inside of mywebRequest.onHeadersReceived
handler:But by the time the
net.request
request.on('response')
handler receives the headers, the content-type is gone.I haven't tested if this is an issue in all types of responses, but I can tell you this is occurring without fail for the case when the
response.statusCode === 200
, but theresponse.headers.status === 304
.Expected Behavior
For
net.request
response handler to receive the content-type that clearly should exist on the response (proved bywebRequest.onHeadersReceived
).Actual Behavior
net.request
response handler is receiving what seems to be a cached set of headers (or something?), which do not match what is seen inwebRequest.onHeadersReceived
.The text was updated successfully, but these errors were encountered: