|
38 | 38 | StandardCompressionOptions)
|
39 | 39 | (io.netty.handler.codec.http
|
40 | 40 | HttpMessage
|
41 |
| - HttpObjectAggregator) |
| 41 | + HttpObjectAggregator |
| 42 | + HttpRequestDecoder |
| 43 | + LastHttpContent) |
42 | 44 | (io.netty.handler.codec.http2 Http2HeadersFrame)
|
43 | 45 | (java.io
|
44 | 46 | Closeable
|
|
1659 | 1661 | (is (= true (deref conn-closed 1000 :timeout)))
|
1660 | 1662 | (is (thrown? RequestCancellationException (deref rsp 1000 :timeout)))))))
|
1661 | 1663 |
|
| 1664 | +(deftest test-client-proxy-support |
| 1665 | + (with-http-ssl-servers basic-handler {} |
| 1666 | + (let [proxy-request (d/deferred) |
| 1667 | + proxy-server (tcp/start-server |
| 1668 | + (fn [stream _] |
| 1669 | + (d/future |
| 1670 | + (try |
| 1671 | + (let [stream-ch (:aleph/channel (meta stream)) |
| 1672 | + req (http.core/netty-request->ring-request |
| 1673 | + @(d/timeout! (s/take! stream) 1000) |
| 1674 | + false |
| 1675 | + stream-ch |
| 1676 | + nil)] |
| 1677 | + (assert (instance? LastHttpContent @(d/timeout! (s/take! stream) 1000))) |
| 1678 | + (-> stream-ch .pipeline (.remove "http-request-decoder")) |
| 1679 | + (when (= :connect (:request-method req)) |
| 1680 | + (when-let [[host port] (some-> req :uri (str/split #":" 2))] |
| 1681 | + (when-let [client (-> (tcp/client {:host host |
| 1682 | + :port (parse-long port) |
| 1683 | + :connect-timeout 1000}) |
| 1684 | + (d/timeout! 2000) |
| 1685 | + deref)] |
| 1686 | + (s/put! stream (netty/to-byte-buf "HTTP/1.0 200 Connection established\r\n\r\n")) |
| 1687 | + (s/connect stream client) |
| 1688 | + (s/connect client stream)))) |
| 1689 | + (d/success! proxy-request req)) |
| 1690 | + (catch Throwable e |
| 1691 | + (d/error! proxy-request e))))) |
| 1692 | + {:port 0 |
| 1693 | + :shutdown-timeout 0 |
| 1694 | + :raw-stream? true |
| 1695 | + :pipeline-transform (fn [^ChannelPipeline p] |
| 1696 | + (.addFirst p "http-request-decoder" (HttpRequestDecoder.)))})] |
| 1697 | + (binding [*connection-options* {:proxy-options {:host "localhost" |
| 1698 | + :port (netty/port proxy-server)}}] |
| 1699 | + (with-server proxy-server |
| 1700 | + (is (= string-response (some-> (http-get "/string") |
| 1701 | + (d/timeout! 1000) |
| 1702 | + deref |
| 1703 | + :body |
| 1704 | + bs/to-string))) |
| 1705 | + (is (= {:request-method :connect |
| 1706 | + :uri (str "localhost:" port) |
| 1707 | + :headers {"host" (str "localhost:" port) |
| 1708 | + "proxy-connection" "Keep-Alive"} |
| 1709 | + :body nil} |
| 1710 | + (select-keys @(d/timeout! proxy-request 1000) |
| 1711 | + [:request-method :uri :headers :body])))))))) |
| 1712 | + |
1662 | 1713 | (deftest ^:leak test-leak-in-raw-stream-handler
|
1663 | 1714 | ;; NOTE: Expecting 2 leaks because `with-raw-handler` will run its body for both http1 and
|
1664 | 1715 | ;; http2. It would be nicer to put this assertion into the body but the http1 server seems to
|
|
0 commit comments