我正在使用 Spring Boot 3 服务,该服务使用
spring-boot-starter-webflux
。该服务包含一个简单的端点:
@RestController
public class TestController {
@GetMapping("/test")
public String test() {
return "test";
}
}
假设我在端口 8080 上运行此服务。我可以按如下方式卷曲此端点并获得 HTTP 200 响应:
% curl -v -H "X-Forwarded-Host: localhost" http://localhost:8080/test
* Trying 127.0.0.1:8080...
* Connected to localhost (127.0.0.1) port 8080 (#0)
> GET /test HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.86.0
> Accept: */*
> X-Forwarded-Host: localhost
>
< HTTP/1.1 200 OK
< Content-Type: text/plain;charset=UTF-8
< Content-Length: 4
<
test%
但是,如果我使用包含
X-Forwarded-Host
的 :<port>
值制作对此端点的请求,我会收到 HTTP 400 响应:
% curl -v -H "X-Forwarded-Host: localhost:8080" http://localhost:8080/test
* Trying 127.0.0.1:8080...
* Connected to localhost (127.0.0.1) port 8080 (#0)
> GET /test HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.86.0
> Accept: */*
> X-Forwarded-Host: localhost:8080
>
< HTTP/1.1 400 Bad Request
< content-length: 0
<
包含端口号的
X-Forwarded-Host
标头似乎有问题。
问题: