Skip to content

QoSHandler: Allow customization of rejection status code (429 vs 503) and improve extensibility #14085

@jan-osc

Description

@jan-osc

Jetty version(s)
12.1.X

Enhancement Description
Two changes to make the class QoSHandler more flexible:

  1. Allow configuration of the status code - Add a field and setter to configure the status code returned when limits are exceeded. It could also be the constructor parameter.
// Default to 503 for backward compatibility
private int _throttledStatus = HttpStatus.SERVICE_UNAVAILABLE_503;

public void setThrottledStatus(int status) {
    _throttledStatus = status;
}
  1. Relax the visibility of internal rejection methods
    Change the visibility of some methods from private to protected. This would allow developers to extend the class and implement custom rejection logic (e.g., by adding specific headers such as Retry-After or custom JSON error bodies).

Specifically, these methods:

  • private boolean tooManyRequests(Response response, Callback callback)
  • private boolean notAvailable(Response response, Callback callback)

Currently, the only way to achieve this without copying the entire class is a complex workaround involving:

  1. A "Marker" handler inside the QoS handler to flag successful passage.
  2. A "Wrapper" handler outside the QoS handler that intercepts 503 responses, checks for the absence of the marker, and swaps the code to 429

This adds unnecessary object allocation and runtime overhead for a simple status code change.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions