Skip to content
This repository has been archived by the owner on Jul 9, 2023. It is now read-only.

Commit

Permalink
Merge pull request #901 from justcoding121/develop
Browse files Browse the repository at this point in the history
http2 fix
  • Loading branch information
honfika authored Jan 29, 2022
2 parents f74219a + 04fa2f9 commit 28ed4c9
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public void Update(SessionEventArgsBase args)
var response = HttpClient.Response;
int statusCode = response?.StatusCode ?? 0;
StatusCode = statusCode == 0 ? "-" : statusCode.ToString();
Protocol = request.RequestUri.Scheme;
Protocol = request.HttpVersion.Major == 2 ? "http2" : request.RequestUri.Scheme;
ClientConnectionId = args.ClientConnectionId;
ServerConnectionId = args.ServerConnectionId;

Expand Down
3 changes: 2 additions & 1 deletion src/Titanium.Web.Proxy/Http/KnownHeaders.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public static class KnownHeaders
public static KnownHeader ConnectionKeepAlive = "keep-alive";

public static KnownHeader ContentLength = "Content-Length";
public static KnownHeader ContentLengthHttp2 = "content-length";

public static KnownHeader ContentType = "Content-Type";
public static KnownHeader ContentTypeCharset = "charset";
Expand Down Expand Up @@ -48,4 +49,4 @@ public static class KnownHeaders
public static KnownHeader TransferEncoding = "Transfer-Encoding";
public static KnownHeader TransferEncodingChunked = "chunked";
}
}
}
5 changes: 4 additions & 1 deletion src/Titanium.Web.Proxy/Http/RequestResponseBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,10 @@ public long ContentLength
{
if (value >= 0)
{
Headers.SetOrAddHeaderValue(KnownHeaders.ContentLength, value.ToString());
Headers.SetOrAddHeaderValue(
HttpVersion >= HttpHeader.Version20
? KnownHeaders.ContentLengthHttp2
: KnownHeaders.ContentLength, value.ToString());
IsChunked = false;
}
else
Expand Down
5 changes: 5 additions & 0 deletions src/Titanium.Web.Proxy/Http/Response.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ public override bool HasBody
return true;
}

if (ContentLength == -1 && HttpVersion == HttpHeader.Version20)
{
return true;
}

// has response if connection:keep-alive header exist and when version is http/1.0
// Because in Http 1.0 server can return a response without content-length (expectation being client would read until end of stream)
if (KeepAlive && HttpVersion == HttpHeader.Version10)
Expand Down

0 comments on commit 28ed4c9

Please sign in to comment.