Skip to content

Commit

Permalink
Improve the error message for SPDY
Browse files Browse the repository at this point in the history
  • Loading branch information
MihaZupan committed Jan 28, 2025
1 parent 33bff40 commit 93d0a04
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/ReverseProxy/Forwarder/HttpForwarder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -370,9 +370,10 @@ public async ValueTask<ForwarderError> SendAsync(
var outgoingUpgrade = false;
var outgoingConnect = false;
var tryDowngradingH2WsOnFailure = false;

if (isSpdyRequest)
{
// Can only be done on HTTP/1.1, force regardless of options.
// Can only be done on HTTP/1.1.
outgoingUpgrade = true;
}
else if (isH1WsRequest || isH2WsRequest)
Expand All @@ -384,6 +385,7 @@ public async ValueTask<ForwarderError> SendAsync(
case (2, HttpVersionPolicy.RequestVersionOrHigher, _):
outgoingConnect = true;
break;

case (1, HttpVersionPolicy.RequestVersionOrHigher, true):
case (2, HttpVersionPolicy.RequestVersionOrLower, true):
case (3, HttpVersionPolicy.RequestVersionOrLower, true):
Expand All @@ -392,8 +394,7 @@ public async ValueTask<ForwarderError> SendAsync(
tryDowngradingH2WsOnFailure = true;
break;
#endif
// 1.x Lower or Exact, regardless of HTTPS
// Anything else without HTTPS except 2 Exact

default:
// Override to use HTTP/1.1, nothing else is supported.
outgoingUpgrade = true;
Expand All @@ -408,7 +409,9 @@ public async ValueTask<ForwarderError> SendAsync(
// Can only be done on HTTP/1.1, throw if disallowed by options.
if (!http1IsAllowed)
{
throw new HttpRequestException("An outgoing HTTP/1.1 Upgrade request is required to proxy this request, but is disallowed by HttpVersionPolicy.");
throw new HttpRequestException(isSpdyRequest
? "SPDY requests require HTTP/1.1 support, but outbound HTTP/1.1 was disallowed by HttpVersionPolicy."
: "An outgoing HTTP/1.1 Upgrade request is required to proxy this request, but is disallowed by HttpVersionPolicy.");
}

destinationRequest.Version = HttpVersion.Version11;
Expand Down

0 comments on commit 93d0a04

Please sign in to comment.