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

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

Issue 2144803002: Remove HTTP/0.9 support from HttpStreamParser. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update comments Created 4 years, 5 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/net_error_list.h ('k') | 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 717 matching lines...) Expand 10 before | Expand all | Expand 10 after
728 } 728 }
729 729
730 // Response with no status line. 730 // Response with no status line.
731 TEST_P(HttpNetworkTransactionTest, SimpleGETNoHeaders) { 731 TEST_P(HttpNetworkTransactionTest, SimpleGETNoHeaders) {
732 MockRead data_reads[] = { 732 MockRead data_reads[] = {
733 MockRead("hello world"), 733 MockRead("hello world"),
734 MockRead(SYNCHRONOUS, OK), 734 MockRead(SYNCHRONOUS, OK),
735 }; 735 };
736 SimpleGetHelperResult out = SimpleGetHelper(data_reads, 736 SimpleGetHelperResult out = SimpleGetHelper(data_reads,
737 arraysize(data_reads)); 737 arraysize(data_reads));
738 EXPECT_THAT(out.rv, IsOk()); 738 EXPECT_THAT(out.rv, IsError(ERR_INVALID_HTTP_RESPONSE));
739 EXPECT_EQ("HTTP/0.9 200 OK", out.status_line);
740 EXPECT_EQ("hello world", out.response_data);
741 int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads));
742 EXPECT_EQ(reads_size, out.total_received_bytes);
743 } 739 }
744 740
745 // Allow up to 4 bytes of junk to precede status line. 741 // Allow up to 4 bytes of junk to precede status line.
746 TEST_P(HttpNetworkTransactionTest, StatusLineJunk3Bytes) { 742 TEST_P(HttpNetworkTransactionTest, StatusLineJunk3Bytes) {
747 MockRead data_reads[] = { 743 MockRead data_reads[] = {
748 MockRead("xxxHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), 744 MockRead("xxxHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"),
749 MockRead(SYNCHRONOUS, OK), 745 MockRead(SYNCHRONOUS, OK),
750 }; 746 };
751 SimpleGetHelperResult out = SimpleGetHelper(data_reads, 747 SimpleGetHelperResult out = SimpleGetHelper(data_reads,
752 arraysize(data_reads)); 748 arraysize(data_reads));
(...skipping 12 matching lines...) Expand all
765 }; 761 };
766 SimpleGetHelperResult out = SimpleGetHelper(data_reads, 762 SimpleGetHelperResult out = SimpleGetHelper(data_reads,
767 arraysize(data_reads)); 763 arraysize(data_reads));
768 EXPECT_THAT(out.rv, IsOk()); 764 EXPECT_THAT(out.rv, IsOk());
769 EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); 765 EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line);
770 EXPECT_EQ("DATA", out.response_data); 766 EXPECT_EQ("DATA", out.response_data);
771 int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); 767 int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads));
772 EXPECT_EQ(reads_size, out.total_received_bytes); 768 EXPECT_EQ(reads_size, out.total_received_bytes);
773 } 769 }
774 770
775 // Beyond 4 bytes of slop and it should fail to find a status line. 771 // Beyond 4 bytes of slop and it should fail to find a status line.
eroman 2016/07/14 17:52:08 We should have a bug too about removing the slop b
mmenke 2016/07/14 18:06:46 We have two general bug for cleaning up various ha
776 TEST_P(HttpNetworkTransactionTest, StatusLineJunk5Bytes) { 772 TEST_P(HttpNetworkTransactionTest, StatusLineJunk5Bytes) {
777 MockRead data_reads[] = { 773 MockRead data_reads[] = {
778 MockRead("xxxxxHTTP/1.1 404 Not Found\nServer: blah"), 774 MockRead("xxxxxHTTP/1.1 404 Not Found\nServer: blah"),
779 MockRead(SYNCHRONOUS, OK), 775 MockRead(SYNCHRONOUS, OK),
780 }; 776 };
781 SimpleGetHelperResult out = SimpleGetHelper(data_reads, 777 SimpleGetHelperResult out = SimpleGetHelper(data_reads,
782 arraysize(data_reads)); 778 arraysize(data_reads));
783 EXPECT_THAT(out.rv, IsOk()); 779 EXPECT_THAT(out.rv, IsError(ERR_INVALID_HTTP_RESPONSE));
784 EXPECT_EQ("HTTP/0.9 200 OK", out.status_line);
785 EXPECT_EQ("xxxxxHTTP/1.1 404 Not Found\nServer: blah", out.response_data);
786 int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads));
787 EXPECT_EQ(reads_size, out.total_received_bytes);
788 } 780 }
789 781
790 // Same as StatusLineJunk4Bytes, except the read chunks are smaller. 782 // Same as StatusLineJunk4Bytes, except the read chunks are smaller.
791 TEST_P(HttpNetworkTransactionTest, StatusLineJunk4Bytes_Slow) { 783 TEST_P(HttpNetworkTransactionTest, StatusLineJunk4Bytes_Slow) {
792 MockRead data_reads[] = { 784 MockRead data_reads[] = {
793 MockRead("\n"), 785 MockRead("\n"),
794 MockRead("\n"), 786 MockRead("\n"),
795 MockRead("Q"), 787 MockRead("Q"),
796 MockRead("J"), 788 MockRead("J"),
797 MockRead("HTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), 789 MockRead("HTTP/1.0 404 Not Found\nServer: blah\n\nDATA"),
798 MockRead(SYNCHRONOUS, OK), 790 MockRead(SYNCHRONOUS, OK),
799 }; 791 };
800 SimpleGetHelperResult out = SimpleGetHelper(data_reads, 792 SimpleGetHelperResult out = SimpleGetHelper(data_reads,
801 arraysize(data_reads)); 793 arraysize(data_reads));
802 EXPECT_THAT(out.rv, IsOk()); 794 EXPECT_THAT(out.rv, IsOk());
803 EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); 795 EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line);
804 EXPECT_EQ("DATA", out.response_data); 796 EXPECT_EQ("DATA", out.response_data);
805 int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); 797 int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads));
806 EXPECT_EQ(reads_size, out.total_received_bytes); 798 EXPECT_EQ(reads_size, out.total_received_bytes);
807 } 799 }
808 800
809 // Close the connection before enough bytes to have a status line. 801 // Close the connection before enough bytes to have a status line.
810 TEST_P(HttpNetworkTransactionTest, StatusLinePartial) { 802 TEST_P(HttpNetworkTransactionTest, StatusLinePartial) {
811 MockRead data_reads[] = { 803 MockRead data_reads[] = {
812 MockRead("HTT"), 804 MockRead("HTT"),
813 MockRead(SYNCHRONOUS, OK), 805 MockRead(SYNCHRONOUS, OK),
814 }; 806 };
815 SimpleGetHelperResult out = SimpleGetHelper(data_reads, 807 SimpleGetHelperResult out = SimpleGetHelper(data_reads,
816 arraysize(data_reads)); 808 arraysize(data_reads));
817 EXPECT_THAT(out.rv, IsOk()); 809 EXPECT_THAT(out.rv, IsError(ERR_INVALID_HTTP_RESPONSE));
818 EXPECT_EQ("HTTP/0.9 200 OK", out.status_line);
819 EXPECT_EQ("HTT", out.response_data);
820 int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads));
821 EXPECT_EQ(reads_size, out.total_received_bytes);
822 } 810 }
823 811
824 // Simulate a 204 response, lacking a Content-Length header, sent over a 812 // Simulate a 204 response, lacking a Content-Length header, sent over a
825 // persistent connection. The response should still terminate since a 204 813 // persistent connection. The response should still terminate since a 204
826 // cannot have a response body. 814 // cannot have a response body.
827 TEST_P(HttpNetworkTransactionTest, StopsReading204) { 815 TEST_P(HttpNetworkTransactionTest, StopsReading204) {
828 char junk[] = "junk"; 816 char junk[] = "junk";
829 MockRead data_reads[] = { 817 MockRead data_reads[] = {
830 MockRead("HTTP/1.1 204 No Content\r\n\r\n"), 818 MockRead("HTTP/1.1 204 No Content\r\n\r\n"),
831 MockRead(junk), // Should not be read!! 819 MockRead(junk), // Should not be read!!
(...skipping 10341 matching lines...) Expand 10 before | Expand all | Expand 10 after
11173 never_finishing_connect); 11161 never_finishing_connect);
11174 session_deps_.socket_factory->AddSocketDataProvider( 11162 session_deps_.socket_factory->AddSocketDataProvider(
11175 &hanging_non_alternate_protocol_socket); 11163 &hanging_non_alternate_protocol_socket);
11176 11164
11177 TestCompletionCallback callback; 11165 TestCompletionCallback callback;
11178 11166
11179 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); 11167 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_));
11180 std::unique_ptr<HttpTransaction> trans( 11168 std::unique_ptr<HttpTransaction> trans(
11181 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); 11169 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
11182 11170
11171 // HTTP/0.9 should fail.
11183 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); 11172 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
11184 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); 11173 EXPECT_THAT(callback.GetResult(rv), IsError(ERR_INVALID_HTTP_RESPONSE));
11185 EXPECT_THAT(callback.WaitForResult(), IsOk());
11186
11187 const HttpResponseInfo* response = trans->GetResponseInfo();
11188 ASSERT_TRUE(response);
11189 ASSERT_TRUE(response->headers);
11190 EXPECT_EQ("HTTP/0.9 200 OK", response->headers->GetStatusLine());
11191 EXPECT_FALSE(response->was_fetched_via_spdy);
11192 EXPECT_TRUE(response->was_npn_negotiated);
11193
11194 std::string response_data;
11195 ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk());
11196 EXPECT_EQ("hello world", response_data);
11197 11174
11198 trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); 11175 trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
11199 11176
11200 rv = trans->Start(&request, callback.callback(), BoundNetLog()); 11177 rv = trans->Start(&request, callback.callback(), BoundNetLog());
11201 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); 11178 EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
11202 EXPECT_THAT(callback.WaitForResult(), IsOk()); 11179 EXPECT_THAT(callback.WaitForResult(), IsOk());
11203 11180
11204 response = trans->GetResponseInfo(); 11181 const HttpResponseInfo* response = trans->GetResponseInfo();
11205 ASSERT_TRUE(response); 11182 ASSERT_TRUE(response);
11206 ASSERT_TRUE(response->headers); 11183 ASSERT_TRUE(response->headers);
11207 EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); 11184 EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine());
11208 EXPECT_TRUE(response->was_fetched_via_spdy); 11185 EXPECT_TRUE(response->was_fetched_via_spdy);
11209 EXPECT_TRUE(response->was_npn_negotiated); 11186 EXPECT_TRUE(response->was_npn_negotiated);
11210 11187
11188 std::string response_data;
11211 ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); 11189 ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk());
11212 EXPECT_EQ("hello!", response_data); 11190 EXPECT_EQ("hello!", response_data);
11213 ASSERT_EQ(2u, capturing_proxy_resolver.resolved().size()); 11191 ASSERT_EQ(2u, capturing_proxy_resolver.resolved().size());
11214 EXPECT_EQ("https://www.example.org/", 11192 EXPECT_EQ("https://www.example.org/",
11215 capturing_proxy_resolver.resolved()[0].spec()); 11193 capturing_proxy_resolver.resolved()[0].spec());
11216 EXPECT_EQ("https://www.example.org/", 11194 EXPECT_EQ("https://www.example.org/",
11217 capturing_proxy_resolver.resolved()[1].spec()); 11195 capturing_proxy_resolver.resolved()[1].spec());
11218 11196
11219 LoadTimingInfo load_timing_info; 11197 LoadTimingInfo load_timing_info;
11220 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); 11198 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info));
(...skipping 4640 matching lines...) Expand 10 before | Expand all | Expand 10 after
15861 base::RunLoop().RunUntilIdle(); 15839 base::RunLoop().RunUntilIdle();
15862 15840
15863 EXPECT_TRUE(trans.GetResponseInfo()->was_fetched_via_spdy); 15841 EXPECT_TRUE(trans.GetResponseInfo()->was_fetched_via_spdy);
15864 HttpRequestHeaders headers; 15842 HttpRequestHeaders headers;
15865 ASSERT_TRUE(trans.GetFullRequestHeaders(&headers)); 15843 ASSERT_TRUE(trans.GetFullRequestHeaders(&headers));
15866 EXPECT_TRUE(headers.HasHeader(HttpRequestHeaders::kTokenBinding)); 15844 EXPECT_TRUE(headers.HasHeader(HttpRequestHeaders::kTokenBinding));
15867 } 15845 }
15868 #endif // !defined(OS_IOS) 15846 #endif // !defined(OS_IOS)
15869 15847
15870 } // namespace net 15848 } // namespace net
OLDNEW
« no previous file with comments | « net/base/net_error_list.h ('k') | net/http/http_stream_parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698