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 <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 587 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 598 truncated_in_header_reads, | 598 truncated_in_header_reads, |
| 599 truncated_after_header_reads, | 599 truncated_after_header_reads, |
| 600 truncated_after_final_newline_reads, | 600 truncated_after_final_newline_reads, |
| 601 not_truncated_reads, | 601 not_truncated_reads, |
| 602 }; | 602 }; |
| 603 | 603 |
| 604 MockWrite writes[] = { | 604 MockWrite writes[] = { |
| 605 MockWrite(SYNCHRONOUS, 0, "GET / HTTP/1.1\r\n\r\n"), | 605 MockWrite(SYNCHRONOUS, 0, "GET / HTTP/1.1\r\n\r\n"), |
| 606 }; | 606 }; |
| 607 | 607 |
| 608 enum { | 608 for (size_t i = 0; i < arraysize(reads); i++) { |
| 609 HTTP = 0, | 609 SCOPED_TRACE(i); |
| 610 HTTPS, | 610 SequencedSocketData data(reads[i], 2, writes, arraysize(writes)); |
| 611 NUM_PROTOCOLS, | 611 scoped_ptr<ClientSocketHandle> socket_handle( |
|
davidben
2015/07/31 21:32:50
[Confirmed there are no other interesting HTTP vs
| |
| 612 }; | 612 CreateConnectedSocketHandle(&data)); |
| 613 | 613 |
| 614 for (size_t protocol = 0; protocol < NUM_PROTOCOLS; protocol++) { | 614 HttpRequestInfo request_info; |
| 615 SCOPED_TRACE(protocol); | 615 request_info.url = GURL("http://localhost"); |
| 616 | 616 |
| 617 for (size_t i = 0; i < arraysize(reads); i++) { | 617 scoped_refptr<GrowableIOBuffer> read_buffer(new GrowableIOBuffer); |
| 618 SCOPED_TRACE(i); | 618 HttpStreamParser parser(socket_handle.get(), &request_info, |
| 619 SequencedSocketData data(reads[i], 2, writes, arraysize(writes)); | 619 read_buffer.get(), BoundNetLog()); |
| 620 scoped_ptr<ClientSocketHandle> socket_handle( | |
| 621 CreateConnectedSocketHandle(&data)); | |
| 622 | 620 |
| 623 HttpRequestInfo request_info; | 621 HttpRequestHeaders request_headers; |
| 624 request_info.method = "GET"; | 622 HttpResponseInfo response_info; |
| 625 if (protocol == HTTP) { | 623 TestCompletionCallback callback; |
| 626 request_info.url = GURL("http://localhost"); | 624 ASSERT_EQ(OK, parser.SendRequest("GET / HTTP/1.1\r\n", request_headers, |
| 627 } else { | 625 &response_info, callback.callback())); |
| 628 request_info.url = GURL("https://localhost"); | |
| 629 } | |
| 630 request_info.load_flags = LOAD_NORMAL; | |
| 631 | 626 |
| 632 scoped_refptr<GrowableIOBuffer> read_buffer(new GrowableIOBuffer); | 627 int rv = parser.ReadResponseHeaders(callback.callback()); |
| 633 HttpStreamParser parser( | 628 if (i == arraysize(reads) - 1) { |
| 634 socket_handle.get(), &request_info, read_buffer.get(), BoundNetLog()); | 629 EXPECT_EQ(OK, rv); |
| 635 | 630 EXPECT_TRUE(response_info.headers.get()); |
| 636 HttpRequestHeaders request_headers; | 631 } else { |
| 637 HttpResponseInfo response_info; | 632 EXPECT_EQ(ERR_RESPONSE_HEADERS_TRUNCATED, rv); |
| 638 TestCompletionCallback callback; | 633 EXPECT_FALSE(response_info.headers.get()); |
| 639 ASSERT_EQ(OK, parser.SendRequest("GET / HTTP/1.1\r\n", request_headers, | |
| 640 &response_info, callback.callback())); | |
| 641 | |
| 642 int rv = parser.ReadResponseHeaders(callback.callback()); | |
| 643 if (i == arraysize(reads) - 1) { | |
| 644 EXPECT_EQ(OK, rv); | |
| 645 EXPECT_TRUE(response_info.headers.get()); | |
| 646 } else { | |
| 647 if (protocol == HTTP) { | |
| 648 EXPECT_EQ(ERR_CONNECTION_CLOSED, rv); | |
| 649 EXPECT_TRUE(response_info.headers.get()); | |
| 650 } else { | |
| 651 EXPECT_EQ(ERR_RESPONSE_HEADERS_TRUNCATED, rv); | |
| 652 EXPECT_FALSE(response_info.headers.get()); | |
| 653 } | |
| 654 } | |
| 655 } | 634 } |
| 656 } | 635 } |
| 657 } | 636 } |
| 658 | 637 |
| 659 // Confirm that on 101 response, the headers are parsed but the data that | 638 // Confirm that on 101 response, the headers are parsed but the data that |
| 660 // follows remains in the buffer. | 639 // follows remains in the buffer. |
| 661 TEST(HttpStreamParser, Websocket101Response) { | 640 TEST(HttpStreamParser, Websocket101Response) { |
| 662 MockRead reads[] = { | 641 MockRead reads[] = { |
| 663 MockRead(SYNCHRONOUS, 1, | 642 MockRead(SYNCHRONOUS, 1, |
| 664 "HTTP/1.1 101 Switching Protocols\r\n" | 643 "HTTP/1.1 101 Switching Protocols\r\n" |
| (...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1049 response_info.reset(); | 1028 response_info.reset(); |
| 1050 | 1029 |
| 1051 scoped_refptr<IOBuffer> body_buffer(new IOBuffer(kBodySize)); | 1030 scoped_refptr<IOBuffer> body_buffer(new IOBuffer(kBodySize)); |
| 1052 ASSERT_EQ(kBodySize, parser.ReadResponseBody( | 1031 ASSERT_EQ(kBodySize, parser.ReadResponseBody( |
| 1053 body_buffer.get(), kBodySize, callback.callback())); | 1032 body_buffer.get(), kBodySize, callback.callback())); |
| 1054 } | 1033 } |
| 1055 | 1034 |
| 1056 } // namespace | 1035 } // namespace |
| 1057 | 1036 |
| 1058 } // namespace net | 1037 } // namespace net |
| OLD | NEW |