diff options
author | satorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-19 07:09:29 +0000 |
---|---|---|
committer | satorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-19 07:09:29 +0000 |
commit | e44723427b1fc75475a01cbca84fc987c95e7a6b (patch) | |
tree | 807b20bfcd7ab683f380a6bf05898893b90f4292 /net/http/http_stream_parser.h | |
parent | 3c0edf1d82131458b0aa7c5115a53e62a6421f21 (diff) | |
download | chromium_src-e44723427b1fc75475a01cbca84fc987c95e7a6b.zip chromium_src-e44723427b1fc75475a01cbca84fc987c95e7a6b.tar.gz chromium_src-e44723427b1fc75475a01cbca84fc987c95e7a6b.tar.bz2 |
Factor out chunk encoding logic into HttpStreamParser::EncodeChunk().
The logic is meaty enough to be factored out.
Add unit tests along the way.
BUG=72001
TEST=add unit tests.
Review URL: http://codereview.chromium.org/9242018
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@118265 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/http/http_stream_parser.h')
-rw-r--r-- | net/http/http_stream_parser.h | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/net/http/http_stream_parser.h b/net/http/http_stream_parser.h index ae9fc3e..efb41a0 100644 --- a/net/http/http_stream_parser.h +++ b/net/http/http_stream_parser.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -9,7 +9,9 @@ #include <string> #include "base/basictypes.h" +#include "base/string_piece.h" #include "net/base/completion_callback.h" +#include "net/base/net_export.h" #include "net/base/net_log.h" #include "net/base/upload_data_stream.h" #include "net/http/http_chunked_decoder.h" @@ -26,7 +28,7 @@ class IOBuffer; class SSLCertRequestInfo; class SSLInfo; -class HttpStreamParser : public ChunkCallback { +class NET_EXPORT_PRIVATE HttpStreamParser : public ChunkCallback { public: // Any data in |read_buffer| will be used before reading from the socket // and any data left over after parsing the stream will be put into @@ -77,6 +79,21 @@ class HttpStreamParser : public ChunkCallback { // ChunkCallback methods. virtual void OnChunkAvailable() OVERRIDE; + // Encodes the given |payload| in the chunked format to |output|. + // Returns the number of bytes written to |output|. |output_size| should + // be large enough to store the encoded chunk, which is payload.size() + + // kChunkHeaderFooterSize. Returns ERR_INVALID_ARGUMENT if |output_size| + // is not large enough. + // + // The output will look like: "HEX\r\n[payload]\r\n" + // where HEX is a length in hexdecimal (without the "0x" prefix). + static int EncodeChunk(const base::StringPiece& payload, + char* output, + size_t output_size); + + // The number of extra bytes required to encode a chunk. + static const size_t kChunkHeaderFooterSize; + private: // FOO_COMPLETE states implement the second half of potentially asynchronous // operations and don't necessarily mean that FOO is complete. |