@@ -140,13 +140,13 @@ protected SpdyHttpDecoder(SpdyVersion version, int maxContentLength, Map<Integer |
140 | 140 | } |
141 | 141 |
|
142 | 142 | @Override |
143 | | - public void channelInactive(ChannelHandlerContext ctx) throws Exception { |
| 143 | + public void handlerRemoved(ChannelHandlerContext ctx) throws Exception { |
144 | 144 | // Release any outstanding messages from the map |
145 | 145 | for (Map.Entry<Integer, FullHttpMessage> entry : messageMap.entrySet()) { |
146 | 146 | ReferenceCountUtil.safeRelease(entry.getValue()); |
147 | 147 | } |
148 | 148 | messageMap.clear(); |
149 | | - super.channelInactive(ctx); |
| 149 | + super.handlerRemoved(ctx); |
150 | 150 | } |
151 | 151 |
|
152 | 152 | protected FullHttpMessage putMessage(int streamId, FullHttpMessage message) { |
@@ -271,21 +271,26 @@ protected void decode(ChannelHandlerContext ctx, SpdyFrame msg, List<Object> out |
271 | 271 | return; |
272 | 272 | } |
273 | 273 |
|
| 274 | + FullHttpResponse httpResponseWithEntity = null; |
274 | 275 | try { |
275 | | - FullHttpResponse httpResponseWithEntity = |
276 | | - createHttpResponse(spdySynReplyFrame, ctx.alloc()); |
| 276 | + httpResponseWithEntity = createHttpResponse(spdySynReplyFrame, ctx.alloc()); |
277 | 277 |
|
278 | 278 | // Set the Stream-ID as a header |
279 | 279 | httpResponseWithEntity.headers().setInt(Names.STREAM_ID, streamId); |
280 | 280 |
|
281 | 281 | if (spdySynReplyFrame.isLast()) { |
282 | 282 | HttpUtil.setContentLength(httpResponseWithEntity, 0); |
283 | 283 | out.add(httpResponseWithEntity); |
| 284 | + httpResponseWithEntity = null; |
284 | 285 | } else { |
285 | 286 | // Response body will follow in a series of Data Frames |
286 | 287 | putMessage(streamId, httpResponseWithEntity); |
| 288 | + httpResponseWithEntity = null; |
287 | 289 | } |
288 | 290 | } catch (Throwable t) { |
| 291 | + if (httpResponseWithEntity != null) { |
| 292 | + httpResponseWithEntity.release(); |
| 293 | + } |
289 | 294 | // If a client receives a SYN_REPLY without valid getStatus and version headers |
290 | 295 | // the client must reply with a RST_STREAM frame indicating a PROTOCOL_ERROR |
291 | 296 | SpdyRstStreamFrame spdyRstStreamFrame = |
@@ -321,11 +326,16 @@ protected void decode(ChannelHandlerContext ctx, SpdyFrame msg, List<Object> out |
321 | 326 | if (spdyHeadersFrame.isLast()) { |
322 | 327 | HttpUtil.setContentLength(fullHttpMessage, 0); |
323 | 328 | out.add(fullHttpMessage); |
| 329 | + fullHttpMessage = null; |
324 | 330 | } else { |
325 | 331 | // Response body will follow in a series of Data Frames |
326 | 332 | putMessage(streamId, fullHttpMessage); |
| 333 | + fullHttpMessage = null; |
327 | 334 | } |
328 | 335 | } catch (Throwable t) { |
| 336 | + if (fullHttpMessage != null) { |
| 337 | + fullHttpMessage.release(); |
| 338 | + } |
329 | 339 | // If a client receives a SYN_REPLY without valid getStatus and version headers |
330 | 340 | // the client must reply with a RST_STREAM frame indicating a PROTOCOL_ERROR |
331 | 341 | SpdyRstStreamFrame spdyRstStreamFrame = |
@@ -345,7 +355,10 @@ protected void decode(ChannelHandlerContext ctx, SpdyFrame msg, List<Object> out |
345 | 355 |
|
346 | 356 | if (spdyHeadersFrame.isLast()) { |
347 | 357 | HttpUtil.setContentLength(fullHttpMessage, fullHttpMessage.content().readableBytes()); |
348 | | - removeMessage(streamId); |
| 358 | + FullHttpMessage removed = removeMessage(streamId); |
| 359 | + if (removed != null && removed != fullHttpMessage) { |
| 360 | + removed.release(); |
| 361 | + } |
349 | 362 | out.add(fullHttpMessage); |
350 | 363 | } |
351 | 364 |
|
@@ -362,7 +375,11 @@ protected void decode(ChannelHandlerContext ctx, SpdyFrame msg, List<Object> out |
362 | 375 |
|
363 | 376 | ByteBuf content = fullHttpMessage.content(); |
364 | 377 | if (content.readableBytes() > maxContentLength - spdyDataFrame.content().readableBytes()) { |
365 | | - removeMessage(streamId); |
| 378 | + FullHttpMessage removed = removeMessage(streamId); |
| 379 | + if (removed != null && removed != fullHttpMessage) { |
| 380 | + removed.release(); |
| 381 | + } |
| 382 | + fullHttpMessage.release(); |
366 | 383 | throw new TooLongFrameException( |
367 | 384 | "HTTP content length exceeded " + maxContentLength + " bytes: " |
368 | 385 | + spdyDataFrame.content().readableBytes()); |
@@ -374,15 +391,21 @@ protected void decode(ChannelHandlerContext ctx, SpdyFrame msg, List<Object> out |
374 | 391 |
|
375 | 392 | if (spdyDataFrame.isLast()) { |
376 | 393 | HttpUtil.setContentLength(fullHttpMessage, content.readableBytes()); |
377 | | - removeMessage(streamId); |
| 394 | + FullHttpMessage removed = removeMessage(streamId); |
| 395 | + if (removed != null && removed != fullHttpMessage) { |
| 396 | + removed.release(); |
| 397 | + } |
378 | 398 | out.add(fullHttpMessage); |
379 | 399 | } |
380 | 400 |
|
381 | 401 | } else if (msg instanceof SpdyRstStreamFrame) { |
382 | 402 |
|
383 | 403 | SpdyRstStreamFrame spdyRstStreamFrame = (SpdyRstStreamFrame) msg; |
384 | 404 | int streamId = spdyRstStreamFrame.streamId(); |
385 | | - removeMessage(streamId); |
| 405 | + FullHttpMessage removed = removeMessage(streamId); |
| 406 | + if (removed != null) { |
| 407 | + removed.release(); |
| 408 | + } |
386 | 409 | } |
387 | 410 | } |
388 | 411 |
|
|