Twice custom headers in Quarkus rest

232 views Asked by At

I have another serious problem with Quarkus. Any custom header in Rest request - response is doubled.

class Filters(var log: Logger) {

    companion object {
        private val CORRELATION_ID_HEADER_NAME = "X-Correlation-Id";
        private val CORRELATION_ID_LOG_VAR_NAME = "correlationId";
    }

    @ServerRequestFilter(preMatching = true)
    fun preMatchingFilter(requestContext: ContainerRequestContext) {
        var corellationId = requestContext.getHeaderString(CORRELATION_ID_HEADER_NAME)
        corellationId ?: run {
            corellationId = UUID.randomUUID().toString()
            requestContext.headers.add(CORRELATION_ID_HEADER_NAME, corellationId)
        }
        MDC.put(CORRELATION_ID_LOG_VAR_NAME, corellationId)
        log.info(MDC.get(CORRELATION_ID_LOG_VAR_NAME))
    }

    @ServerResponseFilter
    fun responseFilter(responseContext: ContainerResponseContext) {
        var corellationId = MDC.get(CORRELATION_ID_LOG_VAR_NAME)
        corellationId ?: run {
            corellationId = UUID.randomUUID().toString()
            responseContext.headers.add(CORRELATION_ID_HEADER_NAME, corellationId)
        }.also { MDC.put(CORRELATION_ID_LOG_VAR_NAME, corellationId) }
        log.info(MDC.get(CORRELATION_ID_LOG_VAR_NAME))
    }
}

And header x-corellation-id is always doubled. Can you help me, please

0

There are 0 answers