From 824b4d3fb17c6c7368072339949af304e4b14506 Mon Sep 17 00:00:00 2001 From: Anudeep Gunukula Date: Sat, 4 Sep 2021 08:51:33 +0000 Subject: [PATCH 01/14] removed argument requestId --- .../Common/tests/System/Net/Http/LoopbackServer.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libraries/Common/tests/System/Net/Http/LoopbackServer.cs b/src/libraries/Common/tests/System/Net/Http/LoopbackServer.cs index 7594b4908010f..673f2623075d7 100644 --- a/src/libraries/Common/tests/System/Net/Http/LoopbackServer.cs +++ b/src/libraries/Common/tests/System/Net/Http/LoopbackServer.cs @@ -949,13 +949,13 @@ private string GetResponseHeaderString(HttpStatusCode statusCode, IList headers = null, int requestId = 0) + public override async Task SendResponseHeadersAsync(HttpStatusCode statusCode = HttpStatusCode.OK, IList headers = null) { string headerString = GetResponseHeaderString(statusCode, headers); await SendResponseAsync(headerString).ConfigureAwait(false); } - public override async Task SendPartialResponseHeadersAsync(HttpStatusCode statusCode = HttpStatusCode.OK, IList headers = null, int requestId = 0) + public override async Task SendPartialResponseHeadersAsync(HttpStatusCode statusCode = HttpStatusCode.OK, IList headers = null) { string headerString = GetResponseHeaderString(statusCode, headers); @@ -965,7 +965,7 @@ public override async Task SendPartialResponseHeadersAsync(HttpStatusCode status await SendResponseAsync(headerString).ConfigureAwait(false); } - public override async Task SendResponseBodyAsync(byte[] content, bool isFinal = true, int requestId = 0) + public override async Task SendResponseBodyAsync(byte[] content, bool isFinal = true) { await SendResponseAsync(content).ConfigureAwait(false); } @@ -1041,7 +1041,7 @@ public override async Task HandleRequestAsync(HttpStatusCode st return requestData; } - public override async Task WaitForCancellationAsync(bool ignoreIncomingData = true, int requestId = 0) + public override async Task WaitForCancellationAsync(bool ignoreIncomingData = true) { var buffer = new byte[1024]; while (true) From 2b435f3cc3f2a9ca0fb101b270c07081ffd89c1b Mon Sep 17 00:00:00 2001 From: AnudeepGunukula Date: Tue, 7 Sep 2021 11:21:50 +0530 Subject: [PATCH 02/14] removed requestId in LoopbackServer.cs --- .../tests/System/Net/Http/GenericLoopbackServer.cs | 10 +++++----- .../Common/tests/System/Net/Http/LoopbackServer.cs | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/libraries/Common/tests/System/Net/Http/GenericLoopbackServer.cs b/src/libraries/Common/tests/System/Net/Http/GenericLoopbackServer.cs index ecff49e72016a..e171393c8dc33 100644 --- a/src/libraries/Common/tests/System/Net/Http/GenericLoopbackServer.cs +++ b/src/libraries/Common/tests/System/Net/Http/GenericLoopbackServer.cs @@ -122,19 +122,19 @@ public abstract class GenericLoopbackConnection : IDisposable /// Sends Response back with provided statusCode, headers and content. /// If isFinal is false, the body is not completed and you can call SendResponseBodyAsync to send more. - public abstract Task SendResponseAsync(HttpStatusCode statusCode = HttpStatusCode.OK, IList headers = null, string content = "", bool isFinal = true, int requestId = 0); + public abstract Task SendResponseAsync(HttpStatusCode statusCode = HttpStatusCode.OK, IList headers = null, string content = "", bool isFinal = true); /// Sends response headers. - public abstract Task SendResponseHeadersAsync(HttpStatusCode statusCode = HttpStatusCode.OK, IList headers = null, int requestId = 0); + public abstract Task SendResponseHeadersAsync(HttpStatusCode statusCode = HttpStatusCode.OK, IList headers = null); /// Sends valid but incomplete headers. Once called, there is no way to continue the response past this point. - public abstract Task SendPartialResponseHeadersAsync(HttpStatusCode statusCode = HttpStatusCode.OK, IList headers = null, int requestId = 0); + public abstract Task SendPartialResponseHeadersAsync(HttpStatusCode statusCode = HttpStatusCode.OK, IList headers = null); /// Sends Response body after SendResponse was called with isFinal: false. - public abstract Task SendResponseBodyAsync(byte[] content, bool isFinal = true, int requestId = 0); + public abstract Task SendResponseBodyAsync(byte[] content, bool isFinal = true); /// Reads Request, sends Response and closes connection. public abstract Task HandleRequestAsync(HttpStatusCode statusCode = HttpStatusCode.OK, IList headers = null, string content = ""); /// Waits for the client to signal cancellation. - public abstract Task WaitForCancellationAsync(bool ignoreIncomingData = true, int requestId = 0); + public abstract Task WaitForCancellationAsync(bool ignoreIncomingData = true); /// Helper function to make it easier to convert old test with strings. public async Task SendResponseBodyAsync(string content, bool isFinal = true, int requestId = 0) diff --git a/src/libraries/Common/tests/System/Net/Http/LoopbackServer.cs b/src/libraries/Common/tests/System/Net/Http/LoopbackServer.cs index 673f2623075d7..497e64658ebf6 100644 --- a/src/libraries/Common/tests/System/Net/Http/LoopbackServer.cs +++ b/src/libraries/Common/tests/System/Net/Http/LoopbackServer.cs @@ -866,7 +866,7 @@ public override async Task ReadRequestBodyAsync() return buffer; } - public override async Task SendResponseAsync(HttpStatusCode statusCode = HttpStatusCode.OK, IList headers = null, string content = "", bool isFinal = true, int requestId = 0) + public override async Task SendResponseAsync(HttpStatusCode statusCode = HttpStatusCode.OK, IList headers = null, string content = "", bool isFinal = true) { MemoryStream headerBytes = new MemoryStream(); int contentLength = -1; @@ -927,7 +927,7 @@ public override async Task SendResponseAsync(HttpStatusCode statusCode = HttpSta if (content != null) { - await SendResponseBodyAsync(content, isFinal: isFinal, requestId: requestId).ConfigureAwait(false); + await SendResponseBodyAsync(content, isFinal: isFinal).ConfigureAwait(false); } } From ff6c249c0c0a583a9669ab97e26f57b4f561936a Mon Sep 17 00:00:00 2001 From: Anudeep Gunukula <55506841+AnudeepGunukula@users.noreply.github.com> Date: Tue, 7 Sep 2021 20:20:39 +0530 Subject: [PATCH 03/14] Update src/libraries/Common/tests/System/Net/Http/GenericLoopbackServer.cs Co-authored-by: Karel Zikmund --- .../Common/tests/System/Net/Http/GenericLoopbackServer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libraries/Common/tests/System/Net/Http/GenericLoopbackServer.cs b/src/libraries/Common/tests/System/Net/Http/GenericLoopbackServer.cs index e171393c8dc33..556fcfc18938a 100644 --- a/src/libraries/Common/tests/System/Net/Http/GenericLoopbackServer.cs +++ b/src/libraries/Common/tests/System/Net/Http/GenericLoopbackServer.cs @@ -137,7 +137,7 @@ public abstract class GenericLoopbackConnection : IDisposable public abstract Task WaitForCancellationAsync(bool ignoreIncomingData = true); /// Helper function to make it easier to convert old test with strings. - public async Task SendResponseBodyAsync(string content, bool isFinal = true, int requestId = 0) + public async Task SendResponseBodyAsync(string content, bool isFinal = true) { await SendResponseBodyAsync(String.IsNullOrEmpty(content) ? new byte[0] : Encoding.ASCII.GetBytes(content), isFinal, requestId); } From c75dfdbc1ac90a3441b7fce00ec7c8e56b8a612f Mon Sep 17 00:00:00 2001 From: Anudeep Gunukula Date: Wed, 15 Sep 2021 09:59:33 +0000 Subject: [PATCH 04/14] commit after changes --- .../Common/tests/System/Net/Http/LoopbackServer.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/libraries/Common/tests/System/Net/Http/LoopbackServer.cs b/src/libraries/Common/tests/System/Net/Http/LoopbackServer.cs index 497e64658ebf6..7594b4908010f 100644 --- a/src/libraries/Common/tests/System/Net/Http/LoopbackServer.cs +++ b/src/libraries/Common/tests/System/Net/Http/LoopbackServer.cs @@ -866,7 +866,7 @@ public override async Task ReadRequestBodyAsync() return buffer; } - public override async Task SendResponseAsync(HttpStatusCode statusCode = HttpStatusCode.OK, IList headers = null, string content = "", bool isFinal = true) + public override async Task SendResponseAsync(HttpStatusCode statusCode = HttpStatusCode.OK, IList headers = null, string content = "", bool isFinal = true, int requestId = 0) { MemoryStream headerBytes = new MemoryStream(); int contentLength = -1; @@ -927,7 +927,7 @@ public override async Task SendResponseAsync(HttpStatusCode statusCode = HttpSta if (content != null) { - await SendResponseBodyAsync(content, isFinal: isFinal).ConfigureAwait(false); + await SendResponseBodyAsync(content, isFinal: isFinal, requestId: requestId).ConfigureAwait(false); } } @@ -949,13 +949,13 @@ private string GetResponseHeaderString(HttpStatusCode statusCode, IList headers = null) + public override async Task SendResponseHeadersAsync(HttpStatusCode statusCode = HttpStatusCode.OK, IList headers = null, int requestId = 0) { string headerString = GetResponseHeaderString(statusCode, headers); await SendResponseAsync(headerString).ConfigureAwait(false); } - public override async Task SendPartialResponseHeadersAsync(HttpStatusCode statusCode = HttpStatusCode.OK, IList headers = null) + public override async Task SendPartialResponseHeadersAsync(HttpStatusCode statusCode = HttpStatusCode.OK, IList headers = null, int requestId = 0) { string headerString = GetResponseHeaderString(statusCode, headers); @@ -965,7 +965,7 @@ public override async Task SendPartialResponseHeadersAsync(HttpStatusCode status await SendResponseAsync(headerString).ConfigureAwait(false); } - public override async Task SendResponseBodyAsync(byte[] content, bool isFinal = true) + public override async Task SendResponseBodyAsync(byte[] content, bool isFinal = true, int requestId = 0) { await SendResponseAsync(content).ConfigureAwait(false); } @@ -1041,7 +1041,7 @@ public override async Task HandleRequestAsync(HttpStatusCode st return requestData; } - public override async Task WaitForCancellationAsync(bool ignoreIncomingData = true) + public override async Task WaitForCancellationAsync(bool ignoreIncomingData = true, int requestId = 0) { var buffer = new byte[1024]; while (true) From 80937481a62d907ec74047851ba4c2fc4cb98d81 Mon Sep 17 00:00:00 2001 From: Anudeep Gunukula Date: Sat, 18 Sep 2021 12:13:51 +0530 Subject: [PATCH 05/14] removed requestId from LoopbackServer --- .../Common/tests/System/Net/Http/LoopbackServer.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/libraries/Common/tests/System/Net/Http/LoopbackServer.cs b/src/libraries/Common/tests/System/Net/Http/LoopbackServer.cs index ff4b34630525b..30cb5d4a3f043 100644 --- a/src/libraries/Common/tests/System/Net/Http/LoopbackServer.cs +++ b/src/libraries/Common/tests/System/Net/Http/LoopbackServer.cs @@ -872,7 +872,7 @@ public void CompleteRequestProcessing() _bodyRead = false; } - public override async Task SendResponseAsync(HttpStatusCode statusCode = HttpStatusCode.OK, IList headers = null, string content = "", bool isFinal = true, int requestId = 0) + public override async Task SendResponseAsync(HttpStatusCode statusCode = HttpStatusCode.OK, IList headers = null, string content = "", bool isFinal = true) { MemoryStream headerBytes = new MemoryStream(); int contentLength = -1; @@ -933,7 +933,7 @@ public override async Task SendResponseAsync(HttpStatusCode statusCode = HttpSta if (content != null) { - await SendResponseBodyAsync(content, isFinal: isFinal, requestId: requestId).ConfigureAwait(false); + await SendResponseBodyAsync(content, isFinal: isFinal).ConfigureAwait(false); } } @@ -955,13 +955,13 @@ private string GetResponseHeaderString(HttpStatusCode statusCode, IList headers = null, int requestId = 0) + public override async Task SendResponseHeadersAsync(HttpStatusCode statusCode = HttpStatusCode.OK, IList headers = null) { string headerString = GetResponseHeaderString(statusCode, headers); await SendResponseAsync(headerString).ConfigureAwait(false); } - public override async Task SendPartialResponseHeadersAsync(HttpStatusCode statusCode = HttpStatusCode.OK, IList headers = null, int requestId = 0) + public override async Task SendPartialResponseHeadersAsync(HttpStatusCode statusCode = HttpStatusCode.OK, IList headers = null) { string headerString = GetResponseHeaderString(statusCode, headers); @@ -971,7 +971,7 @@ public override async Task SendPartialResponseHeadersAsync(HttpStatusCode status await SendResponseAsync(headerString).ConfigureAwait(false); } - public override async Task SendResponseBodyAsync(byte[] content, bool isFinal = true, int requestId = 0) + public override async Task SendResponseBodyAsync(byte[] content, bool isFinal = true) { await SendResponseAsync(content).ConfigureAwait(false); } @@ -1047,7 +1047,7 @@ public override async Task HandleRequestAsync(HttpStatusCode st return requestData; } - public override async Task WaitForCancellationAsync(bool ignoreIncomingData = true, int requestId = 0) + public override async Task WaitForCancellationAsync(bool ignoreIncomingData = true) { var buffer = new byte[1024]; while (true) From 92fd0fdf0d61a0573382a2d1477814e25920ef40 Mon Sep 17 00:00:00 2001 From: Anudeep Gunukula Date: Sat, 18 Sep 2021 20:48:44 +0530 Subject: [PATCH 06/14] removed requestId from Http2 and Http3 LoopbackConnection --- .../System/Net/Http/GenericLoopbackServer.cs | 2 +- .../Net/Http/Http2LoopbackConnection.cs | 22 +++++++++---------- .../Net/Http/Http3LoopbackConnection.cs | 20 ++++++++--------- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/libraries/Common/tests/System/Net/Http/GenericLoopbackServer.cs b/src/libraries/Common/tests/System/Net/Http/GenericLoopbackServer.cs index 556fcfc18938a..ad3f3fb350729 100644 --- a/src/libraries/Common/tests/System/Net/Http/GenericLoopbackServer.cs +++ b/src/libraries/Common/tests/System/Net/Http/GenericLoopbackServer.cs @@ -139,7 +139,7 @@ public abstract class GenericLoopbackConnection : IDisposable /// Helper function to make it easier to convert old test with strings. public async Task SendResponseBodyAsync(string content, bool isFinal = true) { - await SendResponseBodyAsync(String.IsNullOrEmpty(content) ? new byte[0] : Encoding.ASCII.GetBytes(content), isFinal, requestId); + await SendResponseBodyAsync(String.IsNullOrEmpty(content) ? new byte[0] : Encoding.ASCII.GetBytes(content), isFinal); } } diff --git a/src/libraries/Common/tests/System/Net/Http/Http2LoopbackConnection.cs b/src/libraries/Common/tests/System/Net/Http/Http2LoopbackConnection.cs index 18edaca7a6524..158cba871cb14 100644 --- a/src/libraries/Common/tests/System/Net/Http/Http2LoopbackConnection.cs +++ b/src/libraries/Common/tests/System/Net/Http/Http2LoopbackConnection.cs @@ -864,7 +864,7 @@ public override Task ReadRequestBodyAsync() return ReadBodyAsync(); } - public override async Task SendResponseAsync(HttpStatusCode statusCode = HttpStatusCode.OK, IList headers = null, string content = "", bool isFinal = true, int requestId = 0) + public override async Task SendResponseAsync(HttpStatusCode statusCode = HttpStatusCode.OK, IList headers = null, string content = "", bool isFinal = true) { if (headers != null) { @@ -901,7 +901,7 @@ public override async Task SendResponseAsync(HttpStatusCode statusCode = HttpSta } } - int streamId = requestId == 0 ? _lastStreamId : requestId; + int streamId = _lastStreamId; if (string.IsNullOrEmpty(content)) { @@ -910,25 +910,25 @@ public override async Task SendResponseAsync(HttpStatusCode statusCode = HttpSta else { await SendResponseHeadersAsync(streamId, endStream: false, (HttpStatusCode)statusCode, endHeaders: true, headers: headers); - await SendResponseBodyAsync(content, isFinal: isFinal, requestId: streamId); + await SendResponseBodyAsync(content, isFinal: isFinal); } } - public override Task SendResponseHeadersAsync(HttpStatusCode statusCode = HttpStatusCode.OK, IList headers = null, int requestId = 0) + public override Task SendResponseHeadersAsync(HttpStatusCode statusCode = HttpStatusCode.OK, IList headers = null) { - int streamId = requestId == 0 ? _lastStreamId : requestId; + int streamId = _lastStreamId; return SendResponseHeadersAsync(streamId, endStream: false, statusCode, isTrailingHeader: false, endHeaders: true, headers); } - public override Task SendPartialResponseHeadersAsync(HttpStatusCode statusCode = HttpStatusCode.OK, IList headers = null, int requestId = 0) + public override Task SendPartialResponseHeadersAsync(HttpStatusCode statusCode = HttpStatusCode.OK, IList headers = null) { - int streamId = requestId == 0 ? _lastStreamId : requestId; + int streamId = _lastStreamId; return SendResponseHeadersAsync(streamId, endStream: false, statusCode, isTrailingHeader: false, endHeaders: false, headers); } - public override Task SendResponseBodyAsync(byte[] content, bool isFinal = true, int requestId = 0) + public override Task SendResponseBodyAsync(byte[] content, bool isFinal = true) { - int streamId = requestId == 0 ? _lastStreamId : requestId; + int streamId = _lastStreamId; return SendResponseBodyAsync(streamId, content, isFinal); } @@ -955,9 +955,9 @@ public override async Task HandleRequestAsync(HttpStatusCode st return requestData; } - public override async Task WaitForCancellationAsync(bool ignoreIncomingData = true, int requestId = 0) + public override async Task WaitForCancellationAsync(bool ignoreIncomingData = true) { - int streamId = requestId == 0 ? _lastStreamId : requestId; + int streamId = _lastStreamId; Frame frame; do diff --git a/src/libraries/Common/tests/System/Net/Http/Http3LoopbackConnection.cs b/src/libraries/Common/tests/System/Net/Http/Http3LoopbackConnection.cs index cb65b22dd0270..ceb36e0bcbfb1 100644 --- a/src/libraries/Common/tests/System/Net/Http/Http3LoopbackConnection.cs +++ b/src/libraries/Common/tests/System/Net/Http/Http3LoopbackConnection.cs @@ -200,24 +200,24 @@ public override async Task ReadRequestDataAsync(bool readBody = return await stream.ReadRequestDataAsync(readBody).ConfigureAwait(false); } - public override Task SendResponseAsync(HttpStatusCode statusCode = HttpStatusCode.OK, IList headers = null, string content = "", bool isFinal = true, int requestId = 0) + public override Task SendResponseAsync(HttpStatusCode statusCode = HttpStatusCode.OK, IList headers = null, string content = "", bool isFinal = true) { - return GetOpenRequest(requestId).SendResponseAsync(statusCode, headers, content, isFinal); + return GetOpenRequest().SendResponseAsync(statusCode, headers, content, isFinal); } - public override Task SendResponseBodyAsync(byte[] content, bool isFinal = true, int requestId = 0) + public override Task SendResponseBodyAsync(byte[] content, bool isFinal = true) { - return GetOpenRequest(requestId).SendResponseBodyAsync(content, isFinal); + return GetOpenRequest().SendResponseBodyAsync(content, isFinal); } - public override Task SendResponseHeadersAsync(HttpStatusCode statusCode = HttpStatusCode.OK, IList headers = null, int requestId = 0) + public override Task SendResponseHeadersAsync(HttpStatusCode statusCode = HttpStatusCode.OK, IList headers = null) { - return GetOpenRequest(requestId).SendResponseHeadersAsync(statusCode, headers); + return GetOpenRequest().SendResponseHeadersAsync(statusCode, headers); } - public override Task SendPartialResponseHeadersAsync(HttpStatusCode statusCode = HttpStatusCode.OK, IList headers = null, int requestId = 0) + public override Task SendPartialResponseHeadersAsync(HttpStatusCode statusCode = HttpStatusCode.OK, IList headers = null) { - return GetOpenRequest(requestId).SendPartialResponseHeadersAsync(statusCode, headers); + return GetOpenRequest().SendPartialResponseHeadersAsync(statusCode, headers); } public override async Task HandleRequestAsync(HttpStatusCode statusCode = HttpStatusCode.OK, IList headers = null, string content = "") @@ -301,9 +301,9 @@ public async Task WaitForClientDisconnectAsync(bool refuseNewRequests = true) await CloseAsync(H3_NO_ERROR); } - public override async Task WaitForCancellationAsync(bool ignoreIncomingData = true, int requestId = 0) + public override async Task WaitForCancellationAsync(bool ignoreIncomingData = true) { - await GetOpenRequest(requestId).WaitForCancellationAsync(ignoreIncomingData).ConfigureAwait(false); + await GetOpenRequest().WaitForCancellationAsync(ignoreIncomingData).ConfigureAwait(false); } } From 5d3b57d931dce18a26bbbfc9cde4386771072e0f Mon Sep 17 00:00:00 2001 From: Anudeep Gunukula Date: Sun, 19 Sep 2021 18:44:54 +0530 Subject: [PATCH 07/14] removed requestId from HttpClientHandlerTest.Http2.cs --- .../tests/FunctionalTests/HttpClientHandlerTest.Http2.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.Http2.cs b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.Http2.cs index fc94b54bba975..d39abd5b41590 100644 --- a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.Http2.cs +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.Http2.cs @@ -3350,7 +3350,7 @@ await Http2LoopbackServer.CreateClientAndServerAsync(async uri => } } Assert.Equal(continuationCount, receivedContinuations); - await connection.SendResponseAsync(HttpStatusCode.OK, requestId: streamId); + await connection.SendResponseAsync(HttpStatusCode.OK); }); } From 636d0c887847118dd768697894105483ce7dcfd0 Mon Sep 17 00:00:00 2001 From: AnudeepGunukula Date: Sat, 30 Oct 2021 11:45:28 +0530 Subject: [PATCH 08/14] commit after modifying http2 test --- .../Net/Http/Http2LoopbackConnection.cs | 50 +++++++++++++++++++ .../HttpClientHandlerTest.Http2.cs | 2 +- 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/src/libraries/Common/tests/System/Net/Http/Http2LoopbackConnection.cs b/src/libraries/Common/tests/System/Net/Http/Http2LoopbackConnection.cs index 158cba871cb14..1f65e01f74472 100644 --- a/src/libraries/Common/tests/System/Net/Http/Http2LoopbackConnection.cs +++ b/src/libraries/Common/tests/System/Net/Http/Http2LoopbackConnection.cs @@ -864,6 +864,56 @@ public override Task ReadRequestBodyAsync() return ReadBodyAsync(); } + public override async Task SendResponseAsync(HttpStatusCode statusCode = HttpStatusCode.OK, IList headers = null, string content = "", bool isFinal = true, int requestId = 0) + { + if (headers != null) + { + bool hasDate = false; + bool stripContentLength = false; + foreach (HttpHeaderData headerData in headers) + { + // Check if we should inject Date header to match HTTP/1. + if (headerData.Name.Equals("Date", StringComparison.OrdinalIgnoreCase)) + { + hasDate = true; + } + else if (headerData.Name.Equals("Content-Length") && headerData.Value == null) + { + // Hack used for Http/1 to avoid sending content-length header. + stripContentLength = true; + } + } + + if (!hasDate || stripContentLength) + { + var newHeaders = new List(); + foreach (HttpHeaderData headerData in headers) + { + if (headerData.Name.Equals("Content-Length") && headerData.Value == null) + { + continue; + } + + newHeaders.Add(headerData); + } + newHeaders.Add(new HttpHeaderData("Date", $"{DateTimeOffset.UtcNow:R}")); + headers = newHeaders; + } + } + + int streamId = _lastStreamId; + + if (string.IsNullOrEmpty(content)) + { + await SendResponseHeadersAsync(streamId, endStream: isFinal, (HttpStatusCode)statusCode, endHeaders: true, headers: headers); + } + else + { + await SendResponseHeadersAsync(streamId, endStream: false, (HttpStatusCode)statusCode, endHeaders: true, headers: headers); + await SendResponseBodyAsync(content, isFinal: isFinal); + } + } + public override async Task SendResponseAsync(HttpStatusCode statusCode = HttpStatusCode.OK, IList headers = null, string content = "", bool isFinal = true) { if (headers != null) diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.Http2.cs b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.Http2.cs index d39abd5b41590..fc94b54bba975 100644 --- a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.Http2.cs +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.Http2.cs @@ -3350,7 +3350,7 @@ await Http2LoopbackServer.CreateClientAndServerAsync(async uri => } } Assert.Equal(continuationCount, receivedContinuations); - await connection.SendResponseAsync(HttpStatusCode.OK); + await connection.SendResponseAsync(HttpStatusCode.OK, requestId: streamId); }); } From 9e1f7cbfd2a4423cbb84f67508cb45bdb80955a3 Mon Sep 17 00:00:00 2001 From: Anudeep Gunukula Date: Wed, 3 Nov 2021 12:06:24 +0000 Subject: [PATCH 09/14] created new function in http2 --- .../Common/tests/System/Net/Http/Http2LoopbackConnection.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libraries/Common/tests/System/Net/Http/Http2LoopbackConnection.cs b/src/libraries/Common/tests/System/Net/Http/Http2LoopbackConnection.cs index 1f65e01f74472..e9df2915518c6 100644 --- a/src/libraries/Common/tests/System/Net/Http/Http2LoopbackConnection.cs +++ b/src/libraries/Common/tests/System/Net/Http/Http2LoopbackConnection.cs @@ -864,7 +864,7 @@ public override Task ReadRequestBodyAsync() return ReadBodyAsync(); } - public override async Task SendResponseAsync(HttpStatusCode statusCode = HttpStatusCode.OK, IList headers = null, string content = "", bool isFinal = true, int requestId = 0) + public async Task SendResponseAsync(HttpStatusCode statusCode = HttpStatusCode.OK, IList headers = null, string content = "", bool isFinal = true, int requestId = 0) { if (headers != null) { From 6a82b7113ce08f2d5ca38e8912d1ea56f5aa7cfc Mon Sep 17 00:00:00 2001 From: Anudeep Gunukula <55506841+AnudeepGunukula@users.noreply.github.com> Date: Tue, 23 Nov 2021 10:53:51 +0530 Subject: [PATCH 10/14] Update src/libraries/Common/tests/System/Net/Http/Http2LoopbackConnection.cs Co-authored-by: Katya Sokolova --- .../Common/tests/System/Net/Http/Http2LoopbackConnection.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libraries/Common/tests/System/Net/Http/Http2LoopbackConnection.cs b/src/libraries/Common/tests/System/Net/Http/Http2LoopbackConnection.cs index e9df2915518c6..56c332f7df5d5 100644 --- a/src/libraries/Common/tests/System/Net/Http/Http2LoopbackConnection.cs +++ b/src/libraries/Common/tests/System/Net/Http/Http2LoopbackConnection.cs @@ -901,7 +901,7 @@ public async Task SendResponseAsync(HttpStatusCode statusCode = HttpStatusCode.O } } - int streamId = _lastStreamId; + int streamId = requestId == 0 ? _lastStreamId : requestId; if (string.IsNullOrEmpty(content)) { From fd2c8872ade45ecdc3400edd13c6c8a8e1e879e8 Mon Sep 17 00:00:00 2001 From: Anudeep Gunukula <55506841+AnudeepGunukula@users.noreply.github.com> Date: Tue, 23 Nov 2021 16:23:19 +0530 Subject: [PATCH 11/14] Update src/libraries/Common/tests/System/Net/Http/Http2LoopbackConnection.cs Co-authored-by: Karel Zikmund --- .../Net/Http/Http2LoopbackConnection.cs | 47 +------------------ 1 file changed, 1 insertion(+), 46 deletions(-) diff --git a/src/libraries/Common/tests/System/Net/Http/Http2LoopbackConnection.cs b/src/libraries/Common/tests/System/Net/Http/Http2LoopbackConnection.cs index 56c332f7df5d5..603dd4d3f6526 100644 --- a/src/libraries/Common/tests/System/Net/Http/Http2LoopbackConnection.cs +++ b/src/libraries/Common/tests/System/Net/Http/Http2LoopbackConnection.cs @@ -916,52 +916,7 @@ public async Task SendResponseAsync(HttpStatusCode statusCode = HttpStatusCode.O public override async Task SendResponseAsync(HttpStatusCode statusCode = HttpStatusCode.OK, IList headers = null, string content = "", bool isFinal = true) { - if (headers != null) - { - bool hasDate = false; - bool stripContentLength = false; - foreach (HttpHeaderData headerData in headers) - { - // Check if we should inject Date header to match HTTP/1. - if (headerData.Name.Equals("Date", StringComparison.OrdinalIgnoreCase)) - { - hasDate = true; - } - else if (headerData.Name.Equals("Content-Length") && headerData.Value == null) - { - // Hack used for Http/1 to avoid sending content-length header. - stripContentLength = true; - } - } - - if (!hasDate || stripContentLength) - { - var newHeaders = new List(); - foreach (HttpHeaderData headerData in headers) - { - if (headerData.Name.Equals("Content-Length") && headerData.Value == null) - { - continue; - } - - newHeaders.Add(headerData); - } - newHeaders.Add(new HttpHeaderData("Date", $"{DateTimeOffset.UtcNow:R}")); - headers = newHeaders; - } - } - - int streamId = _lastStreamId; - - if (string.IsNullOrEmpty(content)) - { - await SendResponseHeadersAsync(streamId, endStream: isFinal, (HttpStatusCode)statusCode, endHeaders: true, headers: headers); - } - else - { - await SendResponseHeadersAsync(streamId, endStream: false, (HttpStatusCode)statusCode, endHeaders: true, headers: headers); - await SendResponseBodyAsync(content, isFinal: isFinal); - } + return SendResponseAsync(statusCode, headers, content, isFinal, requestId: 0); } public override Task SendResponseHeadersAsync(HttpStatusCode statusCode = HttpStatusCode.OK, IList headers = null) From fefa416942c18625af4a9f4ed20eb0470aa14a5f Mon Sep 17 00:00:00 2001 From: Anudeep Gunukula <55506841+AnudeepGunukula@users.noreply.github.com> Date: Tue, 23 Nov 2021 16:23:46 +0530 Subject: [PATCH 12/14] Update src/libraries/Common/tests/System/Net/Http/Http2LoopbackConnection.cs Co-authored-by: Karel Zikmund --- .../Common/tests/System/Net/Http/Http2LoopbackConnection.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libraries/Common/tests/System/Net/Http/Http2LoopbackConnection.cs b/src/libraries/Common/tests/System/Net/Http/Http2LoopbackConnection.cs index 603dd4d3f6526..9a2a17caef67c 100644 --- a/src/libraries/Common/tests/System/Net/Http/Http2LoopbackConnection.cs +++ b/src/libraries/Common/tests/System/Net/Http/Http2LoopbackConnection.cs @@ -921,7 +921,7 @@ public override async Task SendResponseAsync(HttpStatusCode statusCode = HttpSta public override Task SendResponseHeadersAsync(HttpStatusCode statusCode = HttpStatusCode.OK, IList headers = null) { - int streamId = _lastStreamId; + int streamId = _lastStreamId; return SendResponseHeadersAsync(streamId, endStream: false, statusCode, isTrailingHeader: false, endHeaders: true, headers); } From d06ddf048bf284b0757893b7ee8a11ff92adeef2 Mon Sep 17 00:00:00 2001 From: Anudeep Gunukula <55506841+AnudeepGunukula@users.noreply.github.com> Date: Tue, 23 Nov 2021 16:23:58 +0530 Subject: [PATCH 13/14] Update src/libraries/Common/tests/System/Net/Http/Http2LoopbackConnection.cs Co-authored-by: Karel Zikmund --- .../Common/tests/System/Net/Http/Http2LoopbackConnection.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libraries/Common/tests/System/Net/Http/Http2LoopbackConnection.cs b/src/libraries/Common/tests/System/Net/Http/Http2LoopbackConnection.cs index 9a2a17caef67c..e8834d7c5c784 100644 --- a/src/libraries/Common/tests/System/Net/Http/Http2LoopbackConnection.cs +++ b/src/libraries/Common/tests/System/Net/Http/Http2LoopbackConnection.cs @@ -927,7 +927,7 @@ public override Task SendResponseHeadersAsync(HttpStatusCode statusCode = HttpSt public override Task SendPartialResponseHeadersAsync(HttpStatusCode statusCode = HttpStatusCode.OK, IList headers = null) { - int streamId = _lastStreamId; + int streamId = _lastStreamId; return SendResponseHeadersAsync(streamId, endStream: false, statusCode, isTrailingHeader: false, endHeaders: false, headers); } From 62bc2bbbb541cb198fc587e858167ee0891492e5 Mon Sep 17 00:00:00 2001 From: Anudeep Gunukula Date: Tue, 23 Nov 2021 14:15:14 +0000 Subject: [PATCH 14/14] removed async keyword --- .../Common/tests/System/Net/Http/Http2LoopbackConnection.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libraries/Common/tests/System/Net/Http/Http2LoopbackConnection.cs b/src/libraries/Common/tests/System/Net/Http/Http2LoopbackConnection.cs index e8834d7c5c784..b09232bb009e8 100644 --- a/src/libraries/Common/tests/System/Net/Http/Http2LoopbackConnection.cs +++ b/src/libraries/Common/tests/System/Net/Http/Http2LoopbackConnection.cs @@ -914,7 +914,7 @@ public async Task SendResponseAsync(HttpStatusCode statusCode = HttpStatusCode.O } } - public override async Task SendResponseAsync(HttpStatusCode statusCode = HttpStatusCode.OK, IList headers = null, string content = "", bool isFinal = true) + public override Task SendResponseAsync(HttpStatusCode statusCode = HttpStatusCode.OK, IList headers = null, string content = "", bool isFinal = true) { return SendResponseAsync(statusCode, headers, content, isFinal, requestId: 0); }