| 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 #include "net/http/http_stream_parser.h" | 5 #include "net/http/http_stream_parser.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/metrics/histogram_macros.h" | 12 #include "base/metrics/histogram_macros.h" |
| 13 #include "base/profiler/scoped_tracker.h" | 13 #include "base/profiler/scoped_tracker.h" |
| 14 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
| 15 #include "base/values.h" | 15 #include "base/values.h" |
| 16 #include "net/base/io_buffer.h" | 16 #include "net/base/io_buffer.h" |
| 17 #include "net/base/ip_endpoint.h" | 17 #include "net/base/ip_endpoint.h" |
| 18 #include "net/base/upload_data_stream.h" | 18 #include "net/base/upload_data_stream.h" |
| 19 #include "net/http/http_chunked_decoder.h" | 19 #include "net/http/http_chunked_decoder.h" |
| 20 #include "net/http/http_request_headers.h" | 20 #include "net/http/http_request_headers.h" |
| 21 #include "net/http/http_request_info.h" | 21 #include "net/http/http_request_info.h" |
| 22 #include "net/http/http_response_headers.h" | 22 #include "net/http/http_response_headers.h" |
| 23 #include "net/http/http_status_line_validator.h" | 23 #include "net/http/http_status_line_validator.h" |
| 24 #include "net/http/http_util.h" | 24 #include "net/http/http_util.h" |
| 25 #include "net/log/net_log_event_type.h" |
| 25 #include "net/socket/client_socket_handle.h" | 26 #include "net/socket/client_socket_handle.h" |
| 26 #include "net/socket/ssl_client_socket.h" | 27 #include "net/socket/ssl_client_socket.h" |
| 27 #include "net/ssl/token_binding.h" | 28 #include "net/ssl/token_binding.h" |
| 28 #include "url/url_canon.h" | 29 #include "url/url_canon.h" |
| 29 | 30 |
| 30 namespace net { | 31 namespace net { |
| 31 | 32 |
| 32 namespace { | 33 namespace { |
| 33 | 34 |
| 34 enum HttpHeaderParserEvent { | 35 enum HttpHeaderParserEvent { |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 int HttpStreamParser::SendRequest(const std::string& request_line, | 236 int HttpStreamParser::SendRequest(const std::string& request_line, |
| 236 const HttpRequestHeaders& headers, | 237 const HttpRequestHeaders& headers, |
| 237 HttpResponseInfo* response, | 238 HttpResponseInfo* response, |
| 238 const CompletionCallback& callback) { | 239 const CompletionCallback& callback) { |
| 239 DCHECK_EQ(STATE_NONE, io_state_); | 240 DCHECK_EQ(STATE_NONE, io_state_); |
| 240 DCHECK(callback_.is_null()); | 241 DCHECK(callback_.is_null()); |
| 241 DCHECK(!callback.is_null()); | 242 DCHECK(!callback.is_null()); |
| 242 DCHECK(response); | 243 DCHECK(response); |
| 243 | 244 |
| 244 net_log_.AddEvent( | 245 net_log_.AddEvent( |
| 245 NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST_HEADERS, | 246 NetLogEventType::HTTP_TRANSACTION_SEND_REQUEST_HEADERS, |
| 246 base::Bind(&HttpRequestHeaders::NetLogCallback, | 247 base::Bind(&HttpRequestHeaders::NetLogCallback, |
| 247 base::Unretained(&headers), | 248 base::Unretained(&headers), |
| 248 &request_line)); | 249 &request_line)); |
| 249 | 250 |
| 250 DVLOG(1) << __func__ << "() request_line = \"" << request_line << "\"" | 251 DVLOG(1) << __func__ << "() request_line = \"" << request_line << "\"" |
| 251 << " headers = \"" << headers.ToString() << "\""; | 252 << " headers = \"" << headers.ToString() << "\""; |
| 252 response_ = response; | 253 response_ = response; |
| 253 | 254 |
| 254 // Put the peer's IP address and port into the response. | 255 // Put the peer's IP address and port into the response. |
| 255 IPEndPoint ip_endpoint; | 256 IPEndPoint ip_endpoint; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 DCHECK_GT(consumed, 0); | 301 DCHECK_GT(consumed, 0); |
| 301 request_headers_->DidConsume(consumed); | 302 request_headers_->DidConsume(consumed); |
| 302 todo -= consumed; | 303 todo -= consumed; |
| 303 } | 304 } |
| 304 DCHECK(request_->upload_data_stream->IsEOF()); | 305 DCHECK(request_->upload_data_stream->IsEOF()); |
| 305 // Reset the offset, so the buffer can be read from the beginning. | 306 // Reset the offset, so the buffer can be read from the beginning. |
| 306 request_headers_->SetOffset(0); | 307 request_headers_->SetOffset(0); |
| 307 did_merge = true; | 308 did_merge = true; |
| 308 | 309 |
| 309 net_log_.AddEvent( | 310 net_log_.AddEvent( |
| 310 NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST_BODY, | 311 NetLogEventType::HTTP_TRANSACTION_SEND_REQUEST_BODY, |
| 311 base::Bind(&NetLogSendRequestBodyCallback, | 312 base::Bind(&NetLogSendRequestBodyCallback, |
| 312 request_->upload_data_stream->size(), | 313 request_->upload_data_stream->size(), |
| 313 false, /* not chunked */ | 314 false, /* not chunked */ |
| 314 true /* merged */)); | 315 true /* merged */)); |
| 315 } | 316 } |
| 316 | 317 |
| 317 if (!did_merge) { | 318 if (!did_merge) { |
| 318 // If we didn't merge the body with the headers, then |request_headers_| | 319 // If we didn't merge the body with the headers, then |request_headers_| |
| 319 // contains just the HTTP headers. | 320 // contains just the HTTP headers. |
| 320 scoped_refptr<StringIOBuffer> headers_io_buf(new StringIOBuffer(request)); | 321 scoped_refptr<StringIOBuffer> headers_io_buf(new StringIOBuffer(request)); |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 428 DCHECK_NE(STATE_NONE, io_state_); | 429 DCHECK_NE(STATE_NONE, io_state_); |
| 429 break; | 430 break; |
| 430 case STATE_SEND_REQUEST_READ_BODY_COMPLETE: | 431 case STATE_SEND_REQUEST_READ_BODY_COMPLETE: |
| 431 result = DoSendRequestReadBodyComplete(result); | 432 result = DoSendRequestReadBodyComplete(result); |
| 432 DCHECK_NE(STATE_NONE, io_state_); | 433 DCHECK_NE(STATE_NONE, io_state_); |
| 433 break; | 434 break; |
| 434 case STATE_SEND_REQUEST_COMPLETE: | 435 case STATE_SEND_REQUEST_COMPLETE: |
| 435 result = DoSendRequestComplete(result); | 436 result = DoSendRequestComplete(result); |
| 436 break; | 437 break; |
| 437 case STATE_READ_HEADERS: | 438 case STATE_READ_HEADERS: |
| 438 net_log_.BeginEvent(NetLog::TYPE_HTTP_STREAM_PARSER_READ_HEADERS); | 439 net_log_.BeginEvent(NetLogEventType::HTTP_STREAM_PARSER_READ_HEADERS); |
| 439 DCHECK_GE(result, 0); | 440 DCHECK_GE(result, 0); |
| 440 result = DoReadHeaders(); | 441 result = DoReadHeaders(); |
| 441 break; | 442 break; |
| 442 case STATE_READ_HEADERS_COMPLETE: | 443 case STATE_READ_HEADERS_COMPLETE: |
| 443 result = DoReadHeadersComplete(result); | 444 result = DoReadHeadersComplete(result); |
| 444 net_log_.EndEventWithNetErrorCode( | 445 net_log_.EndEventWithNetErrorCode( |
| 445 NetLog::TYPE_HTTP_STREAM_PARSER_READ_HEADERS, result); | 446 NetLogEventType::HTTP_STREAM_PARSER_READ_HEADERS, result); |
| 446 break; | 447 break; |
| 447 case STATE_READ_BODY: | 448 case STATE_READ_BODY: |
| 448 DCHECK_GE(result, 0); | 449 DCHECK_GE(result, 0); |
| 449 result = DoReadBody(); | 450 result = DoReadBody(); |
| 450 break; | 451 break; |
| 451 case STATE_READ_BODY_COMPLETE: | 452 case STATE_READ_BODY_COMPLETE: |
| 452 result = DoReadBodyComplete(result); | 453 result = DoReadBodyComplete(result); |
| 453 break; | 454 break; |
| 454 default: | 455 default: |
| 455 NOTREACHED(); | 456 NOTREACHED(); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 501 io_state_ = STATE_SEND_HEADERS; | 502 io_state_ = STATE_SEND_HEADERS; |
| 502 return OK; | 503 return OK; |
| 503 } | 504 } |
| 504 | 505 |
| 505 if (request_->upload_data_stream != NULL && | 506 if (request_->upload_data_stream != NULL && |
| 506 (request_->upload_data_stream->is_chunked() || | 507 (request_->upload_data_stream->is_chunked() || |
| 507 // !IsEOF() indicates that the body wasn't merged. | 508 // !IsEOF() indicates that the body wasn't merged. |
| 508 (request_->upload_data_stream->size() > 0 && | 509 (request_->upload_data_stream->size() > 0 && |
| 509 !request_->upload_data_stream->IsEOF()))) { | 510 !request_->upload_data_stream->IsEOF()))) { |
| 510 net_log_.AddEvent( | 511 net_log_.AddEvent( |
| 511 NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST_BODY, | 512 NetLogEventType::HTTP_TRANSACTION_SEND_REQUEST_BODY, |
| 512 base::Bind(&NetLogSendRequestBodyCallback, | 513 base::Bind(&NetLogSendRequestBodyCallback, |
| 513 request_->upload_data_stream->size(), | 514 request_->upload_data_stream->size(), |
| 514 request_->upload_data_stream->is_chunked(), | 515 request_->upload_data_stream->is_chunked(), |
| 515 false /* not merged */)); | 516 false /* not merged */)); |
| 516 io_state_ = STATE_SEND_BODY; | 517 io_state_ = STATE_SEND_BODY; |
| 517 return OK; | 518 return OK; |
| 518 } | 519 } |
| 519 | 520 |
| 520 // Finished sending the request. | 521 // Finished sending the request. |
| 521 io_state_ = STATE_SEND_REQUEST_COMPLETE; | 522 io_state_ = STATE_SEND_REQUEST_COMPLETE; |
| (...skipping 710 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1232 UMA_HISTOGRAM_ENUMERATION("Net.HttpStatusLineStatus", status, | 1233 UMA_HISTOGRAM_ENUMERATION("Net.HttpStatusLineStatus", status, |
| 1233 HttpStatusLineValidator::STATUS_LINE_MAX); | 1234 HttpStatusLineValidator::STATUS_LINE_MAX); |
| 1234 } | 1235 } |
| 1235 | 1236 |
| 1236 bool HttpStreamParser::SendRequestBuffersEmpty() { | 1237 bool HttpStreamParser::SendRequestBuffersEmpty() { |
| 1237 return request_headers_ == nullptr && request_body_send_buf_ == nullptr && | 1238 return request_headers_ == nullptr && request_body_send_buf_ == nullptr && |
| 1238 request_body_send_buf_ == nullptr; | 1239 request_body_send_buf_ == nullptr; |
| 1239 } | 1240 } |
| 1240 | 1241 |
| 1241 } // namespace net | 1242 } // namespace net |
| OLD | NEW |