-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix HTTP request message being marked as completed too early (#63)
- Loading branch information
Showing
5 changed files
with
63 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
example.db | ||
example.db-* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using System.Net; | ||
|
||
namespace Passwordless.Helpers.Extensions; | ||
|
||
internal static class HttpExtensions | ||
{ | ||
private class NonDisposableHttpContent : HttpContent | ||
{ | ||
private readonly HttpContent _content; | ||
|
||
public NonDisposableHttpContent(HttpContent content) => _content = content; | ||
|
||
protected override async Task SerializeToStreamAsync( | ||
Stream stream, | ||
TransportContext? context | ||
) => await _content.CopyToAsync(stream); | ||
|
||
protected override bool TryComputeLength(out long length) | ||
{ | ||
length = default; | ||
return false; | ||
} | ||
} | ||
|
||
public static HttpRequestMessage Clone(this HttpRequestMessage request) | ||
{ | ||
var clonedRequest = new HttpRequestMessage(request.Method, request.RequestUri) | ||
{ | ||
Version = request.Version, | ||
// Don't dispose the original request's content | ||
Content = request.Content is not null | ||
? new NonDisposableHttpContent(request.Content) | ||
: null | ||
}; | ||
|
||
foreach (var header in request.Headers) | ||
clonedRequest.Headers.TryAddWithoutValidation(header.Key, header.Value); | ||
|
||
if (request.Content is not null && clonedRequest.Content is not null) | ||
{ | ||
foreach (var header in request.Content.Headers) | ||
clonedRequest.Content.Headers.TryAddWithoutValidation(header.Key, header.Value); | ||
} | ||
|
||
return clonedRequest; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters