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

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

Issue 1541263002: Landing Recent QUIC changes until 12/18/2015 13:57 UTC (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: replace -1 with 0xff for InvalidPathId 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
« no previous file with comments | « net/tools/quic/quic_server_session_test.cc ('k') | net/tools/quic/quic_simple_server_stream.h » ('j') | 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 7e57bfc3949e20c51c2ce3557c67e092790019f2..cf261fbcf8e1a3501edbb8ee96b055ea7626275a 100644
--- a/net/tools/quic/quic_simple_client_bin.cc
+++ b/net/tools/quic/quic_simple_client_bin.cc
@@ -47,6 +47,7 @@
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
+#include "base/strings/stringprintf.h"
#include "net/base/ip_endpoint.h"
#include "net/base/net_errors.h"
#include "net/base/privacy_mode.h"
@@ -133,6 +134,22 @@ static bool DecodeHexString(const base::StringPiece& hex, std::string* bytes) {
return true;
};
+// Converts binary data into an ASCII string. Each character in the resulting
+// string is preceeded by a space, and replaced with a '.' if not printable.
+string BinaryToAscii(const string& binary) {
+ string out = "";
+ for (const unsigned char c : binary) {
+ // Leading space.
+ out += " ";
+ if (isprint(c)) {
+ out += c;
+ } else {
+ out += '.';
+ }
+ }
+ return out;
+}
+
int main(int argc, char* argv[]) {
base::CommandLine::Init(argc, argv);
base::CommandLine* line = base::CommandLine::ForCurrentProcess();
@@ -337,11 +354,28 @@ int main(int argc, char* argv[]) {
if (!FLAGS_quiet) {
cout << "Request:" << endl;
cout << "headers:" << header_block.DebugString();
- cout << "body: " << body << endl;
+ if (!FLAGS_body_hex.empty()) {
+ // Print the user provided hex, rather than binary body.
+ cout << "body hex: " << FLAGS_body_hex << endl;
+ string bytes;
+ DecodeHexString(FLAGS_body_hex, &bytes);
+ cout << "body ascii: " << BinaryToAscii(bytes) << endl;
+ } else {
+ cout << "body: " << body << endl;
+ }
cout << endl;
cout << "Response:" << endl;
cout << "headers: " << client.latest_response_headers() << endl;
- cout << "body: " << client.latest_response_body() << endl;
+ string response_body = client.latest_response_body();
+ if (!FLAGS_body_hex.empty()) {
+ // Assume response is binary data.
+ string bytes;
+ DecodeHexString(response_body, &bytes);
+ cout << "body hex: " << bytes << endl;
+ cout << "body ascii: " << BinaryToAscii(response_body) << endl;
+ } else {
+ cout << "body: " << response_body << endl;
+ }
}
size_t response_code = client.latest_response_code();
« no previous file with comments | « net/tools/quic/quic_server_session_test.cc ('k') | net/tools/quic/quic_simple_server_stream.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698