Skip to content

[2.15][Netty] Cannot access encoder in case of "413 Content Too Large" #2806

@csisy

Description

@csisy

Hello,

We have a custom error handler that collects extra information and sends it as a response using the context.render method.

The problem is, that if the incoming request is larger than the configured limit, the NettyHandler automatically sends an error with the 413 status code.

context.sendError(new StatusCodeException(StatusCode.REQUEST_ENTITY_TOO_LARGE));

However - since we are using the render method - our error handler cannot run successfully because the context object itself is not complete at this stage. In our concrete example, it cannot determine the encoder to use because the route member is null in the context.

There are two different solutions that came to my mind:

Possible solution 1

Instead of using the render method, we could use the registered encoders to manually encode the content then simply send the response. However, I don't know any way to obtain an encoder, except for creating it from scratch, which is inconvenient. We can register encoders, but their usage seems to be private.

So something like app.encoderOf(mediaType) would be nice.

Possible solution 2

Somehow change the order of things in the NettyHandler and initialze the context when the first part of a request is received. In this case if there are any errors while the request is processed, the error handler could safely use the render method.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions