Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(490)

Side by Side Diff: net/http/http_stream_parser.cc

Issue 2007013003: Introduce error handling in HttpStreamParser on UploadDataStream::Read() failure. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: added upload_data_stream.cc/h in order to be able to land the cl Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/base/upload_data_stream.cc ('k') | net/http/http_stream_parser_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 request_headers_ = new DrainableIOBuffer( 288 request_headers_ = new DrainableIOBuffer(
289 merged_request_headers_and_body.get(), merged_size); 289 merged_request_headers_and_body.get(), merged_size);
290 290
291 memcpy(request_headers_->data(), request.data(), request_headers_length_); 291 memcpy(request_headers_->data(), request.data(), request_headers_length_);
292 request_headers_->DidConsume(request_headers_length_); 292 request_headers_->DidConsume(request_headers_length_);
293 293
294 uint64_t todo = request_->upload_data_stream->size(); 294 uint64_t todo = request_->upload_data_stream->size();
295 while (todo) { 295 while (todo) {
296 int consumed = request_->upload_data_stream->Read( 296 int consumed = request_->upload_data_stream->Read(
297 request_headers_.get(), static_cast<int>(todo), CompletionCallback()); 297 request_headers_.get(), static_cast<int>(todo), CompletionCallback());
298 DCHECK_GT(consumed, 0); // Read() won't fail if not chunked. 298 // Read() must succeed synchronously if not chunked and in memory.
299 DCHECK_GT(consumed, 0);
299 request_headers_->DidConsume(consumed); 300 request_headers_->DidConsume(consumed);
300 todo -= consumed; 301 todo -= consumed;
301 } 302 }
302 DCHECK(request_->upload_data_stream->IsEOF()); 303 DCHECK(request_->upload_data_stream->IsEOF());
303 // Reset the offset, so the buffer can be read from the beginning. 304 // Reset the offset, so the buffer can be read from the beginning.
304 request_headers_->SetOffset(0); 305 request_headers_->SetOffset(0);
305 did_merge = true; 306 did_merge = true;
306 307
307 net_log_.AddEvent( 308 net_log_.AddEvent(
308 NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST_BODY, 309 NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST_BODY,
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 sent_bytes_ += result; 544 sent_bytes_ += result;
544 request_body_send_buf_->DidConsume(result); 545 request_body_send_buf_->DidConsume(result);
545 546
546 io_state_ = STATE_SEND_BODY; 547 io_state_ = STATE_SEND_BODY;
547 return OK; 548 return OK;
548 } 549 }
549 550
550 int HttpStreamParser::DoSendRequestReadBodyComplete(int result) { 551 int HttpStreamParser::DoSendRequestReadBodyComplete(int result) {
551 // |result| is the result of read from the request body from the last call to 552 // |result| is the result of read from the request body from the last call to
552 // DoSendBody(). 553 // DoSendBody().
553 DCHECK_GE(result, 0); // There won't be errors. 554 if (result < 0)
555 return result;
554 556
555 // Chunked data needs to be encoded. 557 // Chunked data needs to be encoded.
556 if (request_->upload_data_stream->is_chunked()) { 558 if (request_->upload_data_stream->is_chunked()) {
557 if (result == 0) { // Reached the end. 559 if (result == 0) { // Reached the end.
558 DCHECK(request_->upload_data_stream->IsEOF()); 560 DCHECK(request_->upload_data_stream->IsEOF());
559 sent_last_chunk_ = true; 561 sent_last_chunk_ = true;
560 } 562 }
561 // Encode the buffer as 1 chunk. 563 // Encode the buffer as 1 chunk.
562 const base::StringPiece payload(request_body_read_buf_->data(), result); 564 const base::StringPiece payload(request_body_read_buf_->data(), result);
563 request_body_send_buf_->Clear(); 565 request_body_send_buf_->Clear();
(...skipping 616 matching lines...) Expand 10 before | Expand all | Expand 10 after
1180 } 1182 }
1181 1183
1182 void HttpStreamParser::ValidateStatusLine(const std::string& status_line) { 1184 void HttpStreamParser::ValidateStatusLine(const std::string& status_line) {
1183 HttpStatusLineValidator::StatusLineStatus status = 1185 HttpStatusLineValidator::StatusLineStatus status =
1184 HttpStatusLineValidator::ValidateStatusLine(status_line); 1186 HttpStatusLineValidator::ValidateStatusLine(status_line);
1185 UMA_HISTOGRAM_ENUMERATION("Net.HttpStatusLineStatus", status, 1187 UMA_HISTOGRAM_ENUMERATION("Net.HttpStatusLineStatus", status,
1186 HttpStatusLineValidator::STATUS_LINE_MAX); 1188 HttpStatusLineValidator::STATUS_LINE_MAX);
1187 } 1189 }
1188 1190
1189 } // namespace net 1191 } // namespace net
OLDNEW
« no previous file with comments | « net/base/upload_data_stream.cc ('k') | net/http/http_stream_parser_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698