Reset request_ at the end of HttpNetworkTransaction::Start instead of in Read.

Bug: 779919
Cq-Include-Trybots: master.tryserver.chromium.android:android_cronet_tester;master.tryserver.chromium.mac:ios-simulator-cronet
Change-Id: I30a0a94731a4a927b0c5882f3e4384adc886543c
Reviewed-on: https://chromium-review.googlesource.com/749523
Commit-Queue: Shivani Sharma <[email protected]>
Reviewed-by: Matt Menke <[email protected]>
Cr-Commit-Position: refs/heads/master@{#513328}
diff --git a/net/http/http_network_transaction_unittest.cc b/net/http/http_network_transaction_unittest.cc
index 95919a6..82db9806 100644
--- a/net/http/http_network_transaction_unittest.cc
+++ b/net/http/http_network_transaction_unittest.cc
@@ -868,6 +868,35 @@
   EXPECT_THAT(callback.GetResult(rv), IsError(ERR_INVALID_HTTP_RESPONSE));
 }
 
+// Tests that request info can be destroyed after the headers phase is complete.
+TEST_F(HttpNetworkTransactionTest, SimpleGETNoReadDestroyRequestInfo) {
+  std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_));
+  auto trans =
+      std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get());
+
+  MockRead data_reads[] = {
+      MockRead("HTTP/1.0 200 OK\r\n"), MockRead("Connection: keep-alive\r\n"),
+      MockRead("Content-Length: 100\r\n\r\n"), MockRead(SYNCHRONOUS, 0),
+  };
+  StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0);
+  session_deps_.socket_factory->AddSocketDataProvider(&data);
+
+  TestCompletionCallback callback;
+
+  {
+    auto request = std::make_unique<HttpRequestInfo>();
+    request->method = "GET";
+    request->url = GURL("http://www.example.org/");
+
+    int rv =
+        trans->Start(request.get(), callback.callback(), NetLogWithSource());
+
+    EXPECT_THAT(callback.GetResult(rv), IsOk());
+  }  // Let request info be destroyed.
+
+  trans.reset();
+}
+
 // Response with no status line, and a weird port.  Option to allow weird ports
 // enabled.
 TEST_F(HttpNetworkTransactionTest, SimpleGETNoHeadersWeirdPortAllowed) {