Skip to content

Commit

Permalink
Merge pull request #189 from ibi-group/dedupe-http-response-headers
Browse files Browse the repository at this point in the history
For proxied responses, we have been combining headers which we need to dedupe
  • Loading branch information
JymDyerIBI authored Oct 31, 2023
2 parents 781aa7d + 9e5ecdd commit 1abd925
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@
<dependency>
<groupId>com.sparkjava</groupId>
<artifactId>spark-core</artifactId>
<version>2.7.2</version>
<version>2.9.4</version>
</dependency>

<!--
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,14 @@ 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()))
.forEach(h -> response.header(h.getName(), h.getValue()));

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

0 comments on commit 1abd925

Please sign in to comment.