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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 // There's at least one |field_name| header. Check if there are any more | 67 // There's at least one |field_name| header. Check if there are any more |
68 // such headers, and if so, return true if they have different values. | 68 // such headers, and if so, return true if they have different values. |
69 std::string field_value2; | 69 std::string field_value2; |
70 while (headers.EnumerateHeader(&it, field_name, &field_value2)) { | 70 while (headers.EnumerateHeader(&it, field_name, &field_value2)) { |
71 if (field_value != field_value2) | 71 if (field_value != field_value2) |
72 return true; | 72 return true; |
73 } | 73 } |
74 return false; | 74 return false; |
75 } | 75 } |
76 | 76 |
77 base::Value* NetLogSendRequestBodyCallback( | 77 scoped_ptr<base::Value> NetLogSendRequestBodyCallback( |
78 uint64 length, | 78 uint64 length, |
79 bool is_chunked, | 79 bool is_chunked, |
80 bool did_merge, | 80 bool did_merge, |
81 NetLogCaptureMode /* capture_mode */) { | 81 NetLogCaptureMode /* capture_mode */) { |
82 base::DictionaryValue* dict = new base::DictionaryValue(); | 82 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
83 dict->SetInteger("length", static_cast<int>(length)); | 83 dict->SetInteger("length", static_cast<int>(length)); |
84 dict->SetBoolean("is_chunked", is_chunked); | 84 dict->SetBoolean("is_chunked", is_chunked); |
85 dict->SetBoolean("did_merge", did_merge); | 85 dict->SetBoolean("did_merge", did_merge); |
86 return dict; | 86 return dict.Pass(); |
87 } | 87 } |
88 | 88 |
89 // Returns true if |error_code| is an error for which we give the server a | 89 // Returns true if |error_code| is an error for which we give the server a |
90 // chance to send a body containing error information, if the error was received | 90 // chance to send a body containing error information, if the error was received |
91 // while trying to upload a request body. | 91 // while trying to upload a request body. |
92 bool ShouldTryReadingOnUploadError(int error_code) { | 92 bool ShouldTryReadingOnUploadError(int error_code) { |
93 return (error_code == ERR_CONNECTION_RESET); | 93 return (error_code == ERR_CONNECTION_RESET); |
94 } | 94 } |
95 | 95 |
96 } // namespace | 96 } // namespace |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 request_headers_.get(), static_cast<int>(todo), CompletionCallback()); | 287 request_headers_.get(), static_cast<int>(todo), CompletionCallback()); |
288 DCHECK_GT(consumed, 0); // Read() won't fail if not chunked. | 288 DCHECK_GT(consumed, 0); // Read() won't fail if not chunked. |
289 request_headers_->DidConsume(consumed); | 289 request_headers_->DidConsume(consumed); |
290 todo -= consumed; | 290 todo -= consumed; |
291 } | 291 } |
292 DCHECK(request_->upload_data_stream->IsEOF()); | 292 DCHECK(request_->upload_data_stream->IsEOF()); |
293 // Reset the offset, so the buffer can be read from the beginning. | 293 // Reset the offset, so the buffer can be read from the beginning. |
294 request_headers_->SetOffset(0); | 294 request_headers_->SetOffset(0); |
295 did_merge = true; | 295 did_merge = true; |
296 | 296 |
297 net_log_.AddEvent( | 297 net_log_.AddEvent(NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST_BODY, |
298 NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST_BODY, | 298 base::Bind(NetLogSendRequestBodyCallback, |
299 base::Bind(&NetLogSendRequestBodyCallback, | 299 request_->upload_data_stream->size(), |
300 request_->upload_data_stream->size(), | 300 false, /* not chunked */ |
301 false, /* not chunked */ | 301 true /* merged */)); |
302 true /* merged */)); | |
303 } | 302 } |
304 | 303 |
305 if (!did_merge) { | 304 if (!did_merge) { |
306 // If we didn't merge the body with the headers, then |request_headers_| | 305 // If we didn't merge the body with the headers, then |request_headers_| |
307 // contains just the HTTP headers. | 306 // contains just the HTTP headers. |
308 scoped_refptr<StringIOBuffer> headers_io_buf(new StringIOBuffer(request)); | 307 scoped_refptr<StringIOBuffer> headers_io_buf(new StringIOBuffer(request)); |
309 request_headers_ = | 308 request_headers_ = |
310 new DrainableIOBuffer(headers_io_buf.get(), headers_io_buf->size()); | 309 new DrainableIOBuffer(headers_io_buf.get(), headers_io_buf->size()); |
311 } | 310 } |
312 | 311 |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
474 if (request_headers_->BytesRemaining() > 0) { | 473 if (request_headers_->BytesRemaining() > 0) { |
475 io_state_ = STATE_SEND_HEADERS; | 474 io_state_ = STATE_SEND_HEADERS; |
476 return OK; | 475 return OK; |
477 } | 476 } |
478 | 477 |
479 if (request_->upload_data_stream != NULL && | 478 if (request_->upload_data_stream != NULL && |
480 (request_->upload_data_stream->is_chunked() || | 479 (request_->upload_data_stream->is_chunked() || |
481 // !IsEOF() indicates that the body wasn't merged. | 480 // !IsEOF() indicates that the body wasn't merged. |
482 (request_->upload_data_stream->size() > 0 && | 481 (request_->upload_data_stream->size() > 0 && |
483 !request_->upload_data_stream->IsEOF()))) { | 482 !request_->upload_data_stream->IsEOF()))) { |
484 net_log_.AddEvent( | 483 net_log_.AddEvent(NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST_BODY, |
485 NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST_BODY, | 484 base::Bind(NetLogSendRequestBodyCallback, |
486 base::Bind(&NetLogSendRequestBodyCallback, | 485 request_->upload_data_stream->size(), |
487 request_->upload_data_stream->size(), | 486 request_->upload_data_stream->is_chunked(), |
488 request_->upload_data_stream->is_chunked(), | 487 false /* not merged */)); |
489 false /* not merged */)); | |
490 io_state_ = STATE_SEND_BODY; | 488 io_state_ = STATE_SEND_BODY; |
491 return OK; | 489 return OK; |
492 } | 490 } |
493 | 491 |
494 // Finished sending the request. | 492 // Finished sending the request. |
495 return OK; | 493 return OK; |
496 } | 494 } |
497 | 495 |
498 int HttpStreamParser::DoSendBody() { | 496 int HttpStreamParser::DoSendBody() { |
499 if (request_body_send_buf_->BytesRemaining() > 0) { | 497 if (request_body_send_buf_->BytesRemaining() > 0) { |
(...skipping 588 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1088 request_body->IsInMemory() && | 1086 request_body->IsInMemory() && |
1089 request_body->size() > 0) { | 1087 request_body->size() > 0) { |
1090 uint64 merged_size = request_headers.size() + request_body->size(); | 1088 uint64 merged_size = request_headers.size() + request_body->size(); |
1091 if (merged_size <= kMaxMergedHeaderAndBodySize) | 1089 if (merged_size <= kMaxMergedHeaderAndBodySize) |
1092 return true; | 1090 return true; |
1093 } | 1091 } |
1094 return false; | 1092 return false; |
1095 } | 1093 } |
1096 | 1094 |
1097 } // namespace net | 1095 } // namespace net |
OLD | NEW |