Skip to content

Commit 8ccf420

Browse files
committed
Add a test of pipeline-transform functionality
Inspired by work for #584
1 parent f124759 commit 8ccf420

File tree

1 file changed

+42
-14
lines changed

1 file changed

+42
-14
lines changed

test/aleph/http_test.clj

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
(:use
33
[clojure test])
44
(:require
5-
[clojure.java.io :as io]
65
[aleph
76
[http :as http]
87
[netty :as netty]
@@ -11,19 +10,23 @@
1110
[manifold.deferred :as d]
1211
[manifold.stream :as s])
1312
(:import
14-
[java.util.concurrent
15-
Executors]
16-
[java.io
17-
File
18-
ByteArrayInputStream]
19-
[java.util.zip
20-
GZIPInputStream
21-
ZipException]
22-
[java.util.concurrent
23-
TimeoutException]
24-
[aleph.utils
25-
ConnectionTimeoutException
26-
RequestTimeoutException]))
13+
(java.io
14+
File)
15+
(java.util.zip
16+
GZIPInputStream
17+
ZipException)
18+
(java.util.concurrent
19+
TimeoutException)
20+
(aleph.utils
21+
ConnectionTimeoutException
22+
RequestTimeoutException)
23+
(io.netty.channel
24+
ChannelHandlerContext
25+
ChannelOutboundHandlerAdapter
26+
ChannelPipeline
27+
ChannelPromise)
28+
(io.netty.handler.codec.http
29+
HttpMessage)))
2730

2831
;;;
2932

@@ -450,3 +453,28 @@
450453
(Thread/sleep (* 1000 60))
451454
(println "stopping server")
452455
(.close ^java.io.Closeable server)))
456+
457+
458+
(deftest test-pipeline-header-alteration
459+
(let [test-header-name "aleph-test"
460+
test-header-val "MOOP"]
461+
(with-server (http/start-server
462+
basic-handler
463+
{:port port
464+
:pipeline-transform
465+
(fn [^ChannelPipeline pipeline]
466+
(.addBefore pipeline
467+
"request-handler"
468+
"test-header-inserter"
469+
(proxy [ChannelOutboundHandlerAdapter] []
470+
(write [^ChannelHandlerContext ctx
471+
^Object msg
472+
^ChannelPromise p]
473+
(when (instance? HttpMessage msg)
474+
(let [^HttpMessage http-msg msg]
475+
(-> http-msg
476+
(.headers)
477+
(.set test-header-name test-header-val))))
478+
(.write ctx msg p)))))})
479+
(let [resp @(http-get (str "http://localhost:" port "/string"))]
480+
(is (= test-header-val (get (:headers resp) test-header-name)))))))

0 commit comments

Comments
 (0)