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

Unified Diff: net/tools/quic/quic_client.cc

Issue 847813005: Updates quic_client_bin.cc to be more user friendly, and support more (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@Refactoring_code_for_readability_83493327
Patch Set: Added DumpHeadersToString to dump response headers Created 5 years, 11 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
Index: net/tools/quic/quic_client.cc
diff --git a/net/tools/quic/quic_client.cc b/net/tools/quic/quic_client.cc
index eb86c7f4c181e9e14ba78c9bf55ca906d7198331..29d11bc5b177f8a469338d9c818eae961547e14c 100644
--- a/net/tools/quic/quic_client.cc
+++ b/net/tools/quic/quic_client.cc
@@ -28,6 +28,8 @@
#define SO_RXQ_OVFL 40
#endif
+using std::string;
+
namespace net {
namespace tools {
@@ -36,7 +38,6 @@ const int kEpollFlags = EPOLLIN | EPOLLOUT | EPOLLET;
QuicClient::QuicClient(IPEndPoint server_address,
const QuicServerId& server_id,
const QuicVersionVector& supported_versions,
- bool print_response,
EpollServer* epoll_server)
: server_address_(server_address),
server_id_(server_id),
@@ -48,13 +49,13 @@ QuicClient::QuicClient(IPEndPoint server_address,
packets_dropped_(0),
overflow_supported_(false),
supported_versions_(supported_versions),
- print_response_(print_response) {
+ store_response_(false),
+ latest_response_code_(-1) {
}
QuicClient::QuicClient(IPEndPoint server_address,
const QuicServerId& server_id,
const QuicVersionVector& supported_versions,
- bool print_response,
const QuicConfig& config,
EpollServer* epoll_server)
: server_address_(server_address),
@@ -68,7 +69,8 @@ QuicClient::QuicClient(IPEndPoint server_address,
packets_dropped_(0),
overflow_supported_(false),
supported_versions_(supported_versions),
- print_response_(print_response) {
+ store_response_(false),
+ latest_response_code_(-1) {
}
QuicClient::~QuicClient() {
@@ -245,21 +247,33 @@ void QuicClient::CleanUpUDPSocket() {
}
}
+void QuicClient::SendRequest(const BalsaHeaders& headers,
+ StringPiece body,
+ bool fin) {
+ QuicSpdyClientStream* stream = CreateReliableClientStream();
+ if (stream == nullptr) {
+ LOG(DFATAL) << "stream creation failed!";
+ return;
+ }
+ stream->SendRequest(headers, body, fin);
+ stream->set_visitor(this);
+}
+
+void QuicClient::SendRequestAndWaitForResponse(const BalsaHeaders& headers,
+ StringPiece body,
+ bool fin) {
+ SendRequest(headers, "", true);
+ while (WaitForEvents()) {
+ }
+}
+
void QuicClient::SendRequestsAndWaitForResponse(
const base::CommandLine::StringVector& args) {
for (size_t i = 0; i < args.size(); ++i) {
BalsaHeaders headers;
headers.SetRequestFirstlineFromStringPieces("GET", args[i], "HTTP/1.1");
- QuicSpdyClientStream* stream = CreateReliableClientStream();
- DCHECK(stream != nullptr);
- if (stream == nullptr) {
- LOG(ERROR) << "stream creation failed!";
- break;
- }
- stream->SendRequest(headers, "", true);
- stream->set_visitor(this);
+ SendRequest(headers, "", true);
}
-
while (WaitForEvents()) {}
}
@@ -318,19 +332,12 @@ void QuicClient::OnClose(QuicDataStream* stream) {
stream->id(), client_stream->headers(), client_stream->data());
}
- if (!print_response_) {
- return;
- }
-
- const BalsaHeaders& headers = client_stream->headers();
- printf("%s\n", headers.first_line().as_string().c_str());
- for (BalsaHeaders::const_header_lines_iterator i =
- headers.header_lines_begin();
- i != headers.header_lines_end(); ++i) {
- printf("%s: %s\n", i->first.as_string().c_str(),
- i->second.as_string().c_str());
+ // Store response headers and body.
+ if (store_response_) {
+ latest_response_code_ = client_stream->headers().parsed_response_code();
+ client_stream->headers().DumpHeadersToString(&latest_response_headers_);
+ latest_response_body_ = client_stream->data();
}
- printf("%s\n", client_stream->data().c_str());
}
bool QuicClient::connected() const {
@@ -342,6 +349,21 @@ bool QuicClient::goaway_received() const {
return session_ != nullptr && session_->goaway_received();
}
+size_t QuicClient::latest_response_code() const {
+ LOG_IF(DFATAL, !store_response_) << "Response not stored!";
+ return latest_response_code_;
+}
+
+const string& QuicClient::latest_response_headers() const {
+ LOG_IF(DFATAL, !store_response_) << "Response not stored!";
+ return latest_response_headers_;
+}
+
+const string& QuicClient::latest_response_body() const {
+ LOG_IF(DFATAL, !store_response_) << "Response not stored!";
+ return latest_response_body_;
+}
+
QuicConnectionId QuicClient::GenerateConnectionId() {
return QuicRandom::GetInstance()->RandUint64();
}

Powered by Google App Engine
This is Rietveld 408576698