| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef NET_HTTP_HTTP_STREAM_PARSER_H_ | 5 #ifndef NET_HTTP_HTTP_STREAM_PARSER_H_ |
| 6 #define NET_HTTP_HTTP_STREAM_PARSER_H_ | 6 #define NET_HTTP_HTTP_STREAM_PARSER_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/string_piece.h" |
| 12 #include "net/base/completion_callback.h" | 13 #include "net/base/completion_callback.h" |
| 14 #include "net/base/net_export.h" |
| 13 #include "net/base/net_log.h" | 15 #include "net/base/net_log.h" |
| 14 #include "net/base/upload_data_stream.h" | 16 #include "net/base/upload_data_stream.h" |
| 15 #include "net/http/http_chunked_decoder.h" | 17 #include "net/http/http_chunked_decoder.h" |
| 16 | 18 |
| 17 namespace net { | 19 namespace net { |
| 18 | 20 |
| 19 class ClientSocketHandle; | 21 class ClientSocketHandle; |
| 20 class DrainableIOBuffer; | 22 class DrainableIOBuffer; |
| 21 class GrowableIOBuffer; | 23 class GrowableIOBuffer; |
| 22 struct HttpRequestInfo; | 24 struct HttpRequestInfo; |
| 23 class HttpRequestHeaders; | 25 class HttpRequestHeaders; |
| 24 class HttpResponseInfo; | 26 class HttpResponseInfo; |
| 25 class IOBuffer; | 27 class IOBuffer; |
| 26 class SSLCertRequestInfo; | 28 class SSLCertRequestInfo; |
| 27 class SSLInfo; | 29 class SSLInfo; |
| 28 | 30 |
| 29 class HttpStreamParser : public ChunkCallback { | 31 class NET_EXPORT_PRIVATE HttpStreamParser : public ChunkCallback { |
| 30 public: | 32 public: |
| 31 // Any data in |read_buffer| will be used before reading from the socket | 33 // Any data in |read_buffer| will be used before reading from the socket |
| 32 // and any data left over after parsing the stream will be put into | 34 // and any data left over after parsing the stream will be put into |
| 33 // |read_buffer|. The left over data will start at offset 0 and the | 35 // |read_buffer|. The left over data will start at offset 0 and the |
| 34 // buffer's offset will be set to the first free byte. |read_buffer| may | 36 // buffer's offset will be set to the first free byte. |read_buffer| may |
| 35 // have its capacity changed. | 37 // have its capacity changed. |
| 36 HttpStreamParser(ClientSocketHandle* connection, | 38 HttpStreamParser(ClientSocketHandle* connection, |
| 37 const HttpRequestInfo* request, | 39 const HttpRequestInfo* request, |
| 38 GrowableIOBuffer* read_buffer, | 40 GrowableIOBuffer* read_buffer, |
| 39 const BoundNetLog& net_log); | 41 const BoundNetLog& net_log); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 70 | 72 |
| 71 bool IsConnectionReusable() const; | 73 bool IsConnectionReusable() const; |
| 72 | 74 |
| 73 void GetSSLInfo(SSLInfo* ssl_info); | 75 void GetSSLInfo(SSLInfo* ssl_info); |
| 74 | 76 |
| 75 void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info); | 77 void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info); |
| 76 | 78 |
| 77 // ChunkCallback methods. | 79 // ChunkCallback methods. |
| 78 virtual void OnChunkAvailable() OVERRIDE; | 80 virtual void OnChunkAvailable() OVERRIDE; |
| 79 | 81 |
| 82 // Encodes the given |payload| in the chunked format to |output|. |
| 83 // Returns the number of bytes written to |output|. |output_size| should |
| 84 // be large enough to store the encoded chunk, which is payload.size() + |
| 85 // kChunkHeaderFooterSize. Returns ERR_INVALID_ARGUMENT if |output_size| |
| 86 // is not large enough. |
| 87 // |
| 88 // The output will look like: "HEX\r\n[payload]\r\n" |
| 89 // where HEX is a length in hexdecimal (without the "0x" prefix). |
| 90 static int EncodeChunk(const base::StringPiece& payload, |
| 91 char* output, |
| 92 size_t output_size); |
| 93 |
| 94 // The number of extra bytes required to encode a chunk. |
| 95 static const size_t kChunkHeaderFooterSize; |
| 96 |
| 80 private: | 97 private: |
| 81 // FOO_COMPLETE states implement the second half of potentially asynchronous | 98 // FOO_COMPLETE states implement the second half of potentially asynchronous |
| 82 // operations and don't necessarily mean that FOO is complete. | 99 // operations and don't necessarily mean that FOO is complete. |
| 83 enum State { | 100 enum State { |
| 84 STATE_NONE, | 101 STATE_NONE, |
| 85 STATE_SENDING_HEADERS, | 102 STATE_SENDING_HEADERS, |
| 86 STATE_SENDING_BODY, | 103 STATE_SENDING_BODY, |
| 87 STATE_REQUEST_SENT, | 104 STATE_REQUEST_SENT, |
| 88 STATE_READ_HEADERS, | 105 STATE_READ_HEADERS, |
| 89 STATE_READ_HEADERS_COMPLETE, | 106 STATE_READ_HEADERS_COMPLETE, |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 size_t chunk_length_; | 215 size_t chunk_length_; |
| 199 size_t chunk_length_without_encoding_; | 216 size_t chunk_length_without_encoding_; |
| 200 bool sent_last_chunk_; | 217 bool sent_last_chunk_; |
| 201 | 218 |
| 202 DISALLOW_COPY_AND_ASSIGN(HttpStreamParser); | 219 DISALLOW_COPY_AND_ASSIGN(HttpStreamParser); |
| 203 }; | 220 }; |
| 204 | 221 |
| 205 } // namespace net | 222 } // namespace net |
| 206 | 223 |
| 207 #endif // NET_HTTP_HTTP_STREAM_PARSER_H_ | 224 #endif // NET_HTTP_HTTP_STREAM_PARSER_H_ |
| OLD | NEW |