Index: net/tools/quic/test_tools/quic_test_client.cc |
diff --git a/net/tools/quic/test_tools/quic_test_client.cc b/net/tools/quic/test_tools/quic_test_client.cc |
index e507965c6021a919c37f6bd5ff65554f5b8396d6..c5918e4b6b5b771256b4cc64cde1c508a5a07955 100644 |
--- a/net/tools/quic/test_tools/quic_test_client.cc |
+++ b/net/tools/quic/test_tools/quic_test_client.cc |
@@ -18,12 +18,12 @@ |
#include "net/quic/core/quic_flags.h" |
#include "net/quic/core/quic_server_id.h" |
#include "net/quic/core/quic_utils.h" |
+#include "net/quic/core/spdy_utils.h" |
#include "net/quic/test_tools/crypto_test_utils.h" |
#include "net/quic/test_tools/quic_connection_peer.h" |
#include "net/quic/test_tools/quic_spdy_session_peer.h" |
#include "net/quic/test_tools/quic_test_utils.h" |
#include "net/quic/test_tools/reliable_quic_stream_peer.h" |
-#include "net/tools/balsa/balsa_headers.h" |
#include "net/tools/quic/quic_epoll_connection_helper.h" |
#include "net/tools/quic/quic_packet_writer_wrapper.h" |
#include "net/tools/quic/quic_spdy_client_stream.h" |
@@ -120,27 +120,6 @@ class RecordingProofVerifier : public ProofVerifier { |
} // anonymous namespace |
-BalsaHeaders* MungeHeaders(const BalsaHeaders* const_headers) { |
- StringPiece uri = const_headers->request_uri(); |
- if (uri.empty()) { |
- return nullptr; |
- } |
- if (const_headers->request_method() == "CONNECT") { |
- return nullptr; |
- } |
- BalsaHeaders* headers = new BalsaHeaders; |
- headers->CopyFrom(*const_headers); |
- if (!base::StartsWith(uri, "https://", |
- base::CompareCase::INSENSITIVE_ASCII) && |
- !base::StartsWith(uri, "http://", base::CompareCase::INSENSITIVE_ASCII)) { |
- // If we have a relative URL, set some defaults. |
- string full_uri = "https://test.example.com"; |
- full_uri.append(uri.as_string()); |
- headers->SetRequestUri(full_uri); |
- } |
- return headers; |
-} |
- |
MockableQuicClient::MockableQuicClient( |
IPEndPoint server_address, |
const QuicServerId& server_id, |
@@ -293,9 +272,11 @@ void QuicTestClient::SetUserAgentID(const string& user_agent_id) { |
} |
ssize_t QuicTestClient::SendRequest(const string& uri) { |
- HTTPMessage message; |
- FillInRequest(uri, &message); |
- return SendMessage(message); |
+ SpdyHeaderBlock headers; |
+ if (!PopulateHeaderBlockFromUrl(uri, &headers)) { |
+ return 0; |
+ } |
+ return SendMessage(headers, ""); |
} |
void QuicTestClient::SendRequestsAndWaitForResponses( |
@@ -309,20 +290,20 @@ void QuicTestClient::SendRequestsAndWaitForResponses( |
} |
ssize_t QuicTestClient::GetOrCreateStreamAndSendRequest( |
- const BalsaHeaders* headers, |
+ const SpdyHeaderBlock* headers, |
StringPiece body, |
bool fin, |
QuicAckListenerInterface* delegate) { |
if (headers) { |
QuicClientPushPromiseIndex::TryHandle* handle; |
- QuicAsyncStatus rv = client()->push_promise_index()->Try( |
- SpdyBalsaUtils::RequestHeadersToSpdyHeaders(*headers), this, &handle); |
+ QuicAsyncStatus rv = |
+ client()->push_promise_index()->Try(*headers, this, &handle); |
if (rv == QUIC_SUCCESS) |
return 1; |
if (rv == QUIC_PENDING) { |
// May need to retry request if asynchronous rendezvous fails. |
- std::unique_ptr<SpdyHeaderBlock> new_headers(new SpdyHeaderBlock( |
- SpdyBalsaUtils::RequestHeadersToSpdyHeaders(*headers))); |
+ std::unique_ptr<SpdyHeaderBlock> new_headers( |
+ new SpdyHeaderBlock(headers->Clone())); |
push_promise_data_to_resend_.reset(new TestClientDataToResend( |
std::move(new_headers), body, fin, this, delegate)); |
return 1; |
@@ -339,18 +320,8 @@ ssize_t QuicTestClient::GetOrCreateStreamAndSendRequest( |
ssize_t ret = 0; |
if (headers != nullptr) { |
- SpdyHeaderBlock spdy_headers = |
- SpdyBalsaUtils::RequestHeadersToSpdyHeaders(*headers); |
- if (headers->HasHeader("transfer-encoding")) { |
- // We have tests which rely on sending a non-standards-compliant |
- // T-E header. |
- string encoding; |
- headers->GetAllOfHeaderAsString("transfer-encoding", &encoding); |
- spdy_headers.insert(std::make_pair("transfer-encoding", encoding)); |
- } |
- auto authority = spdy_headers.find(":authority"); |
- if (authority == spdy_headers.end() || authority->second.empty()) { |
- // HTTP/2 requests should include the :authority pseudo hader. |
+ SpdyHeaderBlock spdy_headers(headers->Clone()); |
+ if (spdy_headers[":authority"].as_string().empty()) { |
spdy_headers[":authority"] = client_->server_id().host(); |
} |
ret = stream->SendRequest(std::move(spdy_headers), body, fin); |
@@ -362,8 +333,7 @@ ssize_t QuicTestClient::GetOrCreateStreamAndSendRequest( |
if (FLAGS_enable_quic_stateless_reject_support) { |
std::unique_ptr<SpdyHeaderBlock> new_headers; |
if (headers) { |
- new_headers.reset(new SpdyHeaderBlock( |
- SpdyBalsaUtils::RequestHeadersToSpdyHeaders(*headers))); |
+ new_headers.reset(new SpdyHeaderBlock(headers->Clone())); |
} |
std::unique_ptr<QuicClientBase::QuicDataToResend> data_to_resend( |
new TestClientDataToResend(std::move(new_headers), body, fin, this, |
@@ -373,7 +343,14 @@ ssize_t QuicTestClient::GetOrCreateStreamAndSendRequest( |
return ret; |
} |
-ssize_t QuicTestClient::SendMessage(const HTTPMessage& message) { |
+ssize_t QuicTestClient::SendMessage(const SpdyHeaderBlock& headers, |
+ StringPiece body) { |
+ return SendMessage(headers, body, /*fin=*/true); |
+} |
+ |
+ssize_t QuicTestClient::SendMessage(const SpdyHeaderBlock& headers, |
+ StringPiece body, |
+ bool fin) { |
stream_ = nullptr; // Always force creation of a stream for SendMessage. |
// Any response we might have received for a previous request would no longer |
// be valid. TODO(jeffpiazza): There's probably additional client state that |
@@ -382,26 +359,14 @@ ssize_t QuicTestClient::SendMessage(const HTTPMessage& message) { |
// If we're not connected, try to find an sni hostname. |
if (!connected()) { |
- GURL url(message.headers()->request_uri()); |
+ GURL url(SpdyUtils::GetUrlFromHeaderBlock(headers)); |
if (override_sni_set_) { |
client_->set_server_id(QuicServerId(override_sni_, url.EffectiveIntPort(), |
PRIVACY_MODE_DISABLED)); |
- } else { |
- if (!url.host().empty()) { |
- client_->set_server_id(QuicServerId(url.host(), url.EffectiveIntPort(), |
- PRIVACY_MODE_DISABLED)); |
- } |
} |
} |
- // TODO(rtenneti): Add support for HTTPMessage::body_chunks(). |
- // CHECK(message.body_chunks().empty()) |
- // << "HTTPMessage::body_chunks not supported"; |
- |
- std::unique_ptr<BalsaHeaders> munged_headers(MungeHeaders(message.headers())); |
- ssize_t ret = GetOrCreateStreamAndSendRequest( |
- (munged_headers.get() ? munged_headers.get() : message.headers()), |
- message.body(), message.has_complete_message(), nullptr); |
+ ssize_t ret = GetOrCreateStreamAndSendRequest(&headers, body, fin, nullptr); |
WaitForWriteToFlush(); |
return ret; |
} |
@@ -438,10 +403,10 @@ const string& QuicTestClient::response_body() { |
} |
string QuicTestClient::SendCustomSynchronousRequest( |
- const HTTPMessage& message) { |
- if (SendMessage(message) == 0) { |
- DLOG(ERROR) << "Failed the request for uri:" |
- << message.headers()->request_uri(); |
+ const SpdyHeaderBlock& headers, |
+ const string& body) { |
+ if (SendMessage(headers, body) == 0) { |
+ DLOG(ERROR) << "Failed the request for: " << headers.DebugString(); |
// Set the response_ explicitly. Otherwise response_ will contain the |
// response from the previously successful request. |
response_ = ""; |
@@ -452,9 +417,11 @@ string QuicTestClient::SendCustomSynchronousRequest( |
} |
string QuicTestClient::SendSynchronousRequest(const string& uri) { |
- HTTPMessage message; |
- FillInRequest(uri, &message); |
- return SendCustomSynchronousRequest(message); |
+ SpdyHeaderBlock headers; |
+ if (!PopulateHeaderBlockFromUrl(uri, &headers)) { |
+ return ""; |
+ } |
+ return SendCustomSynchronousRequest(headers, ""); |
} |
void QuicTestClient::SetStream(QuicSpdyClientStream* stream) { |
@@ -706,21 +673,23 @@ void QuicTestClient::WaitForWriteToFlush() { |
} |
void QuicTestClient::TestClientDataToResend::Resend() { |
- BalsaHeaders balsa_headers; |
- SpdyBalsaUtils::SpdyHeadersToRequestHeaders(*headers_, &balsa_headers); |
- test_client_->GetOrCreateStreamAndSendRequest(&balsa_headers, body_, fin_, |
+ test_client_->GetOrCreateStreamAndSendRequest(headers_.get(), body_, fin_, |
delegate_); |
headers_.reset(); |
} |
-// static |
-void QuicTestClient::FillInRequest(const string& uri, HTTPMessage* message) { |
- CHECK(message); |
- message->headers()->SetRequestVersion( |
- HTTPMessage::VersionToString(HttpConstants::HTTP_1_1)); |
- message->headers()->SetRequestMethod( |
- HTTPMessage::MethodToString(HttpConstants::GET)); |
- message->headers()->SetRequestUri(uri); |
+bool QuicTestClient::PopulateHeaderBlockFromUrl(const string& uri, |
+ SpdyHeaderBlock* headers) { |
+ string url; |
+ if (base::StartsWith(uri, "https://", base::CompareCase::INSENSITIVE_ASCII) || |
+ base::StartsWith(uri, "http://", base::CompareCase::INSENSITIVE_ASCII)) { |
+ url = uri; |
+ } else if (uri[0] == '/') { |
+ url = "https://" + client_->server_id().host() + uri; |
+ } else { |
+ url = "https://" + uri; |
+ } |
+ return SpdyUtils::PopulateHeaderBlockFromUrl(url, headers); |
} |
} // namespace test |