     (.setHandler s (gzip-handler hc))
     (assoc webserver-context :server s)))
 
-(sm/defn ^:always-validate
-  initialize-context :- WebserverServiceContext
-  "Create a webserver-context which contains a HandlerCollection and a
-  ContextHandlerCollection which can accept the addition of new handlers
-  before the webserver is started."
-  []
-  (let [^ContextHandlerCollection chc (ContextHandlerCollection.)]
-    {:handlers chc
-     :state (atom {})
-     :server nil}))
-
 (sm/defn ^:always-validate start-webserver! :- WebserverServiceContext
   "Creates and starts a webserver.  Returns an updated context map containing
   the Server object."

;; NOTE: this code is an adaptation of ring-jetty-handler.
;;  It adds some SSL utility functions, and
;;  provides the ability to dynamically register ring handlers.

(ns puppetlabs.trapperkeeper.services.webserver.jetty9-core
  "Adapter for the Jetty webserver."
  (:import (org.eclipse.jetty.server Handler Server Request ServerConnector
                                     HttpConfiguration HttpConnectionFactory
                                     ConnectionFactory)

    (.setHandler handler)
    (.setMimeTypes (gzip-excluded-mime-types))
    (.setExcludeMimeTypes true)))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Handler Helper Functions

(sm/defn ^:always-validate
  add-handler :- ContextHandler
  [webserver-context :- WebserverServiceContext
   handler :- ContextHandler]
  (.addHandler (:handlers webserver-context) handler)
  handler)

(defn- ring-handler
  "Returns an Jetty Handler implementation for the given Ring handler."
  [handler]
  (proxy [AbstractHandler] []
    (handle [_ ^Request base-request request response]
      (let [request-map  (servlet/build-request-map request)
            response-map (handler request-map)]
        (when response-map
          (servlet/update-servlet-response response response-map)
          (.setHandled base-request true))))))

(sm/defn ^:always-validate
  proxy-servlet :- ProxyServlet
