microsoft / reverse-proxy

A toolkit for developing high-performance HTTP reverse proxy applications.
https://microsoft.github.io/reverse-proxy
MIT License
8.48k stars 835 forks source link

reverse-proxy will auto append "/" to the request adress #903

Closed Edward-Zhou closed 3 years ago

Edward-Zhou commented 3 years ago

Describe the bug

I am trying to redirect request to another domain to request static files like mp4 file. But it will append the "/" to the redirect request which cause the server fail to find the document

To Reproduce

asp.net core appsettings.json

  "ReverseProxy": {
    "Routes": [
      {
        "RouteId": "route1",
        "ClusterId": "cluster1",
        "Match": {
          "Path": "{**catch-all}"
        }
      }
    ],
    "Clusters": {
      "cluster1": {
        "Destinations": {
          "cluster1/destination1": {
            "Address": "http://qiniu.meekou.cn/tmp/wxf7af440ff55eb16f.o6zAJsykdr1no9f31bqQnFXBUmKI.F7XNsEHOYMgx55299128c977791aee009dd04aaf9ef6.mp4"
          }
        }
      }
    }
  }

The Debug output is

Yarp.ReverseProxy.Service.Proxy.HttpProxy: Information: Proxying to http://qiniu.meekou.cn/tmp/wxf7af440ff55eb16f.o6zAJsykdr1no9f31bqQnFXBUmKI.F7XNsEHOYMgx55299128c977791aee009dd04aaf9ef6.mp4/
Failed to load resource: the server responded with a status of 404 (Not Found) [https://localhost:44367/]

The proxy target is appending the "/" to the last.

Is there any way to avoid the "/"?

Kahbazi commented 3 years ago

Try this appsettings.json

  "ReverseProxy": {
    "Routes": [
      {
        "RouteId": "route1",
        "ClusterId": "cluster1",
        "Match": {
          "Path": "{**catch-all}"
        },
        "Transforms": [
            { "PathSet" : "tmp/wxf7af440ff55eb16f.o6zAJsykdr1no9f31bqQnFXBUmKI.F7XNsEHOYMgx55299128c977791aee009dd04aaf9ef6.mp4" }
        ]
      }
    ],
    "Clusters": {
      "cluster1": {
        "Destinations": {
          "cluster1/destination1": {
            "Address": "http://qiniu.meekou.cn/"
          }
        }
      }
    }
  }
Tratcher commented 3 years ago

The Destination Address field is a prefix that the current request path is appended to by default. The current request path in your sample must have been "/", so it was appended to the destination path. Note a request path always has at least "/". @Kahbazi gave a good solution here, re-writing the path.

karelz commented 3 years ago

Triage: Solved above.