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

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

Issue 2247003003: Revert HTTP/0.9 removal (https://codereview.chromium.org/2144803002/) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add back new error code Created 4 years, 4 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 | « no previous file | net/http/http_stream_parser.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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_network_transaction.h" 5 #include "net/http/http_network_transaction.h"
6 6
7 #include <math.h> // ceil 7 #include <math.h> // ceil
8 #include <stdarg.h> 8 #include <stdarg.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
(...skipping 685 matching lines...) Expand 10 before | Expand all | Expand 10 after
696 } 696 }
697 697
698 // Response with no status line. 698 // Response with no status line.
699 TEST_F(HttpNetworkTransactionTest, SimpleGETNoHeaders) { 699 TEST_F(HttpNetworkTransactionTest, SimpleGETNoHeaders) {
700 MockRead data_reads[] = { 700 MockRead data_reads[] = {
701 MockRead("hello world"), 701 MockRead("hello world"),
702 MockRead(SYNCHRONOUS, OK), 702 MockRead(SYNCHRONOUS, OK),
703 }; 703 };
704 SimpleGetHelperResult out = SimpleGetHelper(data_reads, 704 SimpleGetHelperResult out = SimpleGetHelper(data_reads,
705 arraysize(data_reads)); 705 arraysize(data_reads));
706 EXPECT_THAT(out.rv, IsError(ERR_INVALID_HTTP_RESPONSE)); 706 EXPECT_THAT(out.rv, IsOk());
707 EXPECT_EQ("HTTP/0.9 200 OK", out.status_line);
708 EXPECT_EQ("hello world", out.response_data);
709 int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads));
710 EXPECT_EQ(reads_size, out.total_received_bytes);
707 } 711 }
708 712
709 // Allow up to 4 bytes of junk to precede status line. 713 // Allow up to 4 bytes of junk to precede status line.
710 TEST_F(HttpNetworkTransactionTest, StatusLineJunk3Bytes) { 714 TEST_F(HttpNetworkTransactionTest, StatusLineJunk3Bytes) {
711 MockRead data_reads[] = { 715 MockRead data_reads[] = {
712 MockRead("xxxHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), 716 MockRead("xxxHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"),
713 MockRead(SYNCHRONOUS, OK), 717 MockRead(SYNCHRONOUS, OK),
714 }; 718 };
715 SimpleGetHelperResult out = SimpleGetHelper(data_reads, 719 SimpleGetHelperResult out = SimpleGetHelper(data_reads,
716 arraysize(data_reads)); 720 arraysize(data_reads));
(...skipping 20 matching lines...) Expand all
737 } 741 }
738 742
739 // Beyond 4 bytes of slop and it should fail to find a status line. 743 // Beyond 4 bytes of slop and it should fail to find a status line.
740 TEST_F(HttpNetworkTransactionTest, StatusLineJunk5Bytes) { 744 TEST_F(HttpNetworkTransactionTest, StatusLineJunk5Bytes) {
741 MockRead data_reads[] = { 745 MockRead data_reads[] = {
742 MockRead("xxxxxHTTP/1.1 404 Not Found\nServer: blah"), 746 MockRead("xxxxxHTTP/1.1 404 Not Found\nServer: blah"),
743 MockRead(SYNCHRONOUS, OK), 747 MockRead(SYNCHRONOUS, OK),
744 }; 748 };
745 SimpleGetHelperResult out = SimpleGetHelper(data_reads, 749 SimpleGetHelperResult out = SimpleGetHelper(data_reads,
746 arraysize(data_reads)); 750 arraysize(data_reads));
747 EXPECT_THAT(out.rv, IsError(ERR_INVALID_HTTP_RESPONSE)); 751 EXPECT_THAT(out.rv, IsOk());
752 EXPECT_EQ("HTTP/0.9 200 OK", out.status_line);
753 EXPECT_EQ("xxxxxHTTP/1.1 404 Not Found\nServer: blah", out.response_data);
754 int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads));
755 EXPECT_EQ(reads_size, out.total_received_bytes);
748 } 756 }
749 757
750 // Same as StatusLineJunk4Bytes, except the read chunks are smaller. 758 // Same as StatusLineJunk4Bytes, except the read chunks are smaller.
751 TEST_F(HttpNetworkTransactionTest, StatusLineJunk4Bytes_Slow) { 759 TEST_F(HttpNetworkTransactionTest, StatusLineJunk4Bytes_Slow) {
752 MockRead data_reads[] = { 760 MockRead data_reads[] = {
753 MockRead("\n"), 761 MockRead("\n"),
754 MockRead("\n"), 762 MockRead("\n"),
755 MockRead("Q"), 763 MockRead("Q"),
756 MockRead("J"), 764 MockRead("J"),
757 MockRead("HTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), 765 MockRead("HTTP/1.0 404 Not Found\nServer: blah\n\nDATA"),
758 MockRead(SYNCHRONOUS, OK), 766 MockRead(SYNCHRONOUS, OK),
759 }; 767 };
760 SimpleGetHelperResult out = SimpleGetHelper(data_reads, 768 SimpleGetHelperResult out = SimpleGetHelper(data_reads,
761 arraysize(data_reads)); 769 arraysize(data_reads));
762 EXPECT_THAT(out.rv, IsOk()); 770 EXPECT_THAT(out.rv, IsOk());
763 EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); 771 EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line);
764 EXPECT_EQ("DATA", out.response_data); 772 EXPECT_EQ("DATA", out.response_data);
765 int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); 773 int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads));
766 EXPECT_EQ(reads_size, out.total_received_bytes); 774 EXPECT_EQ(reads_size, out.total_received_bytes);
767 } 775 }
768 776
769 // Close the connection before enough bytes to have a status line. 777 // Close the connection before enough bytes to have a status line.
770 TEST_F(HttpNetworkTransactionTest, StatusLinePartial) { 778 TEST_F(HttpNetworkTransactionTest, StatusLinePartial) {
771 MockRead data_reads[] = { 779 MockRead data_reads[] = {
772 MockRead("HTT"), 780 MockRead("HTT"),
773 MockRead(SYNCHRONOUS, OK), 781 MockRead(SYNCHRONOUS, OK),
774 }; 782 };
775 SimpleGetHelperResult out = SimpleGetHelper(data_reads, 783 SimpleGetHelperResult out = SimpleGetHelper(data_reads,
776 arraysize(data_reads)); 784 arraysize(data_reads));
777 EXPECT_THAT(out.rv, IsError(ERR_INVALID_HTTP_RESPONSE)); 785 EXPECT_THAT(out.rv, IsOk());
786 EXPECT_EQ("HTTP/0.9 200 OK", out.status_line);
787 EXPECT_EQ("HTT", out.response_data);
788 int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads));
789 EXPECT_EQ(reads_size, out.total_received_bytes);
778 } 790 }
779 791
780 // Simulate a 204 response, lacking a Content-Length header, sent over a 792 // Simulate a 204 response, lacking a Content-Length header, sent over a
781 // persistent connection. The response should still terminate since a 204 793 // persistent connection. The response should still terminate since a 204
782 // cannot have a response body. 794 // cannot have a response body.
783 TEST_F(HttpNetworkTransactionTest, StopsReading204) { 795 TEST_F(HttpNetworkTransactionTest, StopsReading204) {
784 char junk[] = "junk"; 796 char junk[] = "junk";
785 MockRead data_reads[] = { 797 MockRead data_reads[] = {
786 MockRead("HTTP/1.1 204 No Content\r\n\r\n"), 798 MockRead("HTTP/1.1 204 No Content\r\n\r\n"),
787 MockRead(junk), // Should not be read!! 799 MockRead(junk), // Should not be read!!
(...skipping 10406 matching lines...) Expand 10 before | Expand all | Expand 10 after
11194 never_finishing_connect); 11206 never_finishing_connect);
11195 session_deps_.socket_factory->AddSocketDataProvider( 11207 session_deps_.socket_factory->AddSocketDataProvider(
11196 &hanging_non_alternate_protocol_socket); 11208 &hanging_non_alternate_protocol_socket);
11197 11209
11198 TestCompletionCallback callback; 11210 TestCompletionCallback callback;
11199 11211
11200 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); 11212 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_));
11201 std::unique_ptr<HttpTransaction> trans( 11213 std::unique_ptr<HttpTransaction> trans(
11202 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); 11214 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
11203 11215
11204 // HTTP/0.9 should fail.
11205 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); 11216 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
11206 EXPECT_THAT(callback.GetResult(rv), IsError(ERR_INVALID_HTTP_RESPONSE)); 11217 EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
11218 EXPECT_THAT(callback.WaitForResult(), IsOk());
11219
11220 const HttpResponseInfo* response = trans->GetResponseInfo();
11221 ASSERT_TRUE(response);
11222 ASSERT_TRUE(response->headers);
11223 EXPECT_EQ("HTTP/0.9 200 OK", response->headers->GetStatusLine());
11224 EXPECT_FALSE(response->was_fetched_via_spdy);
11225 EXPECT_TRUE(response->was_npn_negotiated);
11226
11227 std::string response_data;
11228 ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk());
11229 EXPECT_EQ("hello world", response_data);
11207 11230
11208 trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); 11231 trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
11209 11232
11210 rv = trans->Start(&request, callback.callback(), BoundNetLog()); 11233 rv = trans->Start(&request, callback.callback(), BoundNetLog());
11211 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); 11234 EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
11212 EXPECT_THAT(callback.WaitForResult(), IsOk()); 11235 EXPECT_THAT(callback.WaitForResult(), IsOk());
11213 11236
11214 const HttpResponseInfo* response = trans->GetResponseInfo(); 11237 response = trans->GetResponseInfo();
11215 ASSERT_TRUE(response); 11238 ASSERT_TRUE(response);
11216 ASSERT_TRUE(response->headers); 11239 ASSERT_TRUE(response->headers);
11217 EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); 11240 EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine());
11218 EXPECT_TRUE(response->was_fetched_via_spdy); 11241 EXPECT_TRUE(response->was_fetched_via_spdy);
11219 EXPECT_TRUE(response->was_npn_negotiated); 11242 EXPECT_TRUE(response->was_npn_negotiated);
11220 11243
11221 std::string response_data;
11222 ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); 11244 ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk());
11223 EXPECT_EQ("hello!", response_data); 11245 EXPECT_EQ("hello!", response_data);
11224 ASSERT_EQ(2u, capturing_proxy_resolver.resolved().size()); 11246 ASSERT_EQ(2u, capturing_proxy_resolver.resolved().size());
11225 EXPECT_EQ("https://www.example.org/", 11247 EXPECT_EQ("https://www.example.org/",
11226 capturing_proxy_resolver.resolved()[0].spec()); 11248 capturing_proxy_resolver.resolved()[0].spec());
11227 EXPECT_EQ("https://www.example.org/", 11249 EXPECT_EQ("https://www.example.org/",
11228 capturing_proxy_resolver.resolved()[1].spec()); 11250 capturing_proxy_resolver.resolved()[1].spec());
11229 11251
11230 LoadTimingInfo load_timing_info; 11252 LoadTimingInfo load_timing_info;
11231 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); 11253 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info));
(...skipping 4435 matching lines...) Expand 10 before | Expand all | Expand 10 after
15667 base::RunLoop().RunUntilIdle(); 15689 base::RunLoop().RunUntilIdle();
15668 15690
15669 EXPECT_TRUE(trans.GetResponseInfo()->was_fetched_via_spdy); 15691 EXPECT_TRUE(trans.GetResponseInfo()->was_fetched_via_spdy);
15670 HttpRequestHeaders headers; 15692 HttpRequestHeaders headers;
15671 ASSERT_TRUE(trans.GetFullRequestHeaders(&headers)); 15693 ASSERT_TRUE(trans.GetFullRequestHeaders(&headers));
15672 EXPECT_TRUE(headers.HasHeader(HttpRequestHeaders::kTokenBinding)); 15694 EXPECT_TRUE(headers.HasHeader(HttpRequestHeaders::kTokenBinding));
15673 } 15695 }
15674 #endif // !defined(OS_IOS) 15696 #endif // !defined(OS_IOS)
15675 15697
15676 } // namespace net 15698 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | net/http/http_stream_parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698