summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorvandebo@chromium.org <vandebo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-13 17:33:09 +0000
committervandebo@chromium.org <vandebo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-13 17:33:09 +0000
commite1a96026a9403bfaa3c6efe120391261e5e795f4 (patch)
treebd97e3470f8d481e4464dcf5024ad311d2db707d /net
parent8133c680452262815566bd8ba6c9b80ca8428780 (diff)
downloadchromium_src-e1a96026a9403bfaa3c6efe120391261e5e795f4.zip
chromium_src-e1a96026a9403bfaa3c6efe120391261e5e795f4.tar.gz
chromium_src-e1a96026a9403bfaa3c6efe120391261e5e795f4.tar.bz2
Add an interface to report the amount of data after a chunked encoding. This will be needed for pipelining. Separated out of http://codereview.chromium.org/249031.
BUG=13289 TEST=existing and added unittests Review URL: http://codereview.chromium.org/267042 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@28833 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r--net/http/http_chunked_decoder.cc4
-rw-r--r--net/http/http_chunked_decoder.h7
-rw-r--r--net/http/http_chunked_decoder_unittest.cc58
3 files changed, 56 insertions, 13 deletions
diff --git a/net/http/http_chunked_decoder.cc b/net/http/http_chunked_decoder.cc
index 25b789f..619c9a1 100644
--- a/net/http/http_chunked_decoder.cc
+++ b/net/http/http_chunked_decoder.cc
@@ -51,7 +51,8 @@ HttpChunkedDecoder::HttpChunkedDecoder()
: chunk_remaining_(0),
chunk_terminator_remaining_(false),
reached_last_chunk_(false),
- reached_eof_(false) {
+ reached_eof_(false),
+ bytes_after_eof_(0) {
}
int HttpChunkedDecoder::FilterBuf(char* buf, int buf_len) {
@@ -72,6 +73,7 @@ int HttpChunkedDecoder::FilterBuf(char* buf, int buf_len) {
chunk_terminator_remaining_ = true;
continue;
} else if (reached_eof_) {
+ bytes_after_eof_ += buf_len;
break; // Done!
}
diff --git a/net/http/http_chunked_decoder.h b/net/http/http_chunked_decoder.h
index f87ae5e..174dddc 100644
--- a/net/http/http_chunked_decoder.h
+++ b/net/http/http_chunked_decoder.h
@@ -76,6 +76,9 @@ class HttpChunkedDecoder {
// Indicates that a previous call to FilterBuf encountered the final CRLF.
bool reached_eof() const { return reached_eof_; }
+ // Returns the number of bytes after the final CRLF.
+ int bytes_after_eof() const { return bytes_after_eof_; }
+
// Called to filter out the chunk markers from buf and to check for end-of-
// file. This method modifies |buf| inline if necessary to remove chunk
// markers. The return value indicates the final size of decoded data stored
@@ -108,6 +111,10 @@ class HttpChunkedDecoder {
// Set to true when FilterBuf encounters the final CRLF.
bool reached_eof_;
+
+ // The number of unfiltered bytes after the final CRLF, either extraneous
+ // data or the first part of the next response in a pipelined stream.
+ int bytes_after_eof_;
};
} // namespace net
diff --git a/net/http/http_chunked_decoder_unittest.cc b/net/http/http_chunked_decoder_unittest.cc
index f335f0a..881ae0b 100644
--- a/net/http/http_chunked_decoder_unittest.cc
+++ b/net/http/http_chunked_decoder_unittest.cc
@@ -13,7 +13,8 @@ typedef testing::Test HttpChunkedDecoderTest;
void RunTest(const char* inputs[], size_t num_inputs,
const char* expected_output,
- bool expected_eof) {
+ bool expected_eof,
+ int bytes_after_eof) {
net::HttpChunkedDecoder decoder;
EXPECT_FALSE(decoder.reached_eof());
@@ -27,8 +28,9 @@ void RunTest(const char* inputs[], size_t num_inputs,
result.append(input.data(), n);
}
- EXPECT_TRUE(result == expected_output);
- EXPECT_TRUE(decoder.reached_eof() == expected_eof);
+ EXPECT_EQ(expected_output, result);
+ EXPECT_EQ(expected_eof, decoder.reached_eof());
+ EXPECT_EQ(bytes_after_eof, decoder.bytes_after_eof());
}
// Feed the inputs to the decoder, until it returns an error.
@@ -56,14 +58,14 @@ TEST(HttpChunkedDecoderTest, Basic) {
const char* inputs[] = {
"5\r\nhello\r\n0\r\n\r\n"
};
- RunTest(inputs, arraysize(inputs), "hello", true);
+ RunTest(inputs, arraysize(inputs), "hello", true, 0);
}
TEST(HttpChunkedDecoderTest, OneChunk) {
const char* inputs[] = {
"5\r\nhello\r\n"
};
- RunTest(inputs, arraysize(inputs), "hello", false);
+ RunTest(inputs, arraysize(inputs), "hello", false, 0);
}
TEST(HttpChunkedDecoderTest, Typical) {
@@ -73,7 +75,7 @@ TEST(HttpChunkedDecoderTest, Typical) {
"5\r\nworld\r\n",
"0\r\n\r\n"
};
- RunTest(inputs, arraysize(inputs), "hello world", true);
+ RunTest(inputs, arraysize(inputs), "hello world", true, 0);
}
TEST(HttpChunkedDecoderTest, Incremental) {
@@ -90,7 +92,7 @@ TEST(HttpChunkedDecoderTest, Incremental) {
"\r",
"\n"
};
- RunTest(inputs, arraysize(inputs), "hello", true);
+ RunTest(inputs, arraysize(inputs), "hello", true, 0);
}
TEST(HttpChunkedDecoderTest, LF_InsteadOf_CRLF) {
@@ -103,7 +105,7 @@ TEST(HttpChunkedDecoderTest, LF_InsteadOf_CRLF) {
"5\nworld\n",
"0\n\n"
};
- RunTest(inputs, arraysize(inputs), "hello world", true);
+ RunTest(inputs, arraysize(inputs), "hello world", true, 0);
}
TEST(HttpChunkedDecoderTest, Extensions) {
@@ -111,7 +113,7 @@ TEST(HttpChunkedDecoderTest, Extensions) {
"5;x=0\r\nhello\r\n",
"0;y=\"2 \"\r\n\r\n"
};
- RunTest(inputs, arraysize(inputs), "hello", true);
+ RunTest(inputs, arraysize(inputs), "hello", true, 0);
}
TEST(HttpChunkedDecoderTest, Trailers) {
@@ -122,7 +124,7 @@ TEST(HttpChunkedDecoderTest, Trailers) {
"Bar: 2\r\n",
"\r\n"
};
- RunTest(inputs, arraysize(inputs), "hello", true);
+ RunTest(inputs, arraysize(inputs), "hello", true, 0);
}
TEST(HttpChunkedDecoderTest, TrailersUnfinished) {
@@ -131,7 +133,7 @@ TEST(HttpChunkedDecoderTest, TrailersUnfinished) {
"0\r\n",
"Foo: 1\r\n"
};
- RunTest(inputs, arraysize(inputs), "hello", false);
+ RunTest(inputs, arraysize(inputs), "hello", false, 0);
}
TEST(HttpChunkedDecoderTest, InvalidChunkSize_TooBig) {
@@ -165,7 +167,7 @@ TEST(HttpChunkedDecoderTest, ChunkSize_TrailingSpace) {
"5 \r\nhello\r\n",
"0\r\n\r\n"
};
- RunTest(inputs, arraysize(inputs), "hello", true);
+ RunTest(inputs, arraysize(inputs), "hello", true, 0);
}
TEST(HttpChunkedDecoderTest, InvalidChunkSize_TrailingTab) {
@@ -273,3 +275,35 @@ TEST(HttpChunkedDecoderTest, ExcessiveChunkLen) {
};
RunTestUntilFailure(inputs, arraysize(inputs), 0);
}
+
+TEST(HttpChunkedDecoderTest, BasicExtraData) {
+ const char* inputs[] = {
+ "5\r\nhello\r\n0\r\n\r\nextra bytes"
+ };
+ RunTest(inputs, arraysize(inputs), "hello", true, 11);
+}
+
+TEST(HttpChunkedDecoderTest, IncrementalExtraData) {
+ const char* inputs[] = {
+ "5",
+ "\r",
+ "\n",
+ "hello",
+ "\r",
+ "\n",
+ "0",
+ "\r",
+ "\n",
+ "\r",
+ "\nextra bytes"
+ };
+ RunTest(inputs, arraysize(inputs), "hello", true, 11);
+}
+
+TEST(HttpChunkedDecoderTest, MultipleExtraDataBlocks) {
+ const char* inputs[] = {
+ "5\r\nhello\r\n0\r\n\r\nextra",
+ " bytes"
+ };
+ RunTest(inputs, arraysize(inputs), "hello", true, 11);
+}