From 68ae08548626cae7d4ec525a2e1d0f9f9c5422b2 Mon Sep 17 00:00:00 2001 From: Patrick McManus Date: Thu, 19 Jun 2014 23:42:29 -0400 Subject: [PATCH] bug 1027364 - multiple http/2 header frames on same stream r=hurley --- netwerk/protocol/http/Http2Session.cpp | 20 ++++++++++++++++++-- netwerk/test/unit/test_http2.js | 9 +++++++++ testing/xpcshell/moz-http2/moz-http2.js | 9 +++++++++ 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/netwerk/protocol/http/Http2Session.cpp b/netwerk/protocol/http/Http2Session.cpp index 5a9329b4d55b..dce10e886566 100644 --- a/netwerk/protocol/http/Http2Session.cpp +++ b/netwerk/protocol/http/Http2Session.cpp @@ -1159,9 +1159,25 @@ Http2Session::ResponseHeadersComplete() LOG3(("Http2Session::ResponseHeadersComplete %p for 0x%X fin=%d", this, mInputFrameDataStream->StreamID(), mInputFrameFinal)); - // only do this once, afterwards ignore trailers - if (mInputFrameDataStream->AllHeadersReceived()) + // only interpret headers once, afterwards ignore trailers + if (mInputFrameDataStream->AllHeadersReceived()) { + LOG3(("Http2Session::ResponseHeadersComplete extra headers")); + nsresult rv = UncompressAndDiscard(); + if (NS_FAILED(rv)) { + LOG3(("Http2Session::ResponseHeadersComplete extra uncompress failed\n")); + return rv; + } + mFlatHTTPResponseHeadersOut = 0; + mFlatHTTPResponseHeaders.Truncate(); + if (mInputFrameFinal) { + // need to process the fin + ChangeDownstreamState(PROCESSING_COMPLETE_HEADERS); + } else { + ResetDownstreamState(); + } + return NS_OK; + } mInputFrameDataStream->SetAllHeadersReceived(); // The stream needs to see flattened http headers diff --git a/netwerk/test/unit/test_http2.js b/netwerk/test/unit/test_http2.js index d3d609d4fe67..5a7ab7208bf2 100644 --- a/netwerk/test/unit/test_http2.js +++ b/netwerk/test/unit/test_http2.js @@ -292,6 +292,14 @@ function test_http2_push4() { chan.asyncOpen(listener, chan); } +// this is a basic test where the server sends a simple document with 2 header +// blocks. bug 1027364 +function test_http2_doubleheader() { + var chan = makeChan("https://localhost:6944/doubleheader"); + var listener = new Http2CheckListener(); + chan.asyncOpen(listener, null); +} + // Make sure we handle GETs that cover more than 2 frames properly function test_http2_big() { var chan = makeChan("https://localhost:6944/big"); @@ -338,6 +346,7 @@ var tests = [ test_http2_post_big , test_http2_push2 , test_http2_push3 , test_http2_push4 + , test_http2_doubleheader , test_http2_xhr , test_http2_header , test_http2_cookie_crumbling diff --git a/testing/xpcshell/moz-http2/moz-http2.js b/testing/xpcshell/moz-http2/moz-http2.js index 5364452558b1..c817d2f220b4 100644 --- a/testing/xpcshell/moz-http2/moz-http2.js +++ b/testing/xpcshell/moz-http2/moz-http2.js @@ -114,6 +114,15 @@ function handleRequest(req, res) { } } + else if (u.pathname === "/doubleheader") { + res.setHeader('Content-Type', 'text/html'); + res.writeHead(200); + res.write(content); + res.writeHead(200); + res.end(); + return; + } + else if (u.pathname === "/cookie_crumbling") { res.setHeader("X-Received-Header-Pairs", JSON.stringify(decompressedPairs)); }