Skip to content

Commit

Permalink
Fix potential NPE in websocket upgrade check (#15)
Browse files Browse the repository at this point in the history
* Pick up latest version of io.mantisrx, use shaded ObjectMapper to serialize/deserialize objects

* Remove jackson dependency

* Handle NPE in websocket upgrade check

* Fix breaking changes from zuul-core 2.1.8

Co-authored-by: Calvin Cheung <[email protected]>
  • Loading branch information
calvin681 and calvin681 authored Aug 27, 2020
1 parent 1ce4f51 commit 95cdc14
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 5 deletions.
6 changes: 6 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,13 @@ dependencies {
exclude group: 'com.google.guava', module: 'guava'
exclude group: 'com.google.inject', module: 'guice'
}
api('com.netflix.zuul:zuul-guice:latest.release') {
exclude group: 'com.google.guava', module: 'guava'
exclude group: 'com.google.inject', module: 'guice'
}
implementation 'com.netflix.blitz4j:blitz4j:1.37.2'
implementation "com.netflix.governator:governator:1.+"
implementation "org.apache.commons:commons-lang3:3.+"
api "io.mantisrx:mantis-discovery-proto:$mantisDiscoveryProtoVersion"
api "io.mantisrx:mantis-client:$mantisClientVersion"
api "io.mantisrx:mantis-runtime:$mantisClientVersion"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public int filterOrder() {
@Override
public boolean shouldFilter(HttpResponseMessage response) {
return response.getOutboundRequest().getPath().matches("^/api/v1/jobClusters/.*/latestJobDiscoveryInfo$")
&& response.getHeaders().get(Constants.MANTISAPI_CACHED_HEADER).isEmpty()
&& response.getHeaders().getAll(Constants.MANTISAPI_CACHED_HEADER).isEmpty()
&& cacheEnabled.get();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,6 @@ public boolean shouldFilter(HttpResponseMessage msg) {
return msg.getOutboundRequest().getContext().getRouteVIP() != null
&& msg.getOutboundRequest().getContext().getRouteVIP().equalsIgnoreCase("api")
&& msg.getInboundRequest().getMethod().equalsIgnoreCase("get")
&& msg.getHeaders().get(Constants.MANTISAPI_CACHED_HEADER).size() == 0; // Set by the MasterCacheHitChecker, ensures we aren't re-caching.
&& msg.getHeaders().getAll(Constants.MANTISAPI_CACHED_HEADER).size() == 0; // Set by the MasterCacheHitChecker, ensures we aren't re-caching.
}
}
2 changes: 1 addition & 1 deletion src/main/java/io/mantisrx/api/filters/OutboundHeaders.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ private void upsert(HttpResponseMessage resp, AsciiString name, String value) {
}

private void addHeaderIfMissing(HttpResponseMessage resp, AsciiString name, String value) {
if (resp.getHeaders().get(name.toString()).size() == 0) {
if (resp.getHeaders().getAll(name.toString()).size() == 0) {
resp.getHeaders().add(name.toString(), value);
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/io/mantisrx/api/push/MantisSSEHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,10 @@ private boolean isWebsocketUpgrade(HttpRequest request) {
HttpHeaders headers = request.headers();
// Header "Connection" contains "upgrade" (case insensitive) and
// Header "Upgrade" equals "websocket" (case insensitive)
return headers.get(HttpHeaderNames.CONNECTION).toLowerCase().contains("upgrade") &&
headers.get(HttpHeaderNames.UPGRADE).toLowerCase().equals("websocket");
String connection = headers.get(HttpHeaderNames.CONNECTION);
String upgrade = headers.get(HttpHeaderNames.UPGRADE);
return connection != null && connection.toLowerCase().contains("upgrade") &&
upgrade != null && upgrade.toLowerCase().equals("websocket");
}


Expand Down

0 comments on commit 95cdc14

Please sign in to comment.