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

WebHeaderCollection needs some internal APIs made public #21280

Closed
davidsh opened this issue Apr 22, 2017 · 8 comments
Closed

WebHeaderCollection needs some internal APIs made public #21280

davidsh opened this issue Apr 22, 2017 · 8 comments
Labels
area-System.Net bug disabled-test The test is disabled in source code against the issue
Milestone

Comments

@davidsh
Copy link
Contributor

davidsh commented Apr 22, 2017

While investigating failures in System.Net.Requests tests ( #20873), I discovered that FtpWebResponse.Headers and FileWebResponse.Headers is returning a WebHeaderCollection object that does not have the private field WebHeaderCollectionType properly initialized within the collection.

This causes code like this:

FileWebResponse response = ...
Assert.Equal(data.Length.ToString(), response.Headers[HttpResponseHeader.ContentLength]);

to pass on .NET Core (which is wrong). Instead, it should throw an exception

System.InvalidOperationException : This collection holds request headers and cannot contain the specified response header.

similar to what happens on .NET Framework. The exception is because FtpWebResponse/FileWebResponse don't have Http type headers.

So, the net result is that we don't have proper validation for WebHeaderCollection type.

The problem is that on .NET Core, the WebHeaderCollection is being created with the default contructor which doesn't pass it any specific WebHeaderCollectionType enum value. On .NET Framework, it uses an internal constructor overload. Also, the WebHeaderCollectionType enum is also marked as internal in .NET Framework and is not a public API.

This was ok for .NET Framework since everything was in System.dll. But on .NET Core, WebHeaderCollection lives in a different library from System.Net.Requests where *WebRequest, *WebResponse classes live.

    internal enum WebHeaderCollectionType : ushort {
        Unknown,
        WebRequest,
        WebResponse,
        HttpWebRequest,
        HttpWebResponse,
        HttpListenerRequest,
        HttpListenerResponse,
        FtpWebRequest,
        FtpWebResponse,
        FileWebRequest,
        FileWebResponse,
    }
    internal WebHeaderCollection(WebHeaderCollectionType type) : base(DBNull.Value);

This is resulting in all WebHeaderCollection objects being set with the WebHeaderCollectionType.Unknown enum value.

@davidsh
Copy link
Contributor Author

davidsh commented Apr 22, 2017

cc: @stephentoub @karelz @CIPop

@CIPop
Copy link
Member

CIPop commented Apr 24, 2017

From my experience with the TLS Alerts work, adding new public APIs required by the implementation complicates packaging and may create issues when packaging netstandard 2.0.
/cc @ericstj @weshaggard

@karelz
Copy link
Member

karelz commented Apr 27, 2017

Legacy APIs

Options:

  1. Merge contracts - all are legacy APIs (it is messy as they are separate contracts since 1.0) + implement on top of internal API
  2. Make the type & constructor public on Core only (not in .NET Standard) + implement on top of public it
  3. Live with sub-optimal validation

Triage recommendation: option [2]. Doesn't fit in, moving to Future.

@caesar-chen
Copy link
Contributor

This issue is blocking UWP work for S.N.HttpListener.
The same tests failed in dotnet/corefx#20425 (netcore scenario) also failed in UAP mode, for the same reason: WebHeaderCollectionType is set to Unknown by default, which skip the validation part: here

I will disable those tests for now.

@karelz
Copy link
Member

karelz commented Jul 6, 2017

@Caesar1995 Please add "disabled-test" label to the main issue which tracks the disabled test (is it this one?), thanks!

@DavidGoll
Copy link

Nice to have. Not needed for UWP. Won't break apps. Implementation is only needed to do extra error checking when adding to the collection.

@karelz
Copy link
Member

karelz commented Oct 2, 2019

Triage: Similar problem affects also non-UWP (we may have another tracking issue for that).

@davidsh
Copy link
Contributor Author

davidsh commented Oct 17, 2019

This issue was specific to the UAP implementation of the networking stack which had a different implementation for things like HTTP and WebSockets.

As of PR dotnet/corefx#41759, we no longer build the separate implementation for the UAP platform. So, this issue can't occur anymore with .NET 5 because we now will be using the same .NET Core implementation as on Windows, Linux, Mac.

@davidsh davidsh closed this as completed Oct 17, 2019
@msftgits msftgits transferred this issue from dotnet/corefx Jan 31, 2020
@msftgits msftgits added this to the 5.0 milestone Jan 31, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Net bug disabled-test The test is disabled in source code against the issue
Projects
None yet
Development

No branches or pull requests

6 participants