Fixed :scheme header for H/2 with PlaintextStreamFilter (#71057)
authorMarie Píchová <11718369+ManickaP@users.noreply.github.com>
Tue, 21 Jun 2022 19:58:49 +0000 (21:58 +0200)
committerGitHub <noreply@github.com>
Tue, 21 Jun 2022 19:58:49 +0000 (21:58 +0200)
src/libraries/Common/tests/System/Net/Http/Http2LoopbackConnection.cs
src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http2Connection.cs
src/libraries/System.Net.Http/tests/FunctionalTests/SocketsHttpHandlerTest.cs

index fbba51f..75415dc 100644 (file)
@@ -103,7 +103,7 @@ namespace System.Net.Test.Common
                 await _connectionStream.WriteAsync("HTTP/2.0 400 Bad Request\r\n\r\n"u8.ToArray());
                 _connectionSocket.Shutdown(SocketShutdown.Send);
                 // If WinHTTP doesn't support streaming a request without a length then it will fallback
-                // to HTTP/1.1. Throwing an exception to detect this case in WinHttpHandler tests. 
+                // to HTTP/1.1. Throwing an exception to detect this case in WinHttpHandler tests.
                 throw new Exception("HTTP/1.1 request sent to HTTP/2 connection.");
             }
         }
index 9dc7066..40c27f5 100644 (file)
@@ -1424,7 +1424,7 @@ namespace System.Net.Http
                 WriteIndexedHeader(H2StaticTable.MethodGet, normalizedMethod.Method, ref headerBuffer);
             }
 
-            WriteIndexedHeader(_stream is SslStream ? H2StaticTable.SchemeHttps : H2StaticTable.SchemeHttp, ref headerBuffer);
+            WriteIndexedHeader(_pool.IsSecure ? H2StaticTable.SchemeHttps : H2StaticTable.SchemeHttp, ref headerBuffer);
 
             if (request.HasHeaders && request.Headers.Host != null)
             {
index 6248cf3..6797e8e 100644 (file)
@@ -3193,7 +3193,12 @@ namespace System.Net.Http.Functional.Tests
                 },
                 async server =>
                 {
-                    await server.AcceptConnectionSendResponseAndCloseAsync(content: "foo");
+                    HttpRequestData request = await server.AcceptConnectionSendResponseAndCloseAsync(content: "foo");
+                    if (request.Version == HttpVersion20.Value)
+                    {
+                        HttpHeaderData schemeHeader = Assert.Single(request.Headers, headerData => headerData.Name == ":scheme");
+                        Assert.Equal(useSsl ? "https" : "http", schemeHeader.Value);
+                    }
                 }, options: options);
         }