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

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

Issue 2253653002: Only allow HTTP/0.9 support on default ports. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Response to comments Created 4 years, 3 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/http/http_network_session.cc ('k') | net/http/http_stream_factory_impl_job.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 690 matching lines...) Expand 10 before | Expand all | Expand 10 after
701 }; 701 };
702 SimpleGetHelperResult out = SimpleGetHelper(data_reads, 702 SimpleGetHelperResult out = SimpleGetHelper(data_reads,
703 arraysize(data_reads)); 703 arraysize(data_reads));
704 EXPECT_THAT(out.rv, IsOk()); 704 EXPECT_THAT(out.rv, IsOk());
705 EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); 705 EXPECT_EQ("HTTP/0.9 200 OK", out.status_line);
706 EXPECT_EQ("hello world", out.response_data); 706 EXPECT_EQ("hello world", out.response_data);
707 int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); 707 int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads));
708 EXPECT_EQ(reads_size, out.total_received_bytes); 708 EXPECT_EQ(reads_size, out.total_received_bytes);
709 } 709 }
710 710
711 // Response with no status line, and a weird port. Should fail by default.
712 TEST_F(HttpNetworkTransactionTest, SimpleGETNoHeadersWeirdPort) {
713 MockRead data_reads[] = {
714 MockRead("hello world"), MockRead(SYNCHRONOUS, OK),
715 };
716
717 StaticSocketDataProvider data(data_reads, arraysize(data_reads), nullptr, 0);
718 session_deps_.socket_factory->AddSocketDataProvider(&data);
719
720 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_));
721
722 std::unique_ptr<HttpTransaction> trans(
723 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
724
725 HttpRequestInfo request;
726 request.method = "GET";
727 request.url = GURL("http://www.example.com:2000/");
728 TestCompletionCallback callback;
729 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
730 EXPECT_THAT(callback.GetResult(rv), IsError(ERR_INVALID_HTTP_RESPONSE));
731 }
732
733 // Response with no status line, and a weird port. Option to allow weird ports
734 // enabled.
735 TEST_F(HttpNetworkTransactionTest, SimpleGETNoHeadersWeirdPortAllowed) {
736 MockRead data_reads[] = {
737 MockRead("hello world"), MockRead(SYNCHRONOUS, OK),
738 };
739
740 StaticSocketDataProvider data(data_reads, arraysize(data_reads), nullptr, 0);
741 session_deps_.socket_factory->AddSocketDataProvider(&data);
742 session_deps_.http_09_on_non_default_ports_enabled = true;
743 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_));
744
745 std::unique_ptr<HttpTransaction> trans(
746 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
747
748 HttpRequestInfo request;
749 request.method = "GET";
750 request.url = GURL("http://www.example.com:2000/");
751 TestCompletionCallback callback;
752 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
753 EXPECT_THAT(callback.GetResult(rv), IsOk());
754
755 const HttpResponseInfo* info = trans->GetResponseInfo();
756 ASSERT_TRUE(info->headers);
757 EXPECT_EQ("HTTP/0.9 200 OK", info->headers->GetStatusLine());
758
759 // Don't bother to read the body - that's verified elsewhere, important thing
760 // is that the option to allow HTTP/0.9 on non-default ports is respected.
761 }
762
711 // Allow up to 4 bytes of junk to precede status line. 763 // Allow up to 4 bytes of junk to precede status line.
712 TEST_F(HttpNetworkTransactionTest, StatusLineJunk3Bytes) { 764 TEST_F(HttpNetworkTransactionTest, StatusLineJunk3Bytes) {
713 MockRead data_reads[] = { 765 MockRead data_reads[] = {
714 MockRead("xxxHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), 766 MockRead("xxxHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"),
715 MockRead(SYNCHRONOUS, OK), 767 MockRead(SYNCHRONOUS, OK),
716 }; 768 };
717 SimpleGetHelperResult out = SimpleGetHelper(data_reads, 769 SimpleGetHelperResult out = SimpleGetHelper(data_reads,
718 arraysize(data_reads)); 770 arraysize(data_reads));
719 EXPECT_THAT(out.rv, IsOk()); 771 EXPECT_THAT(out.rv, IsOk());
720 EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); 772 EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line);
(...skipping 13568 matching lines...) Expand 10 before | Expand all | Expand 10 after
14289 DISALLOW_COPY_AND_ASSIGN(FakeStreamFactory); 14341 DISALLOW_COPY_AND_ASSIGN(FakeStreamFactory);
14290 }; 14342 };
14291 14343
14292 // TODO(ricea): Maybe unify this with the one in 14344 // TODO(ricea): Maybe unify this with the one in
14293 // url_request_http_job_unittest.cc ? 14345 // url_request_http_job_unittest.cc ?
14294 class FakeWebSocketBasicHandshakeStream : public WebSocketHandshakeStreamBase { 14346 class FakeWebSocketBasicHandshakeStream : public WebSocketHandshakeStreamBase {
14295 public: 14347 public:
14296 FakeWebSocketBasicHandshakeStream( 14348 FakeWebSocketBasicHandshakeStream(
14297 std::unique_ptr<ClientSocketHandle> connection, 14349 std::unique_ptr<ClientSocketHandle> connection,
14298 bool using_proxy) 14350 bool using_proxy)
14299 : state_(std::move(connection), using_proxy) {} 14351 : state_(std::move(connection), using_proxy, false) {}
14300 14352
14301 // Fake implementation of HttpStreamBase methods. 14353 // Fake implementation of HttpStreamBase methods.
14302 // This ends up being quite "real" because this object has to really send data 14354 // This ends up being quite "real" because this object has to really send data
14303 // on the mock socket. It might be easier to use the real implementation, but 14355 // on the mock socket. It might be easier to use the real implementation, but
14304 // the fact that the WebSocket code is not compiled on iOS makes that 14356 // the fact that the WebSocket code is not compiled on iOS makes that
14305 // difficult. 14357 // difficult.
14306 int InitializeStream(const HttpRequestInfo* request_info, 14358 int InitializeStream(const HttpRequestInfo* request_info,
14307 RequestPriority priority, 14359 RequestPriority priority,
14308 const BoundNetLog& net_log, 14360 const BoundNetLog& net_log,
14309 const CompletionCallback& callback) override { 14361 const CompletionCallback& callback) override {
(...skipping 1211 matching lines...) Expand 10 before | Expand all | Expand 10 after
15521 base::RunLoop().RunUntilIdle(); 15573 base::RunLoop().RunUntilIdle();
15522 15574
15523 EXPECT_TRUE(trans.GetResponseInfo()->was_fetched_via_spdy); 15575 EXPECT_TRUE(trans.GetResponseInfo()->was_fetched_via_spdy);
15524 HttpRequestHeaders headers; 15576 HttpRequestHeaders headers;
15525 ASSERT_TRUE(trans.GetFullRequestHeaders(&headers)); 15577 ASSERT_TRUE(trans.GetFullRequestHeaders(&headers));
15526 EXPECT_TRUE(headers.HasHeader(HttpRequestHeaders::kTokenBinding)); 15578 EXPECT_TRUE(headers.HasHeader(HttpRequestHeaders::kTokenBinding));
15527 } 15579 }
15528 #endif // !defined(OS_IOS) 15580 #endif // !defined(OS_IOS)
15529 15581
15530 } // namespace net 15582 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_network_session.cc ('k') | net/http/http_stream_factory_impl_job.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698