-
Notifications
You must be signed in to change notification settings - Fork 4.5k
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
'Content-Length' header not always returned when enumerating HttpContentHeaders #16162
Comments
Next step: We need a repro (@davidsh you said you might have it - it is simple ~6 lines), then debug it and fix it. |
I have no context on this issue; I just made a tracking issue because we had references to an old bug tracker in the code, and I was worried we would forget about it entirely. This might not even be a problem anymore. |
This repros in .NET Framework (Desktop) and .NET Core. It is an old bug from .NET Framework and has been there since we first shipped HttpClient in .NET 4.5. Over time, this bug has become more annoying and impactful to developers. [Fact]
public void ContentLength_CreateStringContent_HeaderPresentInToString()
{
string data = "This is a test";
var content = new StringContent(data);
string headers = content.Headers.ToString();
Console.WriteLine(headers);
Assert.IsTrue(headers.Contains("Content-Length"));
}
[Fact]
public void ContentLength_CreateStringContentAndAccessPropertyHeader_HeaderPresentInToString()
{
string data = "This is a test";
var content = new StringContent(data);
// Calling the 'getter' for the ContentLength property will reconcile the strings cache.
Console.WriteLine("content.Headers.ContentLength={0}", content.Headers.ContentLength);
string headers = content.Headers.ToString();
Console.WriteLine(headers);
Assert.IsTrue(headers.Contains("Content-Length"));
} Test [2] always passes. This is good. |
@karelz Hello. Can I take this? |
Info about how to fix this from @Tratcher during this PR.
|
I am going to do the first part - option A. |
any update on that? i'm still facing that issue. Without calling |
Triage: Option A is worth doing - it should be simple. @satano looks like you're not working on it, so unassigning. |
@karelz I'd like to pick up this issue. |
@heemskerkerik sorry for delayed answer, if you are still interested, we'd be happy to help you out to make this happen. Thanks! |
@karelz I'm still interested. I've made some local changes, and I ran into an issue. The solution suggested was to add the Reading the RFCs, this does not seem to be wrong, per se, but it is obviously unnecessary. An obvious solution is to adjust Does this sound reasonable? |
Run app that has a directory that ends in a dot (fix [dotnet#16162](https://github.com/dotnet/coreclr/issues/16162)).
Any update on this so far? |
For reference, #102416 fixes this for built-in If you have other custom |
See #102986 (comment) -- this particular change was reverted.
@michal-zatloukal the issue you are hitting is likely something else. If the response content doesn't have a content length, it's either because it was not sent by the server, or because it was removed (e.g. #42789). |
@MihaZupan It must have been set by the server because This makes implementing forwarding HTTP requests pain, because the See sample #102986 (comment) |
I was digging a bit deeper and made a minimal reproduction repository: I think now I understand the problem completely. The issue occurs when the remote HTTP server doesn't specify But the It returns the calculated value not the value of @MihaZupan could you please re-open the issue as it wasn't fixed by the mentioned PR which was reverted? |
We've reverted that particular (already limited) change because of backward compatibility concerns. Updating the documentation for the Gets or sets the value of the Content-Length content header on an HTTP response.
+If the header was never set, the value may be calculated on demand if the content was already buffered, or via `HttpContent.TryComputeLength`. P.S. For scenarios where you're proxying requests, I'd recommend looking at YARP. |
@MihaZupan I agree with the documentation change and understand the backward compatability concerns. |
Duplicated from internal bug 122111. Creating this tracking issue here so that we can trace these through the markers in the code back to the original internal bug tracker discussions if necessary.
The text was updated successfully, but these errors were encountered: