| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 bool CanFindEndOfResponse() const; | 68 bool CanFindEndOfResponse() const; |
| 69 | 69 |
| 70 bool IsMoreDataBuffered() const; | 70 bool IsMoreDataBuffered() const; |
| 71 | 71 |
| 72 bool IsConnectionReused() const; | 72 bool IsConnectionReused() const; |
| 73 | 73 |
| 74 void SetConnectionReused(); | 74 void SetConnectionReused(); |
| 75 | 75 |
| 76 bool IsConnectionReusable() const; | 76 bool IsConnectionReusable() const; |
| 77 | 77 |
| 78 void SetRestartInfo(int64 read_offset, const void* hash, size_t hash_length); |
| 79 |
| 80 void GetHash(void* output, size_t hash_length); |
| 81 |
| 82 int64 GetReceivedBodyLength() const { return response_body_read_; } |
| 83 |
| 78 int64 received_bytes() const { return received_bytes_; } | 84 int64 received_bytes() const { return received_bytes_; } |
| 79 | 85 |
| 80 void GetSSLInfo(SSLInfo* ssl_info); | 86 void GetSSLInfo(SSLInfo* ssl_info); |
| 81 | 87 |
| 82 void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info); | 88 void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info); |
| 83 | 89 |
| 84 // Encodes the given |payload| in the chunked format to |output|. | 90 // Encodes the given |payload| in the chunked format to |output|. |
| 85 // Returns the number of bytes written to |output|. |output_size| should | 91 // Returns the number of bytes written to |output|. |output_size| should |
| 86 // be large enough to store the encoded chunk, which is payload.size() + | 92 // be large enough to store the encoded chunk, which is payload.size() + |
| 87 // kChunkHeaderFooterSize. Returns ERR_INVALID_ARGUMENT if |output_size| | 93 // kChunkHeaderFooterSize. Returns ERR_INVALID_ARGUMENT if |output_size| |
| 88 // is not large enough. | 94 // is not large enough. |
| 89 // | 95 // |
| 90 // The output will look like: "HEX\r\n[payload]\r\n" | 96 // The output will look like: "HEX\r\n[payload]\r\n" |
| 91 // where HEX is a length in hexdecimal (without the "0x" prefix). | 97 // where HEX is a length in hexdecimal (without the "0x" prefix). |
| 92 static int EncodeChunk(const base::StringPiece& payload, | 98 static int EncodeChunk(const base::StringPiece& payload, |
| 93 char* output, | 99 char* output, |
| 94 size_t output_size); | 100 size_t output_size); |
| 95 | 101 |
| 96 // Returns true if request headers and body should be merged (i.e. the | 102 // Returns true if request headers and body should be merged (i.e. the |
| 97 // sum is small enough and the body is in memory, and not chunked). | 103 // sum is small enough and the body is in memory, and not chunked). |
| 98 static bool ShouldMergeRequestHeadersAndBody( | 104 static bool ShouldMergeRequestHeadersAndBody( |
| 99 const std::string& request_headers, | 105 const std::string& request_headers, |
| 100 const UploadDataStream* request_body); | 106 const UploadDataStream* request_body); |
| 101 | 107 |
| 102 // The number of extra bytes required to encode a chunk. | 108 // The number of extra bytes required to encode a chunk. |
| 103 static const size_t kChunkHeaderFooterSize; | 109 static const size_t kChunkHeaderFooterSize; |
| 104 | 110 |
| 105 private: | 111 private: |
| 106 class SeekableIOBuffer; | 112 class SeekableIOBuffer; |
| 113 class HttpStreamHash; |
| 107 | 114 |
| 108 // FOO_COMPLETE states implement the second half of potentially asynchronous | 115 // FOO_COMPLETE states implement the second half of potentially asynchronous |
| 109 // operations and don't necessarily mean that FOO is complete. | 116 // operations and don't necessarily mean that FOO is complete. |
| 110 enum State { | 117 enum State { |
| 111 // STATE_NONE indicates that this is waiting on an external call before | 118 // STATE_NONE indicates that this is waiting on an external call before |
| 112 // continuing. | 119 // continuing. |
| 113 STATE_NONE, | 120 STATE_NONE, |
| 114 STATE_SEND_HEADERS, | 121 STATE_SEND_HEADERS, |
| 115 STATE_SEND_HEADERS_COMPLETE, | 122 STATE_SEND_HEADERS_COMPLETE, |
| 116 STATE_SEND_BODY, | 123 STATE_SEND_BODY, |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 // cannot be safely accessed after reading the final set of headers, as the | 209 // cannot be safely accessed after reading the final set of headers, as the |
| 203 // caller of SendRequest may have been destroyed - this happens in the case an | 210 // caller of SendRequest may have been destroyed - this happens in the case an |
| 204 // HttpResponseBodyDrainer is used. | 211 // HttpResponseBodyDrainer is used. |
| 205 HttpResponseInfo* response_; | 212 HttpResponseInfo* response_; |
| 206 | 213 |
| 207 // Indicates the content length. If this value is less than zero | 214 // Indicates the content length. If this value is less than zero |
| 208 // (and chunked_decoder_ is null), then we must read until the server | 215 // (and chunked_decoder_ is null), then we must read until the server |
| 209 // closes the connection. | 216 // closes the connection. |
| 210 int64 response_body_length_; | 217 int64 response_body_length_; |
| 211 | 218 |
| 219 // Indicates the amount of body data that should be skipped when reading from |
| 220 // a retried request we have already read data from. |
| 221 int64 read_offset_; |
| 222 |
| 223 // Hash of content as it is retrieved. |
| 224 scoped_ptr<HttpStreamHash> stream_hash_; |
| 225 |
| 212 // Keep track of the number of response body bytes read so far. | 226 // Keep track of the number of response body bytes read so far. |
| 213 int64 response_body_read_; | 227 int64 response_body_read_; |
| 214 | 228 |
| 215 // Helper if the data is chunked. | 229 // Helper if the data is chunked. |
| 216 scoped_ptr<HttpChunkedDecoder> chunked_decoder_; | 230 scoped_ptr<HttpChunkedDecoder> chunked_decoder_; |
| 217 | 231 |
| 218 // Where the caller wants the body data. | 232 // Where the caller wants the body data. |
| 219 scoped_refptr<IOBuffer> user_read_buf_; | 233 scoped_refptr<IOBuffer> user_read_buf_; |
| 220 int user_read_buf_len_; | 234 int user_read_buf_len_; |
| 221 | 235 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 248 int upload_error_; | 262 int upload_error_; |
| 249 | 263 |
| 250 base::WeakPtrFactory<HttpStreamParser> weak_ptr_factory_; | 264 base::WeakPtrFactory<HttpStreamParser> weak_ptr_factory_; |
| 251 | 265 |
| 252 DISALLOW_COPY_AND_ASSIGN(HttpStreamParser); | 266 DISALLOW_COPY_AND_ASSIGN(HttpStreamParser); |
| 253 }; | 267 }; |
| 254 | 268 |
| 255 } // namespace net | 269 } // namespace net |
| 256 | 270 |
| 257 #endif // NET_HTTP_HTTP_STREAM_PARSER_H_ | 271 #endif // NET_HTTP_HTTP_STREAM_PARSER_H_ |
| OLD | NEW |