Recent changes due to PR dotnet/corefx#3199 caused `HttpClient` on Windows to miss
`Set-Cookie` response headers when one of the header values was large
enough to cause `WinHttpQueryHeaders` to fail with
`ERROR_INSUFFICIENT_BUFFER` and advance the index.
This commit addresses the regression, by always setting the index
back to the index we want to retrieve.
Added a new test to validate this change.
Fixesdotnet/corefx#6737.
Commit migrated from https://github.com/dotnet/corefx/commit/f7e9f00aba800d2ea63e040deafcc7ee220331fc
Recent changes due to PR dotnet/corefx#3199 caused the `HttpResponseMessage.ReasonPhrase` property to be a null string if the HTTP server response only contained a statuscode but no description on the status line. The existing .NET Framwork behavior is to have empty string as the property value in that case.
Added a new test to validate this change.
Fixesdotnet/corefx#6721.
Commit migrated from https://github.com/dotnet/corefx/commit/19ec320403cd53ad0cba75c69a1a2c027ed867d5
Both WinHttpHandler and WinHttpWebSocket use pinned buffers for receiving and sending data. The pinned GCHandle was being freed during the dispose of the WinHttpHandler or WinHttpWebSocket objects. The problem is that the buffer should not be unpinned until the async operation is done. It's possible for any async operation to be in flight (and where native code uses the buffer) when the object is explicitly or implicitly disposed.
This fix moves the ownership of the pinned GCHandle to their respective state objects (WinHttRequestState, WinHttpWebSocketState). These objects are strongly rooted and are not released until all async operations are completed and the WinHTTP handles are fully closed. That makes these state objects a safe place to own and free the pinned buffers.
Fixesdotnet/corefx#2508 and dotnet/corefx#6142
Commit migrated from https://github.com/dotnet/corefx/commit/a6eee4cec6bf663a030c8cd41f7a3fc3349b01e3
The fix made in PR dotnet/corefx#6285 for this memory leak turned out to be insufficient. The request handle object for the stream (SafeWinHttpHandle) was part of the strong root chain in WinHttpRequestState. And even when the WinHttpResponseStream object was finalized (implicit Dispose), the request handle was not finalized and thus leaks were happening.
To address this, the request handle object reference is now cleared from the WinHttpRequestState object (along with other object references) once the WinHttpResponseStream is created. WinHttpResponseStream then gets passed the request handle reference. Then normal finalizer rules can apply to both WinHttpResponseStream and the request handle. Once the request handle gets disposed (via finalizing), native WinHTTP will send a final status callback (HANDLE_CLOSING) and that is how the state object will then get unrooted and freed.
Tested this fix with WCF streaming scenarios and used WinDBG to verify the heaps.
There are future plans to improve this code via refactoring as part of dotnet/corefx#2501.
Fixes 5927.
Commit migrated from https://github.com/dotnet/corefx/commit/f2b47770d9014423ab830285b0fee47b75c44c02
Correct instances of new "ArgumentException(nameof(..." so names are in the correct parameter. Where possible, I chose the resource string I felt best fit the situation. Otherwise, I created a new entry (I'm assuming there's some extra work that needs to be done there, but don't know what it is offhand).
Commit migrated from https://github.com/dotnet/corefx/commit/368fdfd86ee3a3bf1bca2a6c339ee590f3d6505d
Fixes https://github.com/dotnet/corefx/issues/5707
We are changing the .NET packages to no longer use the ‘dotnet’, ‘dotnet5.x’, and ‘dnxcore50’ monikers. This is thee first stage of the change for dotnet->netstandard.
The replacements are as follows
Old moniker | New moniker
----------------- | ------------------
dotnet5.x | netstandard1.y (where y = x -1)
DNXCore50 | netstandardapp1.5
dotnet | netstandard1.3
To prepare for this change you can do the following to your project.json. This change will require a recent build of NuGet or dotnet.exe and can be done prior to consuming the packages with the breaking change. These packages will not work with DNX.
For a project targeting dotnet5.6
```
"frameworks": {
"netstandard1.5": {
"imports": [ "dotnet5.6" ]
}
},
```
For a project targeting dnxcore50
```
"frameworks": {
"netstandardapp1.5": {
"imports": [ "dnxcore50", "portable-net45+win8" ]
}
},
```
[tfs-changeset: 1578321]
Commit migrated from https://github.com/dotnet/corefx/commit/4435f9f2776ae007e05f4454675e56cf76a51975
WinHttpResponseStream was not tracking the amount of data read when the response used 'Content-Length' semantics. So, if the amount of bytes read from the server was less than expected, we did not return an error. This was different behavior than .NET Framework.
Fixed WinHttpResponseStream so that it will track the total number of bytes read and compare it to the expected number of bytes if using 'Content-Length' semantics. Note that we don't do this checking if the HTTP request is a HEAD request. That is because the definition of that HTTP verb is to return headers "as-if" it was returning a real response body. So, the 'Content-Length' might be set but there is no response body for a HEAD request.
For cases of using 'Transfer-Encoding: chunked' semantics for the response body, there is already error checking at the lower HTTP layer in WinHTTP.
Fixesdotnet/corefx#6231.
Commit migrated from https://github.com/dotnet/corefx/commit/7f5d6b643996306062836a17ddad643fd7e40ff2
The WinHttpHandler was leaking a lot of objects in cases where an explicit Dispose was not done for the various HttpResponseMessage related objects. It was leaking because there was a cycle between the strong GCHandle of WinHttpRequestState and the objects contained within it.
To break the cycle, we now clear out object references within WinHttpRequestState that are no longer needed once the SendRequest phase is completed.
There was also a leak of a pinned GCHandle and related memory in WinHttpResponseStream. The free'ing of that allocated GCHandle was done in the Dispose(bool disposing) method. However, it wasn't being called when disposing=false (i.e. a finalizer). Since it is a pinned GCHandle, it needed to be freed in all cases.
Fixesdotnet/corefx#5927.
Commit migrated from https://github.com/dotnet/corefx/commit/a38ee461d2d93cc220953b3b6c4b405b188f6965
- Fix Assert that was throwing in a background thread due to mistmatched type (it was looking explicitly for HttpResponseMessage rather than any type in its inheritance hierarchy, and CurlHandler uses a derived type).
- Update project.json package versions
- Unsubscribe the listener when done with it
Commit migrated from https://github.com/dotnet/corefx/commit/9a8d97852bcce9be0b4b6b5eff5ed87f4e36119e
Explicit static cctors cause the C# compiler to not mark types as beforefieldinit, which in turn means that the backend compiler needs to add checks to static methods to ensure that the type has been initialized. We have a bunch of such cctors across corefx that can be easily removed; this commit does so. In a few places, it also presizes some collections to help avoid unnecessary memory pressure.
Commit migrated from https://github.com/dotnet/corefx/commit/79ae21b1b9a113230da7ebfbffa4e3c3fe36f0ac
Some fixes (adding imports, adding Platforms package) were tooled, but more complex ones (forking project.jsons, editing csproj's) were not.
Also makes dependency version validation rules case-insensitive. (I used this fix to update the versions of some packages.)
[tfs-changeset: 1573868]
Commit migrated from https://github.com/dotnet/corefx/commit/84af04317505d48feaa1e83dd5dc27ddc0f6de76