When running the following code
@Override
public void start(Future fut) {
Router router = Router.router(vertx);
router.route(HttpMethod.GET, "/").handler( (RoutingContext routingContext) -> {
HttpServerResponse response = routingContext.response();
response.setChunked(true);
response.putHeader("X-HEADER-BEFORE", "true");
response.write("HELLO WORLD");
response.putHeader("X-HEADER-AFTER", "true");
response.setStatusCode(500);
response.end();
});
vertx.createHttpServer().requestHandler(router::accept).listen(8080, (AsyncResult -> {fut.complete();}));
}
I would expect the following behaviour:
- header "X-HEADER-BEFORE" is set to "true"
- header "X-HEADER-AFTER" is set to "true"
- the http response code is 500
However, this is what I have been observing with both vertx 3.3.0 and 3.3.2:
- header "X-HEADER-BEFORE" is set to "true"
- header "X-HEADER-AFTER" is not set at all
- the http response code is 200
Basically status codes and http headers that are set after the body is written are ignored.
This is the corresponding curl output:
curl -vvvv localhost:8080
* Rebuilt URL to: localhost:8080/
* Trying ::1...
* Connected to localhost (::1) port 8080 (#0)
> GET / HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.43.0
> Accept: */*
>
< HTTP/1.1 200 OK
< X-HEADER-BEFORE: true
< Transfer-Encoding: chunked
<
* Connection #0 to host localhost left intact
HELLO WORLD
Is this expected behaviour?