Skip to content
This repository has been archived by the owner on Mar 22, 2023. It is now read-only.

Commit

Permalink
sends default trailers only for http2 requests
Browse files Browse the repository at this point in the history
  • Loading branch information
shamsimam committed Jun 28, 2019
1 parent 29eae78 commit 11cccbc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
4 changes: 3 additions & 1 deletion src/clj/qbits/jet/servlet.clj
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,9 @@
^Request servlet-request (:servlet-request request-map)
servlet-response (.getServletResponse servlet-request)]
(when (and trailers (instance? Response servlet-response))
(.setTrailers ^Response servlet-response (util/trailers-ch->supplier trailers)))
(let [request-protocol (some-> servlet-request .getProtocol)
http2? (util/http2-request? request-protocol)]
(.setTrailers ^Response servlet-response (util/trailers-ch->supplier trailers http2?))))
(set-status+headers! servlet-response request-map status headers)
(set-body! servlet-response request-map body)))

Expand Down
21 changes: 9 additions & 12 deletions src/clj/qbits/jet/util.clj
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,16 @@
(when-let [trailers (trailers-fn)]
(map->http-fields trailers))))))

(defn- map->non-empty-http-fields
"Ensures that we return on-empty http fields as trailers in responses.
This is to prevent issues while using clients who do not accept empty trailers in responses."
;; TODO remove when https://github.com/eclipse/jetty.project/issues/3829 is fixed and empty trailer frames are not sent.
[trailers-map]
(if (seq trailers-map)
(map->http-fields trailers-map)
(map->http-fields {"x-waiter-trailer-reason" "ensures-non-empty-trailers"})))

(defn trailers-ch->supplier
[trailers-ch]
[trailers-ch http2?]
(when trailers-ch
(reify Supplier
(get [_]
(map->non-empty-http-fields (async/<!! trailers-ch))))))

(let [trailers-map (async/<!! trailers-ch)]
(if (seq trailers-map)
(map->http-fields trailers-map)
(when http2?
;; Ensures that we return on-empty http fields as trailers in responses.
;; This is to prevent issues while using http2 clients who do not accept empty trailers in responses.
;; TODO remove when https://github.com/eclipse/jetty.project/issues/3829 is fixed and empty trailer frames are not sent.
(map->http-fields {"x-waiter-trailer-reason" "ensures-non-empty-trailers"}))))))))

0 comments on commit 11cccbc

Please sign in to comment.