Skip to content

Commit

Permalink
removed argument requestId from loopbackserver.cs (#58678)
Browse files Browse the repository at this point in the history
* removed argument requestId

* removed requestId in LoopbackServer.cs

* Update src/libraries/Common/tests/System/Net/Http/GenericLoopbackServer.cs

Co-authored-by: Karel Zikmund <karelz@microsoft.com>

* commit after changes

* removed requestId from LoopbackServer

* removed requestId from Http2 and Http3 LoopbackConnection

* removed requestId from HttpClientHandlerTest.Http2.cs

* commit after modifying http2 test

* created new function in http2

* Update src/libraries/Common/tests/System/Net/Http/Http2LoopbackConnection.cs

Co-authored-by: Katya Sokolova <esokolov@microsoft.com>

* Update src/libraries/Common/tests/System/Net/Http/Http2LoopbackConnection.cs

Co-authored-by: Karel Zikmund <karelz@microsoft.com>

* Update src/libraries/Common/tests/System/Net/Http/Http2LoopbackConnection.cs

Co-authored-by: Karel Zikmund <karelz@microsoft.com>

* Update src/libraries/Common/tests/System/Net/Http/Http2LoopbackConnection.cs

Co-authored-by: Karel Zikmund <karelz@microsoft.com>

* removed async keyword

Co-authored-by: Karel Zikmund <karelz@microsoft.com>
Co-authored-by: Katya Sokolova <esokolov@microsoft.com>
  • Loading branch information
3 people authored Nov 23, 2021
1 parent b35c0ad commit 8b67772
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,24 +124,24 @@ public abstract class GenericLoopbackConnection : IDisposable

/// <summary>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.</summary>
public abstract Task SendResponseAsync(HttpStatusCode statusCode = HttpStatusCode.OK, IList<HttpHeaderData> headers = null, string content = "", bool isFinal = true, int requestId = 0);
public abstract Task SendResponseAsync(HttpStatusCode statusCode = HttpStatusCode.OK, IList<HttpHeaderData> headers = null, string content = "", bool isFinal = true);
/// <summary>Sends response headers.</summary>
public abstract Task SendResponseHeadersAsync(HttpStatusCode statusCode = HttpStatusCode.OK, IList<HttpHeaderData> headers = null, int requestId = 0);
public abstract Task SendResponseHeadersAsync(HttpStatusCode statusCode = HttpStatusCode.OK, IList<HttpHeaderData> headers = null);
/// <summary>Sends valid but incomplete headers. Once called, there is no way to continue the response past this point.</summary>
public abstract Task SendPartialResponseHeadersAsync(HttpStatusCode statusCode = HttpStatusCode.OK, IList<HttpHeaderData> headers = null, int requestId = 0);
public abstract Task SendPartialResponseHeadersAsync(HttpStatusCode statusCode = HttpStatusCode.OK, IList<HttpHeaderData> headers = null);
/// <summary>Sends Response body after SendResponse was called with isFinal: false.</summary>
public abstract Task SendResponseBodyAsync(byte[] content, bool isFinal = true, int requestId = 0);
public abstract Task SendResponseBodyAsync(byte[] content, bool isFinal = true);

/// <summary>Reads Request, sends Response and closes connection.</summary>
public abstract Task<HttpRequestData> HandleRequestAsync(HttpStatusCode statusCode = HttpStatusCode.OK, IList<HttpHeaderData> headers = null, string content = "");

/// <summary>Waits for the client to signal cancellation.</summary>
public abstract Task WaitForCancellationAsync(bool ignoreIncomingData = true, int requestId = 0);
public abstract Task WaitForCancellationAsync(bool ignoreIncomingData = true);

/// <summary>Helper function to make it easier to convert old test with strings.</summary>
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);
await SendResponseBodyAsync(String.IsNullOrEmpty(content) ? new byte[0] : Encoding.ASCII.GetBytes(content), isFinal);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -864,7 +864,7 @@ public override Task<Byte[]> ReadRequestBodyAsync()
return ReadBodyAsync();
}

public override async Task SendResponseAsync(HttpStatusCode statusCode = HttpStatusCode.OK, IList<HttpHeaderData> headers = null, string content = "", bool isFinal = true, int requestId = 0)
public async Task SendResponseAsync(HttpStatusCode statusCode = HttpStatusCode.OK, IList<HttpHeaderData> headers = null, string content = "", bool isFinal = true, int requestId = 0)
{
if (headers != null)
{
Expand Down Expand Up @@ -910,25 +910,30 @@ 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<HttpHeaderData> headers = null, int requestId = 0)
public override Task SendResponseAsync(HttpStatusCode statusCode = HttpStatusCode.OK, IList<HttpHeaderData> headers = null, string content = "", bool isFinal = true)
{
int streamId = requestId == 0 ? _lastStreamId : requestId;
return SendResponseAsync(statusCode, headers, content, isFinal, requestId: 0);
}

public override Task SendResponseHeadersAsync(HttpStatusCode statusCode = HttpStatusCode.OK, IList<HttpHeaderData> headers = null)
{
int streamId = _lastStreamId;
return SendResponseHeadersAsync(streamId, endStream: false, statusCode, isTrailingHeader: false, endHeaders: true, headers);
}

public override Task SendPartialResponseHeadersAsync(HttpStatusCode statusCode = HttpStatusCode.OK, IList<HttpHeaderData> headers = null, int requestId = 0)
public override Task SendPartialResponseHeadersAsync(HttpStatusCode statusCode = HttpStatusCode.OK, IList<HttpHeaderData> 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);
}

Expand All @@ -955,9 +960,9 @@ public override async Task<HttpRequestData> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,24 +200,24 @@ public override async Task<HttpRequestData> ReadRequestDataAsync(bool readBody =
return await stream.ReadRequestDataAsync(readBody).ConfigureAwait(false);
}

public override Task SendResponseAsync(HttpStatusCode statusCode = HttpStatusCode.OK, IList<HttpHeaderData> headers = null, string content = "", bool isFinal = true, int requestId = 0)
public override Task SendResponseAsync(HttpStatusCode statusCode = HttpStatusCode.OK, IList<HttpHeaderData> 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<HttpHeaderData> headers = null, int requestId = 0)
public override Task SendResponseHeadersAsync(HttpStatusCode statusCode = HttpStatusCode.OK, IList<HttpHeaderData> headers = null)
{
return GetOpenRequest(requestId).SendResponseHeadersAsync(statusCode, headers);
return GetOpenRequest().SendResponseHeadersAsync(statusCode, headers);
}

public override Task SendPartialResponseHeadersAsync(HttpStatusCode statusCode = HttpStatusCode.OK, IList<HttpHeaderData> headers = null, int requestId = 0)
public override Task SendPartialResponseHeadersAsync(HttpStatusCode statusCode = HttpStatusCode.OK, IList<HttpHeaderData> headers = null)
{
return GetOpenRequest(requestId).SendPartialResponseHeadersAsync(statusCode, headers);
return GetOpenRequest().SendPartialResponseHeadersAsync(statusCode, headers);
}

public override async Task<HttpRequestData> HandleRequestAsync(HttpStatusCode statusCode = HttpStatusCode.OK, IList<HttpHeaderData> headers = null, string content = "")
Expand Down Expand Up @@ -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);
}
}

Expand Down
12 changes: 6 additions & 6 deletions src/libraries/Common/tests/System/Net/Http/LoopbackServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -872,7 +872,7 @@ public void CompleteRequestProcessing()
_bodyRead = false;
}

public override async Task SendResponseAsync(HttpStatusCode statusCode = HttpStatusCode.OK, IList<HttpHeaderData> headers = null, string content = "", bool isFinal = true, int requestId = 0)
public override async Task SendResponseAsync(HttpStatusCode statusCode = HttpStatusCode.OK, IList<HttpHeaderData> headers = null, string content = "", bool isFinal = true)
{
MemoryStream headerBytes = new MemoryStream();
int contentLength = -1;
Expand Down Expand Up @@ -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);
}
}

Expand All @@ -955,13 +955,13 @@ private string GetResponseHeaderString(HttpStatusCode statusCode, IList<HttpHead
return headerString;
}

public override async Task SendResponseHeadersAsync(HttpStatusCode statusCode = HttpStatusCode.OK, IList<HttpHeaderData> headers = null, int requestId = 0)
public override async Task SendResponseHeadersAsync(HttpStatusCode statusCode = HttpStatusCode.OK, IList<HttpHeaderData> headers = null)
{
string headerString = GetResponseHeaderString(statusCode, headers);
await SendResponseAsync(headerString).ConfigureAwait(false);
}

public override async Task SendPartialResponseHeadersAsync(HttpStatusCode statusCode = HttpStatusCode.OK, IList<HttpHeaderData> headers = null, int requestId = 0)
public override async Task SendPartialResponseHeadersAsync(HttpStatusCode statusCode = HttpStatusCode.OK, IList<HttpHeaderData> headers = null)
{
string headerString = GetResponseHeaderString(statusCode, headers);

Expand All @@ -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);
}
Expand Down Expand Up @@ -1047,7 +1047,7 @@ public override async Task<HttpRequestData> 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)
Expand Down

0 comments on commit 8b67772

Please sign in to comment.