Skip to content

Commit c833381

Browse files
rborerztellman
authored andcommitted
Modify client/client-handler to support HttpObjectAggregator (#393)
HttpObjectAggregator modifies the response to aggregate all HttpMessage(s) up to a maximum length (it throws a TooLongFrameException if the length exceed the limit). When this handler is part of the pipeline, the channel receives an instance of FullHttpResponse with the whole aggregated response.
1 parent 0aef199 commit c833381

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

src/aleph/http/client.clj

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,12 @@
3333
Channel
3434
ChannelHandler ChannelHandlerContext
3535
ChannelPipeline]
36-
[io.netty.handler.stream ChunkedWriteHandler]
37-
[io.netty.handler.codec.http FullHttpRequest]
36+
[io.netty.handler.codec
37+
TooLongFrameException]
38+
[io.netty.handler.stream
39+
ChunkedWriteHandler]
40+
[io.netty.handler.codec.http
41+
FullHttpRequest]
3842
[io.netty.handler.codec.http.websocketx
3943
CloseWebSocketFrame
4044
PingWebSocketFrame
@@ -159,7 +163,13 @@
159163

160164
:exception-caught
161165
([_ ctx ex]
162-
(when-not (instance? IOException ex)
166+
(cond
167+
; could happens when io.netty.handler.codec.http.HttpObjectAggregator
168+
; is part of the pipeline
169+
(instance? TooLongFrameException ex)
170+
(s/put! response-stream ex)
171+
172+
(not (instance? IOException ex))
163173
(log/warn ex "error in HTTP client")))
164174

165175
:channel-inactive
@@ -176,6 +186,18 @@
176186

177187
(cond
178188

189+
; happens when io.netty.handler.codec.http.HttpObjectAggregator is part of the pipeline
190+
(instance? FullHttpResponse msg)
191+
(let [^FullHttpResponse rsp msg
192+
content (.content rsp)
193+
c (d/deferred)
194+
s (netty/buffered-source (netty/channel ctx) #(alength ^bytes %) buffer-capacity)]
195+
(s/on-closed s #(d/success! c true))
196+
(s/put! s (netty/buf->array content))
197+
(netty/release content)
198+
(handle-response rsp c s)
199+
(s/close! s))
200+
179201
(instance? HttpResponse msg)
180202
(let [rsp msg]
181203
(if (HttpUtil/isTransferEncodingChunked rsp)

0 commit comments

Comments
 (0)