Skip to content

Instantly share code, notes, and snippets.

@grimradical
Created November 11, 2013 20:03
Show Gist options
  • Save grimradical/7419411 to your computer and use it in GitHub Desktop.
Save grimradical/7419411 to your computer and use it in GitHub Desktop.
diff --git a/src/com/puppetlabs/jetty.clj b/src/com/puppetlabs/jetty.clj
index 863467d..bbc47df 100644
--- a/src/com/puppetlabs/jetty.clj
+++ b/src/com/puppetlabs/jetty.clj
@@ -2,6 +2,7 @@
;;
(ns com.puppetlabs.jetty
(:import (org.eclipse.jetty.server Server)
+ (org.eclipse.jetty.server.handler GzipHandler)
(org.eclipse.jetty.server.nio SelectChannelConnector))
(:require [ring.adapter.jetty :as jetty])
(:use [clojure.tools.logging :as log]
@@ -86,6 +87,14 @@
(.addConnector server connector)))
server))
+(defn add-gzip-handler
+ [server]
+ (let [current-handler (.getHandler server)
+ gzip-handler (doto (GzipHandler.)
+ (.setHandler current-handler))]
+ (.setHandler server gzip-handler)
+ server))
+
(defn run-jetty
"Version of `ring.adapter.jetty/run-jetty` that uses the above
monkey patch."
@@ -93,4 +102,4 @@
(when (empty? (select-keys options [:port :ssl? :ssl-port]))
(throw (IllegalArgumentException. "No ports were specified to bind")))
(with-redefs [jetty/create-server create-server]
- (jetty/run-jetty handler options)))
+ (jetty/run-jetty handler (assoc options :configurator add-gzip-handler))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment