| 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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/metrics/histogram_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 HEADER_HTTP_09_RESPONSE_OVER_SSL = 6, | 37 HEADER_HTTP_09_RESPONSE_OVER_SSL = 6, |
| 38 HEADER_HTTP_09_ON_REUSED_SOCKET = 7, | 38 HEADER_HTTP_09_ON_REUSED_SOCKET = 7, |
| 39 NUM_HEADER_EVENTS | 39 NUM_HEADER_EVENTS |
| 40 }; | 40 }; |
| 41 | 41 |
| 42 void RecordHeaderParserEvent(HttpHeaderParserEvent header_event) { | 42 void RecordHeaderParserEvent(HttpHeaderParserEvent header_event) { |
| 43 UMA_HISTOGRAM_ENUMERATION("Net.HttpHeaderParserEvent", header_event, | 43 UMA_HISTOGRAM_ENUMERATION("Net.HttpHeaderParserEvent", header_event, |
| 44 NUM_HEADER_EVENTS); | 44 NUM_HEADER_EVENTS); |
| 45 } | 45 } |
| 46 | 46 |
| 47 const uint64 kMaxMergedHeaderAndBodySize = 1400; | 47 const uint64_t kMaxMergedHeaderAndBodySize = 1400; |
| 48 const size_t kRequestBodyBufferSize = 1 << 14; // 16KB | 48 const size_t kRequestBodyBufferSize = 1 << 14; // 16KB |
| 49 | 49 |
| 50 std::string GetResponseHeaderLines(const HttpResponseHeaders& headers) { | 50 std::string GetResponseHeaderLines(const HttpResponseHeaders& headers) { |
| 51 std::string raw_headers = headers.raw_headers(); | 51 std::string raw_headers = headers.raw_headers(); |
| 52 const char* null_separated_headers = raw_headers.c_str(); | 52 const char* null_separated_headers = raw_headers.c_str(); |
| 53 const char* header_line = null_separated_headers; | 53 const char* header_line = null_separated_headers; |
| 54 std::string cr_separated_headers; | 54 std::string cr_separated_headers; |
| 55 while (header_line[0] != 0) { | 55 while (header_line[0] != 0) { |
| 56 cr_separated_headers += header_line; | 56 cr_separated_headers += header_line; |
| 57 cr_separated_headers += "\n"; | 57 cr_separated_headers += "\n"; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 72 // such headers, and if so, return true if they have different values. | 72 // such headers, and if so, return true if they have different values. |
| 73 std::string field_value2; | 73 std::string field_value2; |
| 74 while (headers.EnumerateHeader(&it, field_name, &field_value2)) { | 74 while (headers.EnumerateHeader(&it, field_name, &field_value2)) { |
| 75 if (field_value != field_value2) | 75 if (field_value != field_value2) |
| 76 return true; | 76 return true; |
| 77 } | 77 } |
| 78 return false; | 78 return false; |
| 79 } | 79 } |
| 80 | 80 |
| 81 scoped_ptr<base::Value> NetLogSendRequestBodyCallback( | 81 scoped_ptr<base::Value> NetLogSendRequestBodyCallback( |
| 82 uint64 length, | 82 uint64_t length, |
| 83 bool is_chunked, | 83 bool is_chunked, |
| 84 bool did_merge, | 84 bool did_merge, |
| 85 NetLogCaptureMode /* capture_mode */) { | 85 NetLogCaptureMode /* capture_mode */) { |
| 86 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | 86 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
| 87 dict->SetInteger("length", static_cast<int>(length)); | 87 dict->SetInteger("length", static_cast<int>(length)); |
| 88 dict->SetBoolean("is_chunked", is_chunked); | 88 dict->SetBoolean("is_chunked", is_chunked); |
| 89 dict->SetBoolean("did_merge", did_merge); | 89 dict->SetBoolean("did_merge", did_merge); |
| 90 return dict.Pass(); | 90 return dict.Pass(); |
| 91 } | 91 } |
| 92 | 92 |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 scoped_refptr<IOBuffer> merged_request_headers_and_body( | 280 scoped_refptr<IOBuffer> merged_request_headers_and_body( |
| 281 new IOBuffer(merged_size)); | 281 new IOBuffer(merged_size)); |
| 282 // We'll repurpose |request_headers_| to store the merged headers and | 282 // We'll repurpose |request_headers_| to store the merged headers and |
| 283 // body. | 283 // body. |
| 284 request_headers_ = new DrainableIOBuffer( | 284 request_headers_ = new DrainableIOBuffer( |
| 285 merged_request_headers_and_body.get(), merged_size); | 285 merged_request_headers_and_body.get(), merged_size); |
| 286 | 286 |
| 287 memcpy(request_headers_->data(), request.data(), request_headers_length_); | 287 memcpy(request_headers_->data(), request.data(), request_headers_length_); |
| 288 request_headers_->DidConsume(request_headers_length_); | 288 request_headers_->DidConsume(request_headers_length_); |
| 289 | 289 |
| 290 uint64 todo = request_->upload_data_stream->size(); | 290 uint64_t todo = request_->upload_data_stream->size(); |
| 291 while (todo) { | 291 while (todo) { |
| 292 int consumed = request_->upload_data_stream->Read( | 292 int consumed = request_->upload_data_stream->Read( |
| 293 request_headers_.get(), static_cast<int>(todo), CompletionCallback()); | 293 request_headers_.get(), static_cast<int>(todo), CompletionCallback()); |
| 294 DCHECK_GT(consumed, 0); // Read() won't fail if not chunked. | 294 DCHECK_GT(consumed, 0); // Read() won't fail if not chunked. |
| 295 request_headers_->DidConsume(consumed); | 295 request_headers_->DidConsume(consumed); |
| 296 todo -= consumed; | 296 todo -= consumed; |
| 297 } | 297 } |
| 298 DCHECK(request_->upload_data_stream->IsEOF()); | 298 DCHECK(request_->upload_data_stream->IsEOF()); |
| 299 // Reset the offset, so the buffer can be read from the beginning. | 299 // Reset the offset, so the buffer can be read from the beginning. |
| 300 request_headers_->SetOffset(0); | 300 request_headers_->SetOffset(0); |
| (...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 728 // Save the overflow data, which can be in two places. There may be | 728 // Save the overflow data, which can be in two places. There may be |
| 729 // some left over in |user_read_buf_|, plus there may be more | 729 // some left over in |user_read_buf_|, plus there may be more |
| 730 // in |read_buf_|. But the part left over in |user_read_buf_| must have | 730 // in |read_buf_|. But the part left over in |user_read_buf_| must have |
| 731 // come from the |read_buf_|, so there's room to put it back at the | 731 // come from the |read_buf_|, so there's room to put it back at the |
| 732 // start first. | 732 // start first. |
| 733 int additional_save_amount = read_buf_->offset() - read_buf_unused_offset_; | 733 int additional_save_amount = read_buf_->offset() - read_buf_unused_offset_; |
| 734 int save_amount = 0; | 734 int save_amount = 0; |
| 735 if (chunked_decoder_.get()) { | 735 if (chunked_decoder_.get()) { |
| 736 save_amount = chunked_decoder_->bytes_after_eof(); | 736 save_amount = chunked_decoder_->bytes_after_eof(); |
| 737 } else if (response_body_length_ >= 0) { | 737 } else if (response_body_length_ >= 0) { |
| 738 int64 extra_data_read = response_body_read_ - response_body_length_; | 738 int64_t extra_data_read = response_body_read_ - response_body_length_; |
| 739 if (extra_data_read > 0) { | 739 if (extra_data_read > 0) { |
| 740 save_amount = static_cast<int>(extra_data_read); | 740 save_amount = static_cast<int>(extra_data_read); |
| 741 if (result > 0) | 741 if (result > 0) |
| 742 result -= save_amount; | 742 result -= save_amount; |
| 743 } | 743 } |
| 744 } | 744 } |
| 745 | 745 |
| 746 CHECK_LE(save_amount + additional_save_amount, kMaxBufSize); | 746 CHECK_LE(save_amount + additional_save_amount, kMaxBufSize); |
| 747 if (read_buf_->capacity() < save_amount + additional_save_amount) { | 747 if (read_buf_->capacity() < save_amount + additional_save_amount) { |
| 748 read_buf_->SetCapacity(save_amount + additional_save_amount); | 748 read_buf_->SetCapacity(save_amount + additional_save_amount); |
| (...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1123 } | 1123 } |
| 1124 | 1124 |
| 1125 // static | 1125 // static |
| 1126 bool HttpStreamParser::ShouldMergeRequestHeadersAndBody( | 1126 bool HttpStreamParser::ShouldMergeRequestHeadersAndBody( |
| 1127 const std::string& request_headers, | 1127 const std::string& request_headers, |
| 1128 const UploadDataStream* request_body) { | 1128 const UploadDataStream* request_body) { |
| 1129 if (request_body != NULL && | 1129 if (request_body != NULL && |
| 1130 // IsInMemory() ensures that the request body is not chunked. | 1130 // IsInMemory() ensures that the request body is not chunked. |
| 1131 request_body->IsInMemory() && | 1131 request_body->IsInMemory() && |
| 1132 request_body->size() > 0) { | 1132 request_body->size() > 0) { |
| 1133 uint64 merged_size = request_headers.size() + request_body->size(); | 1133 uint64_t merged_size = request_headers.size() + request_body->size(); |
| 1134 if (merged_size <= kMaxMergedHeaderAndBodySize) | 1134 if (merged_size <= kMaxMergedHeaderAndBodySize) |
| 1135 return true; | 1135 return true; |
| 1136 } | 1136 } |
| 1137 return false; | 1137 return false; |
| 1138 } | 1138 } |
| 1139 | 1139 |
| 1140 void HttpStreamParser::ValidateStatusLine(const std::string& status_line) { | 1140 void HttpStreamParser::ValidateStatusLine(const std::string& status_line) { |
| 1141 HttpStatusLineValidator::StatusLineStatus status = | 1141 HttpStatusLineValidator::StatusLineStatus status = |
| 1142 HttpStatusLineValidator::ValidateStatusLine(status_line); | 1142 HttpStatusLineValidator::ValidateStatusLine(status_line); |
| 1143 UMA_HISTOGRAM_ENUMERATION("Net.HttpStatusLineStatus", status, | 1143 UMA_HISTOGRAM_ENUMERATION("Net.HttpStatusLineStatus", status, |
| 1144 HttpStatusLineValidator::STATUS_LINE_MAX); | 1144 HttpStatusLineValidator::STATUS_LINE_MAX); |
| 1145 } | 1145 } |
| 1146 | 1146 |
| 1147 } // namespace net | 1147 } // namespace net |
| OLD | NEW |