| 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 for (size_t i = 0; i < arraysize(reads); i++) { | 608 enum { |
| 609 SCOPED_TRACE(i); | 609 HTTP = 0, |
| 610 SequencedSocketData data(reads[i], 2, writes, arraysize(writes)); | 610 HTTPS, |
| 611 scoped_ptr<ClientSocketHandle> socket_handle( | 611 NUM_PROTOCOLS, |
| 612 CreateConnectedSocketHandle(&data)); | 612 }; |
| 613 | 613 |
| 614 HttpRequestInfo request_info; | 614 for (size_t protocol = 0; protocol < NUM_PROTOCOLS; protocol++) { |
| 615 request_info.url = GURL("http://localhost"); | 615 SCOPED_TRACE(protocol); |
| 616 | 616 |
| 617 scoped_refptr<GrowableIOBuffer> read_buffer(new GrowableIOBuffer); | 617 for (size_t i = 0; i < arraysize(reads); i++) { |
| 618 HttpStreamParser parser(socket_handle.get(), &request_info, | 618 SCOPED_TRACE(i); |
| 619 read_buffer.get(), BoundNetLog()); | 619 SequencedSocketData data(reads[i], 2, writes, arraysize(writes)); |
| 620 scoped_ptr<ClientSocketHandle> socket_handle( |
| 621 CreateConnectedSocketHandle(&data)); |
| 620 | 622 |
| 621 HttpRequestHeaders request_headers; | 623 HttpRequestInfo request_info; |
| 622 HttpResponseInfo response_info; | 624 request_info.method = "GET"; |
| 623 TestCompletionCallback callback; | 625 if (protocol == HTTP) { |
| 624 ASSERT_EQ(OK, parser.SendRequest("GET / HTTP/1.1\r\n", request_headers, | 626 request_info.url = GURL("http://localhost"); |
| 625 &response_info, callback.callback())); | 627 } else { |
| 628 request_info.url = GURL("https://localhost"); |
| 629 } |
| 630 request_info.load_flags = LOAD_NORMAL; |
| 626 | 631 |
| 627 int rv = parser.ReadResponseHeaders(callback.callback()); | 632 scoped_refptr<GrowableIOBuffer> read_buffer(new GrowableIOBuffer); |
| 628 if (i == arraysize(reads) - 1) { | 633 HttpStreamParser parser( |
| 629 EXPECT_EQ(OK, rv); | 634 socket_handle.get(), &request_info, read_buffer.get(), BoundNetLog()); |
| 630 EXPECT_TRUE(response_info.headers.get()); | 635 |
| 631 } else { | 636 HttpRequestHeaders request_headers; |
| 632 EXPECT_EQ(ERR_RESPONSE_HEADERS_TRUNCATED, rv); | 637 HttpResponseInfo response_info; |
| 633 EXPECT_FALSE(response_info.headers.get()); | 638 TestCompletionCallback callback; |
| 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 } |
| 634 } | 655 } |
| 635 } | 656 } |
| 636 } | 657 } |
| 637 | 658 |
| 638 // Confirm that on 101 response, the headers are parsed but the data that | 659 // Confirm that on 101 response, the headers are parsed but the data that |
| 639 // follows remains in the buffer. | 660 // follows remains in the buffer. |
| 640 TEST(HttpStreamParser, Websocket101Response) { | 661 TEST(HttpStreamParser, Websocket101Response) { |
| 641 MockRead reads[] = { | 662 MockRead reads[] = { |
| 642 MockRead(SYNCHRONOUS, 1, | 663 MockRead(SYNCHRONOUS, 1, |
| 643 "HTTP/1.1 101 Switching Protocols\r\n" | 664 "HTTP/1.1 101 Switching Protocols\r\n" |
| (...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1028 response_info.reset(); | 1049 response_info.reset(); |
| 1029 | 1050 |
| 1030 scoped_refptr<IOBuffer> body_buffer(new IOBuffer(kBodySize)); | 1051 scoped_refptr<IOBuffer> body_buffer(new IOBuffer(kBodySize)); |
| 1031 ASSERT_EQ(kBodySize, parser.ReadResponseBody( | 1052 ASSERT_EQ(kBodySize, parser.ReadResponseBody( |
| 1032 body_buffer.get(), kBodySize, callback.callback())); | 1053 body_buffer.get(), kBodySize, callback.callback())); |
| 1033 } | 1054 } |
| 1034 | 1055 |
| 1035 } // namespace | 1056 } // namespace |
| 1036 | 1057 |
| 1037 } // namespace net | 1058 } // namespace net |
| OLD | NEW |