OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // A binary wrapper for QuicClient. | 5 // A binary wrapper for QuicClient. |
6 // Connects to a host using QUIC, sends a request to the provided URL, and | 6 // Connects to a host using QUIC, sends a request to the provided URL, and |
7 // displays the response. | 7 // displays the response. |
8 // | 8 // |
9 // Some usage examples: | 9 // Some usage examples: |
10 // | 10 // |
(...skipping 29 matching lines...) Expand all Loading... |
40 | 40 |
41 #include <iostream> | 41 #include <iostream> |
42 | 42 |
43 #include "base/at_exit.h" | 43 #include "base/at_exit.h" |
44 #include "base/command_line.h" | 44 #include "base/command_line.h" |
45 #include "base/logging.h" | 45 #include "base/logging.h" |
46 #include "base/message_loop/message_loop.h" | 46 #include "base/message_loop/message_loop.h" |
47 #include "base/strings/string_number_conversions.h" | 47 #include "base/strings/string_number_conversions.h" |
48 #include "base/strings/string_split.h" | 48 #include "base/strings/string_split.h" |
49 #include "base/strings/string_util.h" | 49 #include "base/strings/string_util.h" |
| 50 #include "base/strings/stringprintf.h" |
50 #include "net/base/ip_endpoint.h" | 51 #include "net/base/ip_endpoint.h" |
51 #include "net/base/net_errors.h" | 52 #include "net/base/net_errors.h" |
52 #include "net/base/privacy_mode.h" | 53 #include "net/base/privacy_mode.h" |
53 #include "net/cert/cert_verifier.h" | 54 #include "net/cert/cert_verifier.h" |
54 #include "net/cert/multi_log_ct_verifier.h" | 55 #include "net/cert/multi_log_ct_verifier.h" |
55 #include "net/http/http_request_info.h" | 56 #include "net/http/http_request_info.h" |
56 #include "net/http/transport_security_state.h" | 57 #include "net/http/transport_security_state.h" |
57 #include "net/log/net_log.h" | 58 #include "net/log/net_log.h" |
58 #include "net/quic/crypto/proof_verifier_chromium.h" | 59 #include "net/quic/crypto/proof_verifier_chromium.h" |
59 #include "net/quic/quic_protocol.h" | 60 #include "net/quic/quic_protocol.h" |
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 net::SpdyHeaderBlock header_block; | 331 net::SpdyHeaderBlock header_block; |
331 net::CreateSpdyHeadersFromHttpRequest(request, request.extra_headers, | 332 net::CreateSpdyHeadersFromHttpRequest(request, request.extra_headers, |
332 net::HTTP2, /*direct=*/true, | 333 net::HTTP2, /*direct=*/true, |
333 &header_block); | 334 &header_block); |
334 client.SendRequestAndWaitForResponse(request, body, /*fin=*/true); | 335 client.SendRequestAndWaitForResponse(request, body, /*fin=*/true); |
335 | 336 |
336 // Print request and response details. | 337 // Print request and response details. |
337 if (!FLAGS_quiet) { | 338 if (!FLAGS_quiet) { |
338 cout << "Request:" << endl; | 339 cout << "Request:" << endl; |
339 cout << "headers:" << header_block.DebugString(); | 340 cout << "headers:" << header_block.DebugString(); |
340 cout << "body: " << body << endl; | 341 string body_to_print = body; |
| 342 if (!FLAGS_body_hex.empty()) { |
| 343 // Print the user provided hex, rather than binary body. |
| 344 body_to_print = base::StringPrintf("(hex) 0x%s", FLAGS_body_hex.c_str()); |
| 345 } |
| 346 cout << "body: " << body_to_print << endl; |
341 cout << endl; | 347 cout << endl; |
342 cout << "Response:" << endl; | 348 cout << "Response:" << endl; |
343 cout << "headers: " << client.latest_response_headers() << endl; | 349 cout << "headers: " << client.latest_response_headers() << endl; |
344 cout << "body: " << client.latest_response_body() << endl; | 350 cout << "body: " << client.latest_response_body() << endl; |
345 } | 351 } |
346 | 352 |
347 size_t response_code = client.latest_response_code(); | 353 size_t response_code = client.latest_response_code(); |
348 if (response_code >= 200 && response_code < 300) { | 354 if (response_code >= 200 && response_code < 300) { |
349 cout << "Request succeeded (" << response_code << ")." << endl; | 355 cout << "Request succeeded (" << response_code << ")." << endl; |
350 return 0; | 356 return 0; |
351 } else if (response_code >= 300 && response_code < 400) { | 357 } else if (response_code >= 300 && response_code < 400) { |
352 if (FLAGS_redirect_is_success) { | 358 if (FLAGS_redirect_is_success) { |
353 cout << "Request succeeded (redirect " << response_code << ")." << endl; | 359 cout << "Request succeeded (redirect " << response_code << ")." << endl; |
354 return 0; | 360 return 0; |
355 } else { | 361 } else { |
356 cout << "Request failed (redirect " << response_code << ")." << endl; | 362 cout << "Request failed (redirect " << response_code << ")." << endl; |
357 return 1; | 363 return 1; |
358 } | 364 } |
359 } else { | 365 } else { |
360 cerr << "Request failed (" << response_code << ")." << endl; | 366 cerr << "Request failed (" << response_code << ")." << endl; |
361 return 1; | 367 return 1; |
362 } | 368 } |
363 } | 369 } |
OLD | NEW |