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

Unified 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, 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/http/http_network_transaction_unittest.cc
diff --git a/net/http/http_network_transaction_unittest.cc b/net/http/http_network_transaction_unittest.cc
index 0bb806c1526a4f7a670a71eee705ee2a35beba3c..c6c44f0aa3c0442866baf338fa09432cfb8105b0 100644
--- a/net/http/http_network_transaction_unittest.cc
+++ b/net/http/http_network_transaction_unittest.cc
@@ -708,6 +708,58 @@ TEST_F(HttpNetworkTransactionTest, SimpleGETNoHeaders) {
EXPECT_EQ(reads_size, out.total_received_bytes);
}
+// Response with no status line, and a weird port. Should fail by default.
+TEST_F(HttpNetworkTransactionTest, SimpleGETNoHeadersWeirdPort) {
+ MockRead data_reads[] = {
+ MockRead("hello world"), MockRead(SYNCHRONOUS, OK),
+ };
+
+ StaticSocketDataProvider data(data_reads, arraysize(data_reads), nullptr, 0);
+ session_deps_.socket_factory->AddSocketDataProvider(&data);
+
+ std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_));
+
+ std::unique_ptr<HttpTransaction> trans(
+ new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
+
+ HttpRequestInfo request;
+ request.method = "GET";
+ request.url = GURL("http://www.example.com:2000/");
+ TestCompletionCallback callback;
+ int rv = trans->Start(&request, callback.callback(), BoundNetLog());
+ EXPECT_THAT(callback.GetResult(rv), IsError(ERR_INVALID_HTTP_RESPONSE));
+}
+
+// Response with no status line, and a weird port. Option to allow weird ports
+// enabled.
+TEST_F(HttpNetworkTransactionTest, SimpleGETNoHeadersWeirdPortAllowed) {
+ MockRead data_reads[] = {
+ MockRead("hello world"), MockRead(SYNCHRONOUS, OK),
+ };
+
+ StaticSocketDataProvider data(data_reads, arraysize(data_reads), nullptr, 0);
+ session_deps_.socket_factory->AddSocketDataProvider(&data);
+ session_deps_.http_09_on_non_default_ports_enabled = true;
+ std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_));
+
+ std::unique_ptr<HttpTransaction> trans(
+ new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
+
+ HttpRequestInfo request;
+ request.method = "GET";
+ request.url = GURL("http://www.example.com:2000/");
+ TestCompletionCallback callback;
+ int rv = trans->Start(&request, callback.callback(), BoundNetLog());
+ EXPECT_THAT(callback.GetResult(rv), IsOk());
+
+ const HttpResponseInfo* info = trans->GetResponseInfo();
+ ASSERT_TRUE(info->headers);
+ EXPECT_EQ("HTTP/0.9 200 OK", info->headers->GetStatusLine());
+
+ // Don't bother to read the body - that's verified elsewhere, important thing
+ // is that the option to allow HTTP/0.9 on non-default ports is respected.
+}
+
// Allow up to 4 bytes of junk to precede status line.
TEST_F(HttpNetworkTransactionTest, StatusLineJunk3Bytes) {
MockRead data_reads[] = {
@@ -14296,7 +14348,7 @@ class FakeWebSocketBasicHandshakeStream : public WebSocketHandshakeStreamBase {
FakeWebSocketBasicHandshakeStream(
std::unique_ptr<ClientSocketHandle> connection,
bool using_proxy)
- : state_(std::move(connection), using_proxy) {}
+ : state_(std::move(connection), using_proxy, false) {}
// Fake implementation of HttpStreamBase methods.
// This ends up being quite "real" because this object has to really send data
« 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