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

add StreamConformanceTest for HTTP CONNECT stream #50699

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ protected override async Task<StreamPair> CreateConnectedStreamsAsync()
}
}

public sealed class Http1RawResponseStreamConformanceTests : ResponseConnectedStreamConformanceTests
public sealed class Http1UpgradeResponseStreamConformanceTests : ResponseConnectedStreamConformanceTests
{
protected override string GetResponseHeaders() => "HTTP/1.1 101 Switching Protocols\r\n\r\n";

Expand All @@ -35,6 +35,26 @@ protected override async Task<StreamPair> CreateConnectedStreamsAsync()
}
}

public sealed class Http1ConnectResponseStreamConformanceTests : ResponseConnectedStreamConformanceTests
{
protected override string GetResponseHeaders() => "HTTP/1.1 200 OK\r\n\r\n";

protected override HttpRequestMessage GetHttpRequestMessage()
{
var request = new HttpRequestMessage(new HttpMethod("CONNECT"), $"http://doesntmatter:12345/");
request.Headers.Host = "doesntmatter:12345";
return request;
}

protected override async Task<StreamPair> CreateConnectedStreamsAsync()
{
StreamPair pair = await base.CreateConnectedStreamsAsync();
Assert.True(pair.Stream2.CanWrite);
Assert.True(pair.Stream2.CanRead);
return pair;
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this testing a different stream than Http1UpgradeResponseStreamConformanceTests is testing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's the same stream, but a different way of constructing it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From a "we know the implementation" perspective, this doesn't seem like it's actually testing anything further:

                else if (ReferenceEquals(normalizedMethod, HttpMethod.Connect) && response.StatusCode == HttpStatusCode.OK)
                {
                    responseStream = new RawConnectionStream(this);
                    _connectionClose = true; 
                }
                else if (response.StatusCode == HttpStatusCode.SwitchingProtocols)
                {
                    responseStream = new RawConnectionStream(this);
                }

but if you really think it's worth adding additional stream tests for, ok.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think you're right here. I'll just close this.


public sealed class Http1ContentLengthResponseStreamConformanceTests : ResponseStandaloneStreamConformanceTests
{
protected override async Task WriteResponseAsync(Stream responseStream, byte[] bodyData)
Expand Down Expand Up @@ -83,12 +103,15 @@ public abstract class ResponseConnectedStreamConformanceTests : ConnectedStreamC

protected abstract string GetResponseHeaders();

protected virtual HttpRequestMessage GetHttpRequestMessage() =>
new HttpRequestMessage(HttpMethod.Get, $"http://doesntmatter:12345/");

protected override async Task<StreamPair> CreateConnectedStreamsAsync()
{
(Stream httpConnection, Stream server) = ConnectedStreams.CreateBidirectional(4096, int.MaxValue);

using var hc = new HttpClient(new SocketsHttpHandler() { ConnectCallback = delegate { return ValueTask.FromResult(httpConnection); } });
Task<HttpResponseMessage> clientTask = hc.SendAsync(new HttpRequestMessage(HttpMethod.Get, $"http://doesntmatter:12345/"), HttpCompletionOption.ResponseHeadersRead);
Task<HttpResponseMessage> clientTask = hc.SendAsync(GetHttpRequestMessage(), HttpCompletionOption.ResponseHeadersRead);

await ReadHeadersAsync(server);

Expand Down