Skip to content

Commit 0b3d548

Browse files
committed
Add HTTP client proxy test
1 parent 5006055 commit 0b3d548

File tree

1 file changed

+52
-1
lines changed

1 file changed

+52
-1
lines changed

test/aleph/http_test.clj

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@
3838
StandardCompressionOptions)
3939
(io.netty.handler.codec.http
4040
HttpMessage
41-
HttpObjectAggregator)
41+
HttpObjectAggregator
42+
HttpRequestDecoder
43+
LastHttpContent)
4244
(io.netty.handler.codec.http2 Http2HeadersFrame)
4345
(java.io
4446
Closeable
@@ -1659,6 +1661,55 @@
16591661
(is (= true (deref conn-closed 1000 :timeout)))
16601662
(is (thrown? RequestCancellationException (deref rsp 1000 :timeout)))))))
16611663

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+
16621713
(deftest ^:leak test-leak-in-raw-stream-handler
16631714
;; NOTE: Expecting 2 leaks because `with-raw-handler` will run its body for both http1 and
16641715
;; http2. It would be nicer to put this assertion into the body but the http1 server seems to

0 commit comments

Comments
 (0)