Implementation:APIJSON APIJSON Demo RepeatHeaderFilter
| Knowledge Sources | |
|---|---|
| Domains | Web_Framework, HTTP, Middleware |
| Last Updated | 2026-10-14 00:00 GMT |
Overview
Concrete tool for deduplicating HTTP request headers by preferring x-header variants when both header and x-header are present.
Description
The RepeatHeaderFilter is a Spring OncePerRequestFilter that wraps the HttpServletRequest to resolve duplicate header issues. When a non-x- prefixed header is requested, it first checks for the x- prefixed equivalent and returns that value if present. This prevents parsing errors when APIJSON clients send both header and x-header simultaneously.
Usage
Register this filter (via @Component) when your APIJSON server receives requests with duplicate headers and needs to prefer the x- prefixed variant.
Code Reference
Source Location
- Repository: APIJSON_APIJSON_Demo
- File: APIJSON-Java-Server/APIJSONBoot-MultiDataSource/src/main/java/apijson/boot/RepeatHeaderFilter.java
- Lines: 1-60
Signature
@Component
public class RepeatHeaderFilter extends OncePerRequestFilter {
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
throws ServletException, IOException;
}
Import
import apijson.boot.RepeatHeaderFilter;
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| request | HttpServletRequest | Yes | Incoming HTTP request with possible duplicate headers |
| response | HttpServletResponse | Yes | HTTP response |
| filterChain | FilterChain | Yes | Servlet filter chain |
Outputs
No direct output; wraps request and passes to next filter.
Usage Examples
Automatic Registration
// RepeatHeaderFilter is annotated with @Component, so Spring Boot
// auto-registers it. No manual configuration needed.
// When a request arrives with both "Token" and "x-token" headers,
// request.getHeader("Token") returns the "x-token" value.