-
-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #883 from clojars/tobias/upgrade-to-jetty-11
Upgrade to Jetty 11
- Loading branch information
Showing
3 changed files
with
49 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,44 @@ | ||
(ns clojars.ring-servlet-patch | ||
(:import | ||
(javax.servlet.http | ||
(jakarta.servlet.http | ||
HttpServletResponse | ||
HttpServletResponseWrapper) | ||
(org.eclipse.jetty.server | ||
Request) | ||
Response | ||
Server) | ||
(org.eclipse.jetty.server.handler | ||
AbstractHandler))) | ||
HandlerWrapper) | ||
(org.eclipse.jetty.servlet | ||
ServletContextHandler))) | ||
|
||
(set! *warn-on-reflection* true) | ||
|
||
(defn response-wrapper [response] | ||
(defn response-wrapper | ||
[^Response response] | ||
(proxy [HttpServletResponseWrapper] [response] | ||
(setHeader [name value] | ||
(if (and (= name "status-message") value) | ||
(.setStatus response (.getStatus response) value) | ||
(proxy-super setHeader name value))))) | ||
;; Jetty ignores the reason passed to HttpServletResponse#setStatus(), | ||
;; so we have to call a method on Jetty's response impl instead. | ||
(.setStatusWithReason ^Response response (.getStatus response) value) | ||
(.setHeader ^HttpServletResponse response name value))))) | ||
|
||
(defn handler-wrapper ^AbstractHandler [handler] | ||
(proxy [AbstractHandler] [] | ||
(handle [target ^Request base-request request response] | ||
(let [response (response-wrapper response)] | ||
(.handle handler target base-request request response))))) | ||
(defn handler-wrapper | ||
^HandlerWrapper [] | ||
(proxy [HandlerWrapper] [] | ||
(handle [target base-request request response] | ||
(let [response (response-wrapper response) | ||
;; This prevents reflection on the proxy-super call | ||
;; by hinting the explicit `this`. | ||
^HandlerWrapper this this] | ||
(proxy-super handle target base-request request response))))) | ||
|
||
(defn use-status-message-header [server] | ||
(let [handler (.getHandler server)] | ||
(.setHandler server (handler-wrapper handler)))) | ||
(defn use-status-message-header | ||
"This adds a wrapper around the servlet handler to override .setHeader on the response. | ||
We do this so we can set the status message of the response by smuggling it | ||
through ring as a header, as this setting this is not exposed by ring. | ||
The status message is used to provide additional context when deploying." | ||
[^Server server] | ||
(let [^ServletContextHandler handler (.getHandler server)] | ||
(.insertHandler handler (handler-wrapper)))) |