Skip to content

Commit

Permalink
For proxied responses, we have been combining headers which can creat…
Browse files Browse the repository at this point in the history
…e duplicates ("Access-Control-Allow-Origin" is the most problematic). So dedupe them.
  • Loading branch information
JymDyerIBI committed Oct 30, 2023
1 parent 781aa7d commit 17e330e
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,15 @@ private String proxyPost(Request request, Response response) {
} catch(NullPointerException e) {
LOG.warn("Failed to read variables from GraphQL Plan request. Still passing to OTP2: {}", e.getMessage());
}

}

// provide response to requester as received from OTP server
Arrays.stream(otpDispatcherResponse.headers).forEach(header -> response.header(header.getName(), header.getValue()));
// Add response headers to requester as it was received from OTP server, but beware that
// spark.Response#header() will duplicate rather than update, so filter out duplicates.
Arrays.stream(otpDispatcherResponse.headers)
.filter(h -> !response.raw().containsHeader(h.getName()))
//.peek(h -> LOG.info("NEW {}={}", h.getName(), h.getValue()))
.forEach(h -> response.header(h.getName(), h.getValue()));

response.status(otpDispatcherResponse.statusCode);
return otpDispatcherResponse.responseBody;
}
Expand Down

0 comments on commit 17e330e

Please sign in to comment.