Gateway should handle header 'Expect 100-continue' compliant with rfc2616
See original GitHub issue
- If a proxy receives a request that includes an Expect request- header field with the “100-continue” expectation, and the proxy either knows that the next-hop server complies with HTTP/1.1 or higher, or does not know the HTTP version of the next-hop server, it MUST forward the request, including the Expect header field.
Steps to reproduce problem
Target server: Spring Boot 2.1.8 (Tomcat)
@SpringBootApplication @RestController
public class MyDownstreamApp {
public static void main(String[] args) {
SpringApplication.run(MyDownstreamApp.class, args);
}
@PutMapping("/put")
String put(@RequestParam String x) {
System.out.println("x: " +x);
return "hello";
}
}
Cloud gateway: Greenwich SR3
@SpringBootApplication
public class MyGatewayApp {
@Bean
RouteLocator myRoutes(RouteLocatorBuilder builder) {
return builder.routes()
.route(p -> p
.path("/put")
.uri("http://localhost:8080"))
.build();
}
public static void main(String[] args) {
SpringApplication.run(MyGatewayApp.class, "--server.port=8082");
}
}
When target server is called directly:
curl localhost:8080/put -X PUT -H 'Expect: 100-continue' -d x=foo1 -v
communication flow is OK
- Client sends
Expect: 100-continue
- Server reponds
100-continue
- Client sends complete request
- Server responds
hello
> Expect: 100-continue > Content-Length: 6 > Content-Type: application/x-www-form-urlencoded > < HTTP/1.1 100 * We are completely uploaded and fine < HTTP/1.1 200 < Content-Type: text/plain;charset=UTF-8 < Content-Length: 5
When target server is called through gateway:
curl localhost:8082/put -X PUT -H 'Expect: 100-continue' -d x=foo1 -v
communication flow is not OK. My wireshark investigation
- Client sends
Expect: 100-continue
to gateway - Gateway responds
100-continue
- Client sends complete request to gateway
- I’m not sure 100% what happens in point 4
- Target server responds
100-continue
to gateway - Gateway sends complete request to target server
- Target server responds
hello
- Gateway forwards
100-continue
to client - Client waits for response
hello
but it is not forwarded
> Expect: 100-continue > Content-Length: 6 > Content-Type: application/x-www-form-urlencoded > < HTTP/1.1 100 Continue * We are completely uploaded and fine < HTTP/1.1 100 Continue (hang up)
Response 100 Continue
is received 2 times - once generated by gateway itself, second forwarded from target server, but true response never reach client.
Worth to notice that workaround is filter our header 'Expect 100-continue` when gateway forwards request to target server
Issue Analytics
- State:
- Created 4 years ago
- Reactions:5
- Comments:19 (7 by maintainers)
I’m able to send a
100 Continue
from gateway (or let the downstream service send it), but it seems the request is terminated and the client never sends the body. I’m not sure where in the stack the problem is.This clearly violates https://datatracker.ietf.org/doc/html/rfc7231#section-5.1.1. If the proxy cannot handle the expect handle it must ask the origin. So I expect the API gateway to forward all request headers to the origin server if it cannot make a decision based on the headers.