Chromium Code Reviews| 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/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "net/base/address_list.h" | 10 #include "net/base/address_list.h" |
| (...skipping 644 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 655 // Check to see if we're done reading. | 655 // Check to see if we're done reading. |
| 656 if (IsResponseBodyComplete()) | 656 if (IsResponseBodyComplete()) |
| 657 return 0; | 657 return 0; |
| 658 | 658 |
| 659 DCHECK_EQ(0, read_buf_->offset()); | 659 DCHECK_EQ(0, read_buf_->offset()); |
| 660 return connection_->socket()->Read(user_read_buf_, user_read_buf_len_, | 660 return connection_->socket()->Read(user_read_buf_, user_read_buf_len_, |
| 661 io_callback_); | 661 io_callback_); |
| 662 } | 662 } |
| 663 | 663 |
| 664 int HttpStreamParser::DoReadBodyComplete(int result) { | 664 int HttpStreamParser::DoReadBodyComplete(int result) { |
| 665 // If we didn't get a Content-Length and aren't using a chunked encoding, | 665 // When the connection is closed, there are numerous ways to interpret it. |
| 666 // the only way to signal the end of a stream is to close the connection, | 666 // |
| 667 // so we don't treat that as an error, though in some cases we may not | 667 // - If a Content-Length header is present and the body contains exactly that |
| 668 // have completely received the resource. | 668 // number of bytes at connection close, the response is successful. |
| 669 if (result == 0 && !IsResponseBodyComplete() && CanFindEndOfResponse()) | 669 // |
| 670 result = ERR_CONNECTION_CLOSED; | 670 // - If a Content-Length header is present and the body contains fewer bytes |
| 671 // than promised by the header at connection close, it may indicate that | |
| 672 // the connection was closed prematurely, or it may indicate that the | |
| 673 // server sent an invalid Content-Length header. Unfortunately, the invalid | |
| 674 // Content-Length header case does occur in practice and other browsers are | |
| 675 // tolerant of it, so this is reported as OK. | |
| 676 // | |
| 677 // - If chunked encoding is used and the terminating chunk has been processed | |
| 678 // when the connection is closed, the response is successful. | |
| 679 // | |
| 680 // - If chunked encoding is used and the terminating chunk has not been | |
| 681 // processed when the connection is closed, it may indicate that the | |
| 682 // connection was closed prematurely or it may indicate that the server | |
| 683 // sent an invalid chunked encoding. We choose to treat it as | |
| 684 // an invalid chunked encoding. | |
| 685 // | |
| 686 // - If a Content-Length is not present and chunked encoding is not used, | |
| 687 // connection close is the only way to signal that the response is | |
| 688 // complete. Unfortunately, this also means that there is no way to detect | |
| 689 // early close of a connection. No error is returned. | |
| 690 if (result == 0 && !IsResponseBodyComplete() && CanFindEndOfResponse()) { | |
| 691 if (chunked_decoder_.get()) | |
| 692 result = ERR_INVALID_CHUNKED_ENCODING; | |
| 693 else | |
| 694 result = ERR_CONNECTION_CLOSED; | |
|
rvargas (doing something else)
2012/03/23 20:50:29
So we still return an error code at this layer in
cbentzel
2012/03/23 21:19:20
Oops, this was a bad local patch that I did to mak
| |
| 695 } | |
| 671 | 696 |
| 672 // Filter incoming data if appropriate. FilterBuf may return an error. | 697 // Filter incoming data if appropriate. FilterBuf may return an error. |
| 673 if (result > 0 && chunked_decoder_.get()) { | 698 if (result > 0 && chunked_decoder_.get()) { |
| 674 result = chunked_decoder_->FilterBuf(user_read_buf_->data(), result); | 699 result = chunked_decoder_->FilterBuf(user_read_buf_->data(), result); |
| 675 if (result == 0 && !chunked_decoder_->reached_eof()) { | 700 if (result == 0 && !chunked_decoder_->reached_eof()) { |
| 676 // Don't signal completion of the Read call yet or else it'll look like | 701 // Don't signal completion of the Read call yet or else it'll look like |
| 677 // we received end-of-file. Wait for more data. | 702 // we received end-of-file. Wait for more data. |
| 678 io_state_ = STATE_READ_BODY; | 703 io_state_ = STATE_READ_BODY; |
| 679 return OK; | 704 return OK; |
| 680 } | 705 } |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 924 request_body->IsInMemory() && | 949 request_body->IsInMemory() && |
| 925 request_body->size() > 0) { | 950 request_body->size() > 0) { |
| 926 size_t merged_size = request_headers.size() + request_body->size(); | 951 size_t merged_size = request_headers.size() + request_body->size(); |
| 927 if (merged_size <= kMaxMergedHeaderAndBodySize) | 952 if (merged_size <= kMaxMergedHeaderAndBodySize) |
| 928 return true; | 953 return true; |
| 929 } | 954 } |
| 930 return false; | 955 return false; |
| 931 } | 956 } |
| 932 | 957 |
| 933 } // namespace net | 958 } // namespace net |
| OLD | NEW |