diff --git a/crnk-core/src/main/java/io/crnk/core/engine/internal/http/JsonApiRequestProcessor.java b/crnk-core/src/main/java/io/crnk/core/engine/internal/http/JsonApiRequestProcessor.java index caf47472e..9dbce1ddb 100644 --- a/crnk-core/src/main/java/io/crnk/core/engine/internal/http/JsonApiRequestProcessor.java +++ b/crnk-core/src/main/java/io/crnk/core/engine/internal/http/JsonApiRequestProcessor.java @@ -129,11 +129,28 @@ public Result processAsync(HttpRequestContext requestContext) { } QueryContext queryContext = requestContext.getQueryContext(); return processAsync(jsonPath, method, parameters, requestDocument, queryContext) - .map(this::toHttpResponse); + .map(this::toHttpResponse) + .map(httpResp -> transferHeaders(httpResp, requestContext)); } return resultFactory.just(buildMethodNotAllowedResponse(method)); } + private HttpResponse transferHeaders(final HttpResponse targetResponse, final HttpRequestContext requestContext) { + final HttpResponse srcResponse = requestContext.getResponse(); + if (srcResponse == null) { + return targetResponse; + } + + // transfer only header that are not set already + srcResponse.getHeaders().forEach((k, srcValue) -> { + final String targetValue = targetResponse.getHeader(k); + if (targetValue == null && srcValue != null) { + targetResponse.setHeader(k, srcValue); + } + }); + return targetResponse; + } + private Result checkMethod(HttpRequestContext requestContext) { String method = requestContext.getMethod(); boolean isPatch = method.equals(HttpMethod.PATCH.toString());