Chromium Code Reviews| Index: net/tools/quic/quic_client_bin.cc |
| diff --git a/net/tools/quic/quic_client_bin.cc b/net/tools/quic/quic_client_bin.cc |
| index e23bb590e1a0da598cb764c7cae5bc801fd24613..f8526ad227f9ebdc1fe62008ecd3ab5c37d2c8d6 100644 |
| --- a/net/tools/quic/quic_client_bin.cc |
| +++ b/net/tools/quic/quic_client_bin.cc |
| @@ -84,6 +84,9 @@ string FLAGS_host = ""; |
| int32 FLAGS_port = 0; |
| // If set, send a POST with this body. |
| string FLAGS_body = ""; |
| +// If set, contents are converted from hex to ascii, before sending as body of |
| +// a POST. e.g. --body_hex=\"68656c6c6f\" |
| +string FLAGS_body_hex = ""; |
| // A semicolon separated list of key:value pairs to add to request headers. |
| string FLAGS_headers = ""; |
| // Set to true for a quieter output experience. |
| @@ -118,6 +121,18 @@ class FakeCertVerifier : public net::CertVerifier { |
| bool SupportsOCSPStapling() override { return false; } |
| }; |
| +static bool DecodeHexString(const base::StringPiece& hex, std::string* bytes) { |
|
Ryan Hamilton
2015/12/17 17:59:39
Instead, can you try base::HexStringToBytes from b
Ryan Hamilton
2015/12/17 18:37:44
Whoops, this is already doing that, of course.
|
| + bytes->clear(); |
| + if (hex.empty()) |
| + return true; |
| + std::vector<uint8> v; |
| + if (!base::HexStringToBytes(hex.as_string(), &v)) |
| + return false; |
| + if (!v.empty()) |
| + bytes->assign(reinterpret_cast<const char*>(&v[0]), v.size()); |
| + return true; |
| +}; |
| + |
| int main(int argc, char *argv[]) { |
| base::CommandLine::Init(argc, argv); |
| base::CommandLine* line = base::CommandLine::ForCurrentProcess(); |
| @@ -140,6 +155,7 @@ int main(int argc, char *argv[]) { |
| "connect to\n" |
| "--port=<port> specify the port to connect to\n" |
| "--body=<body> specify the body to post\n" |
| + "--body_hex=<body_hex> specify the body_hex to be printed out\n" |
| "--headers=<headers> specify a semicolon separated list of " |
| "key:value pairs to add to request headers\n" |
| "--quiet specify for a quieter output experience\n" |
| @@ -166,6 +182,9 @@ int main(int argc, char *argv[]) { |
| if (line->HasSwitch("body")) { |
| FLAGS_body = line->GetSwitchValueASCII("body"); |
| } |
| + if (line->HasSwitch("body_hex")) { |
| + FLAGS_body_hex = line->GetSwitchValueASCII("body_hex"); |
| + } |
| if (line->HasSwitch("headers")) { |
| FLAGS_headers = line->GetSwitchValueASCII("headers"); |
| } |
| @@ -273,10 +292,17 @@ int main(int argc, char *argv[]) { |
| } |
| cout << "Connected to " << host_port << endl; |
| + // Construct the string body from flags, if provided. |
| + string body = FLAGS_body; |
| + if (!FLAGS_body_hex.empty()) { |
| + DCHECK(FLAGS_body.empty()) << "Only set one of --body and --body_hex."; |
| + DecodeHexString(FLAGS_body_hex, &body); |
| + } |
| + |
| // Construct a GET or POST request for supplied URL. |
| net::BalsaHeaders headers; |
| - headers.SetRequestFirstlineFromStringPieces( |
| - FLAGS_body.empty() ? "GET" : "POST", url.spec(), "HTTP/1.1"); |
| + headers.SetRequestFirstlineFromStringPieces(body.empty() ? "GET" : "POST", |
| + url.spec(), "HTTP/1.1"); |
| // Append any additional headers supplied on the command line. |
| for (const std::string& header : |
| @@ -303,13 +329,13 @@ int main(int argc, char *argv[]) { |
| // Send the request. |
| net::SpdyHeaderBlock header_block = |
| net::tools::SpdyBalsaUtils::RequestHeadersToSpdyHeaders(headers); |
| - client.SendRequestAndWaitForResponse(headers, FLAGS_body, /*fin=*/true); |
| + client.SendRequestAndWaitForResponse(headers, body, /*fin=*/true); |
| // Print request and response details. |
| if (!FLAGS_quiet) { |
| cout << "Request:" << endl; |
| cout << "headers:" << header_block.DebugString(); |
| - cout << "body: " << FLAGS_body << endl; |
| + cout << "body: " << body << endl; |
| cout << endl; |
| cout << "Response:" << endl; |
| cout << "headers: " << client.latest_response_headers() << endl; |