File tree Expand file tree Collapse file tree 2 files changed +51
-49
lines changed Expand file tree Collapse file tree 2 files changed +51
-49
lines changed Original file line number Diff line number Diff line change 308
308
309
309
(let [src (if (or (sequential? body') (s/stream? body'))
310
310
(->> body'
311
- s/->source
312
- (s/map (fn [x]
313
- (try
314
- (netty/to-byte-buf x)
315
- (catch Throwable e
316
- (log/error e " error converting " (.getName (class x)) " to ByteBuf" )
317
- (netty/close ch))))))
311
+ s/->source
312
+ (s/map (fn [x]
313
+ (try
314
+ (netty/to-byte-buf x)
315
+ (catch Throwable e
316
+ (log/error e " error converting " (.getName (class x)) " to ByteBuf" )
317
+ (netty/close ch))))))
318
318
(netty/to-byte-buf-stream body' 8192 ))
319
319
320
- sink (netty/sink ch false #(DefaultHttpContent. %))]
320
+ sink (netty/sink ch false #(DefaultHttpContent. %))
321
+
322
+ ; ; mustn't close over body' if NOT a stream, can hold on to data too long when conns are keep-alive
323
+ ch-close-handler (if (s/stream? body')
324
+ #(s/close! body')
325
+ #(s/close! src))]
321
326
322
327
(s/connect src sink)
323
328
324
329
(-> ch
325
- netty/channel
326
- .closeFuture
327
- netty/wrap-future
328
- (d/chain' (fn [_] (if (s/stream? body')
329
- (s/close! body')
330
- (s/close! src)))))
330
+ netty/channel
331
+ .closeFuture
332
+ netty/wrap-future
333
+ (d/chain' (fn [_] (ch-close-handler ))))
331
334
332
335
(let [d (d/deferred )]
333
336
(s/on-closed sink
334
- (fn []
335
-
336
- (when (instance? Closeable body)
337
- (.close ^Closeable body))
337
+ (fn []
338
+ (when (instance? Closeable body)
339
+ (.close ^Closeable body))
338
340
339
- (.execute (-> ch aleph.netty/channel .eventLoop)
340
- #(d/success! d
341
- (netty/write-and-flush ch empty-last-content)))))
341
+ (.execute (-> ch aleph.netty/channel .eventLoop)
342
+ #(d/success! d
343
+ (netty/write-and-flush ch empty-last-content)))))
342
344
d))
343
345
344
346
(netty/write-and-flush ch empty-last-content)))
496
498
handle-cleanup
497
499
(fn [ch f]
498
500
(-> f
499
- (d/chain'
500
- (fn [^ChannelFuture f]
501
- (if f
502
- (.addListener f ChannelFutureListener/CLOSE)
503
- (netty/close ch))))
504
- (d/catch' (fn [_]))))]
501
+ (d/chain'
502
+ (fn [^ChannelFuture f]
503
+ (if f
504
+ (.addListener f ChannelFutureListener/CLOSE)
505
+ (netty/close ch))))
506
+ (d/catch' (fn [_]))))]
505
507
506
508
(defn send-message
507
509
[ch keep-alive? ssl? ^HttpMessage msg body]
Original file line number Diff line number Diff line change 185
185
(error-response e))))]
186
186
187
187
(-> previous-response
188
- (d/chain'
189
- netty/wrap-future
190
- (fn [_]
191
- (netty/release req)
192
- (-> rsp
193
- (d/catch' error-response)
194
- (d/chain'
195
- (fn [rsp]
196
- (when (not (-> req' ^AtomicBoolean (.websocket? ) .get))
197
- (send-response ctx keep-alive? ssl?
198
- (cond
199
-
200
- (map? rsp)
201
- (if head?
202
- (assoc rsp :body :aleph/omitted )
203
- rsp)
204
-
205
- (nil? rsp)
206
- {:status 204 }
207
-
208
- :else
209
- (invalid-value-response req rsp))))))))))))
188
+ (d/chain'
189
+ netty/wrap-future
190
+ (fn [_]
191
+ (netty/release req)
192
+ (-> rsp
193
+ (d/catch' error-response)
194
+ (d/chain'
195
+ (fn [rsp]
196
+ (when (not (-> req' ^AtomicBoolean (.websocket? ) .get))
197
+ (send-response ctx keep-alive? ssl?
198
+ (cond
199
+
200
+ (map? rsp)
201
+ (if head?
202
+ (assoc rsp :body :aleph/omitted )
203
+ rsp)
204
+
205
+ (nil? rsp)
206
+ {:status 204 }
207
+
208
+ :else
209
+ (invalid-value-response req rsp))))))))))))
210
210
211
211
(defn exception-handler [ctx ex]
212
212
(when-not (instance? IOException ex)
You can’t perform that action at this time.
0 commit comments