Skip to content

Instantly share code, notes, and snippets.

@kleinron
Last active January 24, 2019 18:50
Show Gist options
  • Save kleinron/6b61aa5fff5fc3b68419 to your computer and use it in GitHub Desktop.
Save kleinron/6b61aa5fff5fc3b68419 to your computer and use it in GitHub Desktop.
spark java enable gzip if needed
private static void enableGzipIfNeeded(spark.Request request, spark.Response response) {
String accept = request.headers("Accept-Encoding");
if (accept == null) {
return;
}
String[] tokens = accept.split(",");
if (Arrays.stream(tokens).map(String::trim).anyMatch(s -> s.equalsIgnoreCase("gzip"))) {
response.header("Content-Encoding", "gzip");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment