1*6777b538SAndroid Build Coastguard Worker // Copyright 2012 The Chromium Authors 2*6777b538SAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be 3*6777b538SAndroid Build Coastguard Worker // found in the LICENSE file. 4*6777b538SAndroid Build Coastguard Worker 5*6777b538SAndroid Build Coastguard Worker #ifndef NET_HTTP_HTTP_STREAM_PARSER_H_ 6*6777b538SAndroid Build Coastguard Worker #define NET_HTTP_HTTP_STREAM_PARSER_H_ 7*6777b538SAndroid Build Coastguard Worker 8*6777b538SAndroid Build Coastguard Worker #include <stddef.h> 9*6777b538SAndroid Build Coastguard Worker #include <stdint.h> 10*6777b538SAndroid Build Coastguard Worker 11*6777b538SAndroid Build Coastguard Worker #include <memory> 12*6777b538SAndroid Build Coastguard Worker #include <string> 13*6777b538SAndroid Build Coastguard Worker #include <string_view> 14*6777b538SAndroid Build Coastguard Worker 15*6777b538SAndroid Build Coastguard Worker #include "base/memory/raw_ptr.h" 16*6777b538SAndroid Build Coastguard Worker #include "base/memory/scoped_refptr.h" 17*6777b538SAndroid Build Coastguard Worker #include "base/memory/weak_ptr.h" 18*6777b538SAndroid Build Coastguard Worker #include "base/time/time.h" 19*6777b538SAndroid Build Coastguard Worker #include "crypto/ec_private_key.h" 20*6777b538SAndroid Build Coastguard Worker #include "net/base/completion_once_callback.h" 21*6777b538SAndroid Build Coastguard Worker #include "net/base/completion_repeating_callback.h" 22*6777b538SAndroid Build Coastguard Worker #include "net/base/net_errors.h" 23*6777b538SAndroid Build Coastguard Worker #include "net/base/net_export.h" 24*6777b538SAndroid Build Coastguard Worker #include "net/log/net_log_with_source.h" 25*6777b538SAndroid Build Coastguard Worker #include "net/traffic_annotation/network_traffic_annotation.h" 26*6777b538SAndroid Build Coastguard Worker 27*6777b538SAndroid Build Coastguard Worker namespace net { 28*6777b538SAndroid Build Coastguard Worker 29*6777b538SAndroid Build Coastguard Worker class DrainableIOBuffer; 30*6777b538SAndroid Build Coastguard Worker class GrowableIOBuffer; 31*6777b538SAndroid Build Coastguard Worker class HttpChunkedDecoder; 32*6777b538SAndroid Build Coastguard Worker struct HttpRequestInfo; 33*6777b538SAndroid Build Coastguard Worker class HttpRequestHeaders; 34*6777b538SAndroid Build Coastguard Worker class HttpResponseInfo; 35*6777b538SAndroid Build Coastguard Worker class IOBuffer; 36*6777b538SAndroid Build Coastguard Worker class StreamSocket; 37*6777b538SAndroid Build Coastguard Worker class UploadDataStream; 38*6777b538SAndroid Build Coastguard Worker 39*6777b538SAndroid Build Coastguard Worker class NET_EXPORT_PRIVATE HttpStreamParser { 40*6777b538SAndroid Build Coastguard Worker public: 41*6777b538SAndroid Build Coastguard Worker // |connection_is_reused| must be |true| if |stream_socket| has previously 42*6777b538SAndroid Build Coastguard Worker // been used successfully for an HTTP/1.x request. 43*6777b538SAndroid Build Coastguard Worker // 44*6777b538SAndroid Build Coastguard Worker // Any data in |read_buffer| will be used before reading from the socket 45*6777b538SAndroid Build Coastguard Worker // and any data left over after parsing the stream will be put into 46*6777b538SAndroid Build Coastguard Worker // |read_buffer|. The left over data will start at offset 0 and the 47*6777b538SAndroid Build Coastguard Worker // buffer's offset will be set to the first free byte. |read_buffer| may 48*6777b538SAndroid Build Coastguard Worker // have its capacity changed. 49*6777b538SAndroid Build Coastguard Worker // 50*6777b538SAndroid Build Coastguard Worker // It is not safe to call into the HttpStreamParser after destroying the 51*6777b538SAndroid Build Coastguard Worker // |stream_socket|. 52*6777b538SAndroid Build Coastguard Worker HttpStreamParser(StreamSocket* stream_socket, 53*6777b538SAndroid Build Coastguard Worker bool connection_is_reused, 54*6777b538SAndroid Build Coastguard Worker const HttpRequestInfo* request, 55*6777b538SAndroid Build Coastguard Worker GrowableIOBuffer* read_buffer, 56*6777b538SAndroid Build Coastguard Worker const NetLogWithSource& net_log); 57*6777b538SAndroid Build Coastguard Worker 58*6777b538SAndroid Build Coastguard Worker HttpStreamParser(const HttpStreamParser&) = delete; 59*6777b538SAndroid Build Coastguard Worker HttpStreamParser& operator=(const HttpStreamParser&) = delete; 60*6777b538SAndroid Build Coastguard Worker 61*6777b538SAndroid Build Coastguard Worker virtual ~HttpStreamParser(); 62*6777b538SAndroid Build Coastguard Worker 63*6777b538SAndroid Build Coastguard Worker // These functions implement the interface described in HttpStream with 64*6777b538SAndroid Build Coastguard Worker // some additional functionality 65*6777b538SAndroid Build Coastguard Worker int SendRequest(const std::string& request_line, 66*6777b538SAndroid Build Coastguard Worker const HttpRequestHeaders& headers, 67*6777b538SAndroid Build Coastguard Worker const NetworkTrafficAnnotationTag& traffic_annotation, 68*6777b538SAndroid Build Coastguard Worker HttpResponseInfo* response, 69*6777b538SAndroid Build Coastguard Worker CompletionOnceCallback callback); 70*6777b538SAndroid Build Coastguard Worker 71*6777b538SAndroid Build Coastguard Worker int ConfirmHandshake(CompletionOnceCallback callback); 72*6777b538SAndroid Build Coastguard Worker 73*6777b538SAndroid Build Coastguard Worker int ReadResponseHeaders(CompletionOnceCallback callback); 74*6777b538SAndroid Build Coastguard Worker 75*6777b538SAndroid Build Coastguard Worker int ReadResponseBody(IOBuffer* buf, 76*6777b538SAndroid Build Coastguard Worker int buf_len, 77*6777b538SAndroid Build Coastguard Worker CompletionOnceCallback callback); 78*6777b538SAndroid Build Coastguard Worker 79*6777b538SAndroid Build Coastguard Worker bool IsResponseBodyComplete() const; 80*6777b538SAndroid Build Coastguard Worker 81*6777b538SAndroid Build Coastguard Worker bool CanFindEndOfResponse() const; 82*6777b538SAndroid Build Coastguard Worker 83*6777b538SAndroid Build Coastguard Worker bool IsMoreDataBuffered() const; 84*6777b538SAndroid Build Coastguard Worker 85*6777b538SAndroid Build Coastguard Worker // Returns true if the underlying connection can be reused. 86*6777b538SAndroid Build Coastguard Worker // The connection can be reused if: 87*6777b538SAndroid Build Coastguard Worker // * It's still connected. 88*6777b538SAndroid Build Coastguard Worker // * The response headers indicate the connection can be kept alive. 89*6777b538SAndroid Build Coastguard Worker // * The end of the response can be found, though it may not have yet been 90*6777b538SAndroid Build Coastguard Worker // received. 91*6777b538SAndroid Build Coastguard Worker // 92*6777b538SAndroid Build Coastguard Worker // Note that if response headers have yet to be received, this will return 93*6777b538SAndroid Build Coastguard Worker // false. 94*6777b538SAndroid Build Coastguard Worker bool CanReuseConnection() const; 95*6777b538SAndroid Build Coastguard Worker 96*6777b538SAndroid Build Coastguard Worker // Called when stream is closed. 97*6777b538SAndroid Build Coastguard Worker void OnConnectionClose(); 98*6777b538SAndroid Build Coastguard Worker received_bytes()99*6777b538SAndroid Build Coastguard Worker int64_t received_bytes() const { return received_bytes_; } 100*6777b538SAndroid Build Coastguard Worker sent_bytes()101*6777b538SAndroid Build Coastguard Worker int64_t sent_bytes() const { return sent_bytes_; } 102*6777b538SAndroid Build Coastguard Worker first_response_start_time()103*6777b538SAndroid Build Coastguard Worker base::TimeTicks first_response_start_time() const { 104*6777b538SAndroid Build Coastguard Worker return first_response_start_time_; 105*6777b538SAndroid Build Coastguard Worker } non_informational_response_start_time()106*6777b538SAndroid Build Coastguard Worker base::TimeTicks non_informational_response_start_time() const { 107*6777b538SAndroid Build Coastguard Worker return non_informational_response_start_time_; 108*6777b538SAndroid Build Coastguard Worker } first_early_hints_time()109*6777b538SAndroid Build Coastguard Worker base::TimeTicks first_early_hints_time() { return first_early_hints_time_; } 110*6777b538SAndroid Build Coastguard Worker 111*6777b538SAndroid Build Coastguard Worker // Encodes the given |payload| in the chunked format to |output|. 112*6777b538SAndroid Build Coastguard Worker // Returns the number of bytes written to |output|. |output_size| should 113*6777b538SAndroid Build Coastguard Worker // be large enough to store the encoded chunk, which is payload.size() + 114*6777b538SAndroid Build Coastguard Worker // kChunkHeaderFooterSize. Returns ERR_INVALID_ARGUMENT if |output_size| 115*6777b538SAndroid Build Coastguard Worker // is not large enough. 116*6777b538SAndroid Build Coastguard Worker // 117*6777b538SAndroid Build Coastguard Worker // The output will look like: "HEX\r\n[payload]\r\n" 118*6777b538SAndroid Build Coastguard Worker // where HEX is a length in hexdecimal (without the "0x" prefix). 119*6777b538SAndroid Build Coastguard Worker static int EncodeChunk(std::string_view payload, 120*6777b538SAndroid Build Coastguard Worker char* output, 121*6777b538SAndroid Build Coastguard Worker size_t output_size); 122*6777b538SAndroid Build Coastguard Worker 123*6777b538SAndroid Build Coastguard Worker // Returns true if request headers and body should be merged (i.e. the 124*6777b538SAndroid Build Coastguard Worker // sum is small enough and the body is in memory, and not chunked). 125*6777b538SAndroid Build Coastguard Worker static bool ShouldMergeRequestHeadersAndBody( 126*6777b538SAndroid Build Coastguard Worker const std::string& request_headers, 127*6777b538SAndroid Build Coastguard Worker const UploadDataStream* request_body); 128*6777b538SAndroid Build Coastguard Worker 129*6777b538SAndroid Build Coastguard Worker // The number of extra bytes required to encode a chunk. 130*6777b538SAndroid Build Coastguard Worker static const size_t kChunkHeaderFooterSize; 131*6777b538SAndroid Build Coastguard Worker 132*6777b538SAndroid Build Coastguard Worker private: 133*6777b538SAndroid Build Coastguard Worker class SeekableIOBuffer; 134*6777b538SAndroid Build Coastguard Worker 135*6777b538SAndroid Build Coastguard Worker // FOO_COMPLETE states implement the second half of potentially asynchronous 136*6777b538SAndroid Build Coastguard Worker // operations and don't necessarily mean that FOO is complete. 137*6777b538SAndroid Build Coastguard Worker enum State { 138*6777b538SAndroid Build Coastguard Worker // STATE_NONE indicates that this is waiting on an external call before 139*6777b538SAndroid Build Coastguard Worker // continuing. 140*6777b538SAndroid Build Coastguard Worker STATE_NONE, 141*6777b538SAndroid Build Coastguard Worker STATE_SEND_HEADERS, 142*6777b538SAndroid Build Coastguard Worker STATE_SEND_HEADERS_COMPLETE, 143*6777b538SAndroid Build Coastguard Worker STATE_SEND_BODY, 144*6777b538SAndroid Build Coastguard Worker STATE_SEND_BODY_COMPLETE, 145*6777b538SAndroid Build Coastguard Worker STATE_SEND_REQUEST_READ_BODY_COMPLETE, 146*6777b538SAndroid Build Coastguard Worker STATE_SEND_REQUEST_COMPLETE, 147*6777b538SAndroid Build Coastguard Worker STATE_READ_HEADERS, 148*6777b538SAndroid Build Coastguard Worker STATE_READ_HEADERS_COMPLETE, 149*6777b538SAndroid Build Coastguard Worker STATE_READ_BODY, 150*6777b538SAndroid Build Coastguard Worker STATE_READ_BODY_COMPLETE, 151*6777b538SAndroid Build Coastguard Worker STATE_DONE 152*6777b538SAndroid Build Coastguard Worker }; 153*6777b538SAndroid Build Coastguard Worker 154*6777b538SAndroid Build Coastguard Worker // The number of bytes by which the header buffer is grown when it reaches 155*6777b538SAndroid Build Coastguard Worker // capacity. 156*6777b538SAndroid Build Coastguard Worker static const int kHeaderBufInitialSize = 4 * 1024; // 4K 157*6777b538SAndroid Build Coastguard Worker 158*6777b538SAndroid Build Coastguard Worker // |kMaxHeaderBufSize| is the number of bytes that the response headers can 159*6777b538SAndroid Build Coastguard Worker // grow to. If the body start is not found within this range of the 160*6777b538SAndroid Build Coastguard Worker // response, the transaction will fail with ERR_RESPONSE_HEADERS_TOO_BIG. 161*6777b538SAndroid Build Coastguard Worker // Note: |kMaxHeaderBufSize| should be a multiple of |kHeaderBufInitialSize|. 162*6777b538SAndroid Build Coastguard Worker static const int kMaxHeaderBufSize = kHeaderBufInitialSize * 64; // 256K 163*6777b538SAndroid Build Coastguard Worker 164*6777b538SAndroid Build Coastguard Worker // The maximum sane buffer size. 165*6777b538SAndroid Build Coastguard Worker static const int kMaxBufSize = 2 * 1024 * 1024; // 2M 166*6777b538SAndroid Build Coastguard Worker 167*6777b538SAndroid Build Coastguard Worker // Handle callbacks. 168*6777b538SAndroid Build Coastguard Worker void OnIOComplete(int result); 169*6777b538SAndroid Build Coastguard Worker 170*6777b538SAndroid Build Coastguard Worker // Try to make progress sending/receiving the request/response. 171*6777b538SAndroid Build Coastguard Worker int DoLoop(int result); 172*6777b538SAndroid Build Coastguard Worker 173*6777b538SAndroid Build Coastguard Worker // The implementations of each state of the state machine. 174*6777b538SAndroid Build Coastguard Worker int DoSendHeaders(); 175*6777b538SAndroid Build Coastguard Worker int DoSendHeadersComplete(int result); 176*6777b538SAndroid Build Coastguard Worker int DoSendBody(); 177*6777b538SAndroid Build Coastguard Worker int DoSendBodyComplete(int result); 178*6777b538SAndroid Build Coastguard Worker int DoSendRequestReadBodyComplete(int result); 179*6777b538SAndroid Build Coastguard Worker int DoSendRequestComplete(int result); 180*6777b538SAndroid Build Coastguard Worker int DoReadHeaders(); 181*6777b538SAndroid Build Coastguard Worker int DoReadHeadersComplete(int result); 182*6777b538SAndroid Build Coastguard Worker int DoReadBody(); 183*6777b538SAndroid Build Coastguard Worker int DoReadBodyComplete(int result); 184*6777b538SAndroid Build Coastguard Worker 185*6777b538SAndroid Build Coastguard Worker // This handles most of the logic for DoReadHeadersComplete. 186*6777b538SAndroid Build Coastguard Worker int HandleReadHeaderResult(int result); 187*6777b538SAndroid Build Coastguard Worker 188*6777b538SAndroid Build Coastguard Worker void RunConfirmHandshakeCallback(int rv); 189*6777b538SAndroid Build Coastguard Worker 190*6777b538SAndroid Build Coastguard Worker // Examines |read_buf_| to find the start and end of the headers. If they are 191*6777b538SAndroid Build Coastguard Worker // found, parse them with DoParseResponseHeaders(). Return the offset for 192*6777b538SAndroid Build Coastguard Worker // the end of the headers, or -1 if the complete headers were not found, or 193*6777b538SAndroid Build Coastguard Worker // with a net::Error if we encountered an error during parsing. 194*6777b538SAndroid Build Coastguard Worker // 195*6777b538SAndroid Build Coastguard Worker // |new_bytes| is the number of new bytes that have been appended to the end 196*6777b538SAndroid Build Coastguard Worker // of |read_buf_| since the last call to this method (which must have returned 197*6777b538SAndroid Build Coastguard Worker // -1). 198*6777b538SAndroid Build Coastguard Worker int FindAndParseResponseHeaders(int new_bytes); 199*6777b538SAndroid Build Coastguard Worker 200*6777b538SAndroid Build Coastguard Worker // Parse the headers into response_. Returns OK on success or a net::Error on 201*6777b538SAndroid Build Coastguard Worker // failure. 202*6777b538SAndroid Build Coastguard Worker int ParseResponseHeaders(int end_of_header_offset); 203*6777b538SAndroid Build Coastguard Worker 204*6777b538SAndroid Build Coastguard Worker // Examine the parsed headers to try to determine the response body size. 205*6777b538SAndroid Build Coastguard Worker void CalculateResponseBodySize(); 206*6777b538SAndroid Build Coastguard Worker 207*6777b538SAndroid Build Coastguard Worker // Check if buffers used to send the request are empty. 208*6777b538SAndroid Build Coastguard Worker bool SendRequestBuffersEmpty(); 209*6777b538SAndroid Build Coastguard Worker 210*6777b538SAndroid Build Coastguard Worker // Next state of the request, when the current one completes. 211*6777b538SAndroid Build Coastguard Worker State io_state_ = STATE_NONE; 212*6777b538SAndroid Build Coastguard Worker 213*6777b538SAndroid Build Coastguard Worker // Null when read state machine is invoked. 214*6777b538SAndroid Build Coastguard Worker raw_ptr<const HttpRequestInfo, AcrossTasksDanglingUntriaged> request_; 215*6777b538SAndroid Build Coastguard Worker 216*6777b538SAndroid Build Coastguard Worker // The request header data. May include a merged request body. 217*6777b538SAndroid Build Coastguard Worker scoped_refptr<DrainableIOBuffer> request_headers_; 218*6777b538SAndroid Build Coastguard Worker 219*6777b538SAndroid Build Coastguard Worker // Size of just the request headers. May be less than the length of 220*6777b538SAndroid Build Coastguard Worker // |request_headers_| if the body was merged with the headers. 221*6777b538SAndroid Build Coastguard Worker int request_headers_length_ = 0; 222*6777b538SAndroid Build Coastguard Worker 223*6777b538SAndroid Build Coastguard Worker // Temporary buffer for reading. 224*6777b538SAndroid Build Coastguard Worker scoped_refptr<GrowableIOBuffer> read_buf_; 225*6777b538SAndroid Build Coastguard Worker 226*6777b538SAndroid Build Coastguard Worker // Offset of the first unused byte in |read_buf_|. May be nonzero due to 227*6777b538SAndroid Build Coastguard Worker // body data in the same packet as header data but is zero when reading 228*6777b538SAndroid Build Coastguard Worker // headers. 229*6777b538SAndroid Build Coastguard Worker int read_buf_unused_offset_ = 0; 230*6777b538SAndroid Build Coastguard Worker 231*6777b538SAndroid Build Coastguard Worker // The amount beyond |read_buf_unused_offset_| where the status line starts; 232*6777b538SAndroid Build Coastguard Worker // std::string::npos if not found yet. 233*6777b538SAndroid Build Coastguard Worker size_t response_header_start_offset_; 234*6777b538SAndroid Build Coastguard Worker 235*6777b538SAndroid Build Coastguard Worker // The amount of received data. If connection is reused then intermediate 236*6777b538SAndroid Build Coastguard Worker // value may be bigger than final. 237*6777b538SAndroid Build Coastguard Worker int64_t received_bytes_ = 0; 238*6777b538SAndroid Build Coastguard Worker 239*6777b538SAndroid Build Coastguard Worker // The amount of sent data. 240*6777b538SAndroid Build Coastguard Worker int64_t sent_bytes_ = 0; 241*6777b538SAndroid Build Coastguard Worker 242*6777b538SAndroid Build Coastguard Worker // The parsed response headers. Owned by the caller of SendRequest. This 243*6777b538SAndroid Build Coastguard Worker // cannot be safely accessed after reading the final set of headers, as the 244*6777b538SAndroid Build Coastguard Worker // caller of SendRequest may have been destroyed - this happens in the case an 245*6777b538SAndroid Build Coastguard Worker // HttpResponseBodyDrainer is used. 246*6777b538SAndroid Build Coastguard Worker raw_ptr<HttpResponseInfo, AcrossTasksDanglingUntriaged> response_ = nullptr; 247*6777b538SAndroid Build Coastguard Worker 248*6777b538SAndroid Build Coastguard Worker // Time at which the first bytes of the first header response including 249*6777b538SAndroid Build Coastguard Worker // informational responses (1xx) are about to be parsed. This corresponds to 250*6777b538SAndroid Build Coastguard Worker // |LoadTimingInfo::receive_headers_start|. See also comments there. 251*6777b538SAndroid Build Coastguard Worker base::TimeTicks first_response_start_time_; 252*6777b538SAndroid Build Coastguard Worker 253*6777b538SAndroid Build Coastguard Worker // Time at which the first bytes of the current header response are about to 254*6777b538SAndroid Build Coastguard Worker // be parsed. This is reset every time new response headers including 255*6777b538SAndroid Build Coastguard Worker // non-informational responses (1xx) are parsed. 256*6777b538SAndroid Build Coastguard Worker base::TimeTicks current_response_start_time_; 257*6777b538SAndroid Build Coastguard Worker 258*6777b538SAndroid Build Coastguard Worker // Time at which the first byte of the non-informational header response 259*6777b538SAndroid Build Coastguard Worker // (non-1xx) are about to be parsed. This corresponds to 260*6777b538SAndroid Build Coastguard Worker // |LoadTimingInfo::receive_non_informational_headers_start|. See also 261*6777b538SAndroid Build Coastguard Worker // comments there. 262*6777b538SAndroid Build Coastguard Worker base::TimeTicks non_informational_response_start_time_; 263*6777b538SAndroid Build Coastguard Worker 264*6777b538SAndroid Build Coastguard Worker // Time at which the first 103 Early Hints response is received. This 265*6777b538SAndroid Build Coastguard Worker // corresponds to |LoadTimingInfo::first_early_hints_time|. 266*6777b538SAndroid Build Coastguard Worker base::TimeTicks first_early_hints_time_; 267*6777b538SAndroid Build Coastguard Worker 268*6777b538SAndroid Build Coastguard Worker // Indicates the content length. If this value is less than zero 269*6777b538SAndroid Build Coastguard Worker // (and chunked_decoder_ is null), then we must read until the server 270*6777b538SAndroid Build Coastguard Worker // closes the connection. 271*6777b538SAndroid Build Coastguard Worker int64_t response_body_length_ = -1; 272*6777b538SAndroid Build Coastguard Worker 273*6777b538SAndroid Build Coastguard Worker // True if reading a keep-alive response. False if not, or if don't yet know. 274*6777b538SAndroid Build Coastguard Worker bool response_is_keep_alive_ = false; 275*6777b538SAndroid Build Coastguard Worker 276*6777b538SAndroid Build Coastguard Worker // True if we've seen a response that has an HTTP status line. This is 277*6777b538SAndroid Build Coastguard Worker // persistent across multiple response parsing. If we see a status line 278*6777b538SAndroid Build Coastguard Worker // for a response, this will remain true forever. 279*6777b538SAndroid Build Coastguard Worker bool has_seen_status_line_ = false; 280*6777b538SAndroid Build Coastguard Worker 281*6777b538SAndroid Build Coastguard Worker // Keep track of the number of response body bytes read so far. 282*6777b538SAndroid Build Coastguard Worker int64_t response_body_read_ = 0; 283*6777b538SAndroid Build Coastguard Worker 284*6777b538SAndroid Build Coastguard Worker // Helper if the data is chunked. 285*6777b538SAndroid Build Coastguard Worker std::unique_ptr<HttpChunkedDecoder> chunked_decoder_; 286*6777b538SAndroid Build Coastguard Worker 287*6777b538SAndroid Build Coastguard Worker // Where the caller wants the body data. 288*6777b538SAndroid Build Coastguard Worker scoped_refptr<IOBuffer> user_read_buf_; 289*6777b538SAndroid Build Coastguard Worker int user_read_buf_len_ = 0; 290*6777b538SAndroid Build Coastguard Worker 291*6777b538SAndroid Build Coastguard Worker // The callback to notify a user that the handshake has been confirmed. 292*6777b538SAndroid Build Coastguard Worker CompletionOnceCallback confirm_handshake_callback_; 293*6777b538SAndroid Build Coastguard Worker 294*6777b538SAndroid Build Coastguard Worker // The callback to notify a user that their request or response is 295*6777b538SAndroid Build Coastguard Worker // complete or there was an error 296*6777b538SAndroid Build Coastguard Worker CompletionOnceCallback callback_; 297*6777b538SAndroid Build Coastguard Worker 298*6777b538SAndroid Build Coastguard Worker // The underlying socket, owned by the caller. The HttpStreamParser must be 299*6777b538SAndroid Build Coastguard Worker // destroyed before the caller destroys the socket, or relinquishes ownership 300*6777b538SAndroid Build Coastguard Worker // of it. 301*6777b538SAndroid Build Coastguard Worker raw_ptr<StreamSocket> stream_socket_; 302*6777b538SAndroid Build Coastguard Worker 303*6777b538SAndroid Build Coastguard Worker // Whether the socket has already been used. Only used in HTTP/0.9 detection 304*6777b538SAndroid Build Coastguard Worker // logic. 305*6777b538SAndroid Build Coastguard Worker const bool connection_is_reused_; 306*6777b538SAndroid Build Coastguard Worker 307*6777b538SAndroid Build Coastguard Worker NetLogWithSource net_log_; 308*6777b538SAndroid Build Coastguard Worker 309*6777b538SAndroid Build Coastguard Worker // Callback to be used when doing IO. 310*6777b538SAndroid Build Coastguard Worker CompletionRepeatingCallback io_callback_; 311*6777b538SAndroid Build Coastguard Worker 312*6777b538SAndroid Build Coastguard Worker // Buffer used to read the request body from UploadDataStream. 313*6777b538SAndroid Build Coastguard Worker scoped_refptr<SeekableIOBuffer> request_body_read_buf_; 314*6777b538SAndroid Build Coastguard Worker // Buffer used to send the request body. This points the same buffer as 315*6777b538SAndroid Build Coastguard Worker // |request_body_read_buf_| unless the data is chunked. 316*6777b538SAndroid Build Coastguard Worker scoped_refptr<SeekableIOBuffer> request_body_send_buf_; 317*6777b538SAndroid Build Coastguard Worker bool sent_last_chunk_ = false; 318*6777b538SAndroid Build Coastguard Worker 319*6777b538SAndroid Build Coastguard Worker // Whether the Content-Length was known and extra data was discarded. 320*6777b538SAndroid Build Coastguard Worker bool discarded_extra_data_ = false; 321*6777b538SAndroid Build Coastguard Worker 322*6777b538SAndroid Build Coastguard Worker // Whether the response body should be truncated to the Content-Length. 323*6777b538SAndroid Build Coastguard Worker const bool truncate_to_content_length_enabled_; 324*6777b538SAndroid Build Coastguard Worker 325*6777b538SAndroid Build Coastguard Worker // Error received when uploading the body, if any. 326*6777b538SAndroid Build Coastguard Worker int upload_error_ = OK; 327*6777b538SAndroid Build Coastguard Worker 328*6777b538SAndroid Build Coastguard Worker MutableNetworkTrafficAnnotationTag traffic_annotation_; 329*6777b538SAndroid Build Coastguard Worker 330*6777b538SAndroid Build Coastguard Worker base::WeakPtrFactory<HttpStreamParser> weak_ptr_factory_{this}; 331*6777b538SAndroid Build Coastguard Worker }; 332*6777b538SAndroid Build Coastguard Worker 333*6777b538SAndroid Build Coastguard Worker } // namespace net 334*6777b538SAndroid Build Coastguard Worker 335*6777b538SAndroid Build Coastguard Worker #endif // NET_HTTP_HTTP_STREAM_PARSER_H_ 336