| 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 908da90c297cd235fe25fd925cda303778c2c9ce..1667e0937add72b41d25abfd5afbbe92781d0c5e 100644
|
| --- a/net/tools/quic/quic_simple_client_bin.cc
|
| +++ b/net/tools/quic/quic_simple_client_bin.cc
|
| @@ -134,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();
|
| @@ -338,16 +354,28 @@ int main(int argc, char *argv[]) {
|
| if (!FLAGS_quiet) {
|
| cout << "Request:" << endl;
|
| cout << "headers:" << header_block.DebugString();
|
| - string body_to_print = body;
|
| if (!FLAGS_body_hex.empty()) {
|
| // Print the user provided hex, rather than binary body.
|
| - body_to_print = base::StringPrintf("(hex) 0x%s", FLAGS_body_hex.c_str());
|
| + 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 << "body: " << body_to_print << 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();
|
|
|