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 <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 // operations and don't necessarily mean that FOO is complete. | 128 // operations and don't necessarily mean that FOO is complete. |
129 enum State { | 129 enum State { |
130 // STATE_NONE indicates that this is waiting on an external call before | 130 // STATE_NONE indicates that this is waiting on an external call before |
131 // continuing. | 131 // continuing. |
132 STATE_NONE, | 132 STATE_NONE, |
133 STATE_SEND_HEADERS, | 133 STATE_SEND_HEADERS, |
134 STATE_SEND_HEADERS_COMPLETE, | 134 STATE_SEND_HEADERS_COMPLETE, |
135 STATE_SEND_BODY, | 135 STATE_SEND_BODY, |
136 STATE_SEND_BODY_COMPLETE, | 136 STATE_SEND_BODY_COMPLETE, |
137 STATE_SEND_REQUEST_READ_BODY_COMPLETE, | 137 STATE_SEND_REQUEST_READ_BODY_COMPLETE, |
| 138 STATE_SEND_REQUEST_COMPLETE, |
138 STATE_READ_HEADERS, | 139 STATE_READ_HEADERS, |
139 STATE_READ_HEADERS_COMPLETE, | 140 STATE_READ_HEADERS_COMPLETE, |
140 STATE_READ_BODY, | 141 STATE_READ_BODY, |
141 STATE_READ_BODY_COMPLETE, | 142 STATE_READ_BODY_COMPLETE, |
142 STATE_DONE | 143 STATE_DONE |
143 }; | 144 }; |
144 | 145 |
145 // The number of bytes by which the header buffer is grown when it reaches | 146 // The number of bytes by which the header buffer is grown when it reaches |
146 // capacity. | 147 // capacity. |
147 static const int kHeaderBufInitialSize = 4 * 1024; // 4K | 148 static const int kHeaderBufInitialSize = 4 * 1024; // 4K |
(...skipping 12 matching lines...) Expand all Loading... |
160 | 161 |
161 // Try to make progress sending/receiving the request/response. | 162 // Try to make progress sending/receiving the request/response. |
162 int DoLoop(int result); | 163 int DoLoop(int result); |
163 | 164 |
164 // The implementations of each state of the state machine. | 165 // The implementations of each state of the state machine. |
165 int DoSendHeaders(); | 166 int DoSendHeaders(); |
166 int DoSendHeadersComplete(int result); | 167 int DoSendHeadersComplete(int result); |
167 int DoSendBody(); | 168 int DoSendBody(); |
168 int DoSendBodyComplete(int result); | 169 int DoSendBodyComplete(int result); |
169 int DoSendRequestReadBodyComplete(int result); | 170 int DoSendRequestReadBodyComplete(int result); |
| 171 int DoSendRequestComplete(int result); |
170 int DoReadHeaders(); | 172 int DoReadHeaders(); |
171 int DoReadHeadersComplete(int result); | 173 int DoReadHeadersComplete(int result); |
172 int DoReadBody(); | 174 int DoReadBody(); |
173 int DoReadBodyComplete(int result); | 175 int DoReadBodyComplete(int result); |
174 | 176 |
175 // This handles most of the logic for DoReadHeadersComplete. | 177 // This handles most of the logic for DoReadHeadersComplete. |
176 int HandleReadHeaderResult(int result); | 178 int HandleReadHeaderResult(int result); |
177 | 179 |
178 // Examines |read_buf_| to find the start and end of the headers. If they are | 180 // Examines |read_buf_| to find the start and end of the headers. If they are |
179 // found, parse them with DoParseResponseHeaders(). Return the offset for | 181 // found, parse them with DoParseResponseHeaders(). Return the offset for |
180 // the end of the headers, or -1 if the complete headers were not found, or | 182 // the end of the headers, or -1 if the complete headers were not found, or |
181 // with a net::Error if we encountered an error during parsing. | 183 // with a net::Error if we encountered an error during parsing. |
182 int FindAndParseResponseHeaders(); | 184 int FindAndParseResponseHeaders(); |
183 | 185 |
184 // Parse the headers into response_. Returns OK on success or a net::Error on | 186 // Parse the headers into response_. Returns OK on success or a net::Error on |
185 // failure. | 187 // failure. |
186 int ParseResponseHeaders(int end_of_header_offset); | 188 int ParseResponseHeaders(int end_of_header_offset); |
187 | 189 |
188 // Examine the parsed headers to try to determine the response body size. | 190 // Examine the parsed headers to try to determine the response body size. |
189 void CalculateResponseBodySize(); | 191 void CalculateResponseBodySize(); |
190 | 192 |
191 // Uploads statistics about status line compliance with RFC 7230. | 193 // Uploads statistics about status line compliance with RFC 7230. |
192 void ValidateStatusLine(const std::string& status_line); | 194 void ValidateStatusLine(const std::string& status_line); |
193 | 195 |
| 196 // Check if buffers used to send the request are empty. |
| 197 bool SendRequestBuffersEmpty(); |
| 198 |
194 // Next state of the request, when the current one completes. | 199 // Next state of the request, when the current one completes. |
195 State io_state_; | 200 State io_state_; |
196 | 201 |
197 // The request to send. | 202 // The request to send. |
198 const HttpRequestInfo* request_; | 203 const HttpRequestInfo* request_; |
199 | 204 |
200 // The request header data. May include a merged request body. | 205 // The request header data. May include a merged request body. |
201 scoped_refptr<DrainableIOBuffer> request_headers_; | 206 scoped_refptr<DrainableIOBuffer> request_headers_; |
202 | 207 |
203 // Size of just the request headers. May be less than the length of | 208 // Size of just the request headers. May be less than the length of |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 int upload_error_; | 281 int upload_error_; |
277 | 282 |
278 base::WeakPtrFactory<HttpStreamParser> weak_ptr_factory_; | 283 base::WeakPtrFactory<HttpStreamParser> weak_ptr_factory_; |
279 | 284 |
280 DISALLOW_COPY_AND_ASSIGN(HttpStreamParser); | 285 DISALLOW_COPY_AND_ASSIGN(HttpStreamParser); |
281 }; | 286 }; |
282 | 287 |
283 } // namespace net | 288 } // namespace net |
284 | 289 |
285 #endif // NET_HTTP_HTTP_STREAM_PARSER_H_ | 290 #endif // NET_HTTP_HTTP_STREAM_PARSER_H_ |
OLD | NEW |