Search code examples
vert.xvertxoptions

Vert.x GET api returns 400 Bad Request for some traffic


We have a Vert.x application where we are hosting few HTTP GET and POST api's. While testing on production we are facing an issue where one GET api response to client is 400 - Bad Request.

This api works most of the times but for few clients it is giving 400 - Bad Request.

We have verified that client is correctly sending the request but getting 400 in response.

But on server where application is running we could not find any logs.

There is an log statement at the first line of Handler which is not printing for 400 - Bad Request case and it is being printed for all successful reqeusts.


Solution

  • After lots of debugging what we identified that requests are reaching vertx application and router is rejecting the requests with 400 - Bad Request.

    By default vertx accepts the requests with total Header size of 8kb. In some of the cases the Cookies in Headers were coming more than 8KB in size, hence the error.

    We can override the Header size limit in HttpServerOptions. After that issue was resolved.

            vertx.createHttpServer
                (new HttpServerOptions().setSsl(true)
                        .setMaxHeaderSize(32 * 1024)
                        .setTcpKeepAlive(true))
                .requestHandler(router::accept)
                .listen(config().getJsonObject("http").getInteger("port"), handler -> {
                    futureHttpServer.complete();
                    Logger.debug("httpservice deployed");
                });