|
38 | 38 | TooLongFrameException]
|
39 | 39 | [io.netty.handler.codec.http
|
40 | 40 | DefaultFullHttpResponse
|
| 41 | + FullHttpRequest |
41 | 42 | HttpContent HttpHeaders HttpUtil
|
42 | 43 | HttpContentCompressor
|
43 | 44 | HttpRequest HttpResponse
|
|
278 | 279 | (handle-request ctx req s))
|
279 | 280 | (reset! request req)))
|
280 | 281 |
|
| 282 | + process-full-request |
| 283 | + (fn [ctx ^FullHttpRequest req] |
| 284 | + ;; HttpObjectAggregator disables chunked encoding, no need to check for it. |
| 285 | + (let [content (.content req) |
| 286 | + body (when (pos? (.readableBytes content)) |
| 287 | + (netty/buf->array content))] |
| 288 | + ;; Don't release content as it will happen automatically once whole |
| 289 | + ;; request is released. |
| 290 | + (handle-request ctx req body))) |
| 291 | + |
281 | 292 | process-last-content
|
282 | 293 | (fn [ctx ^HttpContent msg]
|
283 | 294 | (let [content (.content msg)]
|
|
356 | 367 | ([_ ctx msg]
|
357 | 368 | (cond
|
358 | 369 |
|
| 370 | + ;; Happens when io.netty.handler.codec.http.HttpObjectAggregator is part of the pipeline. |
| 371 | + (instance? FullHttpRequest msg) |
| 372 | + (if (invalid-request? msg) |
| 373 | + (reject-invalid-request ctx msg) |
| 374 | + (process-full-request ctx msg)) |
| 375 | + |
359 | 376 | (instance? HttpRequest msg)
|
360 | 377 | (if (invalid-request? msg)
|
361 | 378 | (reject-invalid-request ctx msg)
|
|
404 | 421 | ([_ ctx msg]
|
405 | 422 | (cond
|
406 | 423 |
|
| 424 | + ;; Happens when io.netty.handler.codec.http.HttpObjectAggregator is part of the pipeline. |
| 425 | + (instance? FullHttpRequest msg) |
| 426 | + (if (invalid-request? msg) |
| 427 | + (reject-invalid-request ctx msg) |
| 428 | + (let [^FullHttpRequest req msg |
| 429 | + content (.content req) |
| 430 | + ch (netty/channel ctx) |
| 431 | + s (netty/source ch)] |
| 432 | + (when-not (zero? (.readableBytes content)) |
| 433 | + ;; Retain the content of FullHttpRequest one extra time to |
| 434 | + ;; compensate for it being released together with the request. |
| 435 | + (netty/put! ch s (netty/acquire content))) |
| 436 | + (s/close! s) |
| 437 | + (handle-request ctx req s))) |
| 438 | + |
407 | 439 | (instance? HttpRequest msg)
|
408 | 440 | (if (invalid-request? msg)
|
409 | 441 | (reject-invalid-request ctx msg)
|
|
0 commit comments