Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/main/java/uk/ac/ox/ctl/canvasproxy/ProxyController.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@
import java.net.SocketTimeoutException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

/**
* This proxy just sends requests on to Canvas. All it does is add the bearer token for the user.
Expand Down Expand Up @@ -85,6 +88,14 @@ public ResponseEntity<?> proxy(AbstractOAuth2TokenAuthenticationToken principal,

// We don't want to pass through cookies from Canvas.
httpHeaders.remove("Set-Cookie");
Set<String> hopByHopHeaders = new HashSet<>(Set.of("Connection", "Keep-Alive", "Proxy-Authenticate",
"Proxy-Authorization", "TE", "Trailer", "Transfer-Encoding", "Upgrade"));
response.getHeaders().getOrEmpty("Connection").stream()
.flatMap(connectionValue -> Arrays.stream(connectionValue.split(",")))
.map(String::trim)
.filter(headerName -> !headerName.isEmpty())
.forEach(hopByHopHeaders::add);
hopByHopHeaders.forEach(httpHeaders::remove);
return new ResponseEntity<>(response.getBody().readAllBytes(), httpHeaders, response.getStatusCode());
Comment on lines 89 to 99
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implemented in commit fbfacd0: the proxy now strips the full standard hop-by-hop header set and also removes any additional header names declared by upstream Connection before returning the response.

});
} catch (ResourceAccessException e) {
Expand Down