reverse-proxy: POST not working in IIS/Express due to IsUpgradableRequest

– Admin Edit: Unrelated issue content hidden –

I’m currently unable to get Request Transforms to work on NETCore 3.1 in VS19 16.6.5.

    {
        "RouteId": "oh/rest",
        "BackendId": "oh",
        "Match": {
          "Host": "localhost",
          "Path": "/rest/{*remainder}"
        },
        "Transforms": [
          { "X-Forwarded": "" },
          { "RequestHeaderOriginalHost": "true" }
        ]
      }

From wireshark:

POST /rest/items/Flush2Relay_Switch1 HTTP/1.1\r\n
    Host: otherhost:8080\r\n
    Accept: application/json, text/plain, */*\r\n
    Accept-Encoding: gzip, deflate, br\r\n
    Accept-Language: en-US, en; q=0.9\r\n
    Cache-Control: no-cache\r\n
    Connection: close\r\n
     [truncated]Cookie: HIDDDEN
    Pragma: no-cache\r\n
    Referer: https://localhost:44354/paperui/index.html\r\n
    User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.106 Safari/537.36 Edg/83.0.478.54\r\n
    Origin: https://localhost:44354\r\n
    sec-fetch-site: same-origin\r\n
    sec-fetch-mode: cors\r\n
    sec-fetch-dest: empty\r\n
    X-Forwarded-Proto: https\r\n
    X-Forwarded-Host: localhost:44354\r\n
    X-Forwarded-For: ::1\r\n
    Content-Length: 0\r\n
    \r\n
    [Full request URI: http://otherhost:8080/rest/items/Flush2Relay_Switch1]
    [HTTP request 1/1]
    [Response in frame: 52458]

The proxy is proxying correctly but the incoming request is not being modified. Is this feature still in development?

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 19 (13 by maintainers)

Commits related to this issue

Most upvoted comments

Here’s a workaround you can do without modifying YARP. Add this in Startup anywhere before UseEndpoints, or even in the MapReverseProxy pipeline. Note this completely disables WebSocket proxying.

            app.Use((context, next) =>
            {
                context.Features.Set<IHttpUpgradeFeature>(null);
                return next();
            });

You could choose to be more selective by checking the upgrade header first.

            app.Use((context, next) =>
            {
                if (!string.Equals("WebSocket", context.Request.Headers[HeaderNames.Upgrade], StringComparison.OrdinalIgnoreCase))
                {
                    context.Features.Set<IHttpUpgradeFeature>(null);
                }
                return next();
            });

I’m going to add the same check for preview3 as a temporary mitigation.

Transforms were introduced in preview2 which has not been released yet. You can either build the repo locally or wait for preview2 to release (soon).