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

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

Issue 1532113002: Adds a --body_hex flag to quic_client_bin to allow POST message body to be specified as a hex strin… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@110183495
Patch Set: Created 5 years 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
« net/tools/quic/quic_client_bin.cc ('K') | « net/tools/quic/quic_client_bin.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/tools/quic/quic_simple_client_bin.cc
diff --git a/net/tools/quic/quic_simple_client_bin.cc b/net/tools/quic/quic_simple_client_bin.cc
index 6599c8699553293494d64a86c8a15b93089b3d9a..0217fa5d5562926de2f13c8a9964b1cfd85c5db8 100644
--- a/net/tools/quic/quic_simple_client_bin.cc
+++ b/net/tools/quic/quic_simple_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) {
+ 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,9 +292,16 @@ 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::HttpRequestInfo request;
- request.method = FLAGS_body.empty() ? "GET" : "POST";
+ request.method = body.empty() ? "GET" : "POST";
request.url = url;
// Append any additional headers supplied on the command line.
@@ -305,13 +331,13 @@ int main(int argc, char *argv[]) {
net::CreateSpdyHeadersFromHttpRequest(request, request.extra_headers,
net::HTTP2, /*direct=*/true,
&header_block);
- client.SendRequestAndWaitForResponse(request, FLAGS_body, /*fin=*/true);
+ client.SendRequestAndWaitForResponse(request, 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;
« net/tools/quic/quic_client_bin.cc ('K') | « net/tools/quic/quic_client_bin.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698