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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 #include "net/base/net_errors.h" | 52 #include "net/base/net_errors.h" |
53 #include "net/base/privacy_mode.h" | 53 #include "net/base/privacy_mode.h" |
54 #include "net/cert/cert_verifier.h" | 54 #include "net/cert/cert_verifier.h" |
55 #include "net/cert/multi_log_ct_verifier.h" | 55 #include "net/cert/multi_log_ct_verifier.h" |
56 #include "net/http/http_request_info.h" | 56 #include "net/http/http_request_info.h" |
57 #include "net/http/transport_security_state.h" | 57 #include "net/http/transport_security_state.h" |
58 #include "net/quic/chromium/crypto/proof_verifier_chromium.h" | 58 #include "net/quic/chromium/crypto/proof_verifier_chromium.h" |
59 #include "net/quic/core/quic_error_codes.h" | 59 #include "net/quic/core/quic_error_codes.h" |
60 #include "net/quic/core/quic_packets.h" | 60 #include "net/quic/core/quic_packets.h" |
61 #include "net/quic/core/quic_server_id.h" | 61 #include "net/quic/core/quic_server_id.h" |
62 #include "net/quic/core/quic_utils.h" | 62 #include "net/quic/platform/api/quic_text_utils.h" |
63 #include "net/spdy/spdy_header_block.h" | 63 #include "net/spdy/spdy_header_block.h" |
64 #include "net/spdy/spdy_http_utils.h" | 64 #include "net/spdy/spdy_http_utils.h" |
65 #include "net/tools/quic/quic_simple_client.h" | 65 #include "net/tools/quic/quic_simple_client.h" |
66 #include "net/tools/quic/synchronous_host_resolver.h" | 66 #include "net/tools/quic/synchronous_host_resolver.h" |
67 #include "url/gurl.h" | 67 #include "url/gurl.h" |
68 | 68 |
69 using base::StringPiece; | 69 using base::StringPiece; |
70 using net::CertVerifier; | 70 using net::CertVerifier; |
71 using net::CTPolicyEnforcer; | 71 using net::CTPolicyEnforcer; |
72 using net::CTVerifier; | 72 using net::CTVerifier; |
73 using net::MultiLogCTVerifier; | 73 using net::MultiLogCTVerifier; |
74 using net::ProofVerifier; | 74 using net::ProofVerifier; |
75 using net::ProofVerifierChromium; | 75 using net::ProofVerifierChromium; |
| 76 using net::QuicTextUtils; |
76 using net::TransportSecurityState; | 77 using net::TransportSecurityState; |
77 using std::cout; | 78 using std::cout; |
78 using std::cerr; | 79 using std::cerr; |
79 using std::endl; | 80 using std::endl; |
80 using std::string; | 81 using std::string; |
81 | 82 |
82 // The IP or hostname the quic client will connect to. | 83 // The IP or hostname the quic client will connect to. |
83 string FLAGS_host = ""; | 84 string FLAGS_host = ""; |
84 // The port to connect to. | 85 // The port to connect to. |
85 int32_t FLAGS_port = 0; | 86 int32_t FLAGS_port = 0; |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 cerr << "Failed to connect to " << host_port | 291 cerr << "Failed to connect to " << host_port |
291 << ". Error: " << net::QuicErrorCodeToString(error) << endl; | 292 << ". Error: " << net::QuicErrorCodeToString(error) << endl; |
292 return 1; | 293 return 1; |
293 } | 294 } |
294 cout << "Connected to " << host_port << endl; | 295 cout << "Connected to " << host_port << endl; |
295 | 296 |
296 // Construct the string body from flags, if provided. | 297 // Construct the string body from flags, if provided. |
297 string body = FLAGS_body; | 298 string body = FLAGS_body; |
298 if (!FLAGS_body_hex.empty()) { | 299 if (!FLAGS_body_hex.empty()) { |
299 DCHECK(FLAGS_body.empty()) << "Only set one of --body and --body_hex."; | 300 DCHECK(FLAGS_body.empty()) << "Only set one of --body and --body_hex."; |
300 body = net::QuicUtils::HexDecode(FLAGS_body_hex); | 301 body = QuicTextUtils::HexDecode(FLAGS_body_hex); |
301 } | 302 } |
302 | 303 |
303 // Construct a GET or POST request for supplied URL. | 304 // Construct a GET or POST request for supplied URL. |
304 net::HttpRequestInfo request; | 305 net::HttpRequestInfo request; |
305 request.method = body.empty() ? "GET" : "POST"; | 306 request.method = body.empty() ? "GET" : "POST"; |
306 request.url = url; | 307 request.url = url; |
307 | 308 |
308 // Append any additional headers supplied on the command line. | 309 // Append any additional headers supplied on the command line. |
309 for (const std::string& header : | 310 for (const std::string& header : |
310 base::SplitString(FLAGS_headers, ";", base::KEEP_WHITESPACE, | 311 base::SplitString(FLAGS_headers, ";", base::KEEP_WHITESPACE, |
(...skipping 22 matching lines...) Expand all Loading... |
333 /*direct=*/true, &header_block); | 334 /*direct=*/true, &header_block); |
334 client.SendRequestAndWaitForResponse(header_block, body, /*fin=*/true); | 335 client.SendRequestAndWaitForResponse(header_block, 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 if (!FLAGS_body_hex.empty()) { | 341 if (!FLAGS_body_hex.empty()) { |
341 // Print the user provided hex, rather than binary body. | 342 // Print the user provided hex, rather than binary body. |
342 cout << "body:\n" | 343 cout << "body:\n" |
343 << net::QuicUtils::HexDump(net::QuicUtils::HexDecode(FLAGS_body_hex)) | 344 << QuicTextUtils::HexDump(QuicTextUtils::HexDecode(FLAGS_body_hex)) |
344 << endl; | 345 << endl; |
345 } else { | 346 } else { |
346 cout << "body: " << body << endl; | 347 cout << "body: " << body << endl; |
347 } | 348 } |
348 cout << endl; | 349 cout << endl; |
349 cout << "Response:" << endl; | 350 cout << "Response:" << endl; |
350 cout << "headers: " << client.latest_response_headers() << endl; | 351 cout << "headers: " << client.latest_response_headers() << endl; |
351 string response_body = client.latest_response_body(); | 352 string response_body = client.latest_response_body(); |
352 if (!FLAGS_body_hex.empty()) { | 353 if (!FLAGS_body_hex.empty()) { |
353 // Assume response is binary data. | 354 // Assume response is binary data. |
354 cout << "body:\n" << net::QuicUtils::HexDump(response_body) << endl; | 355 cout << "body:\n" << QuicTextUtils::HexDump(response_body) << endl; |
355 } else { | 356 } else { |
356 cout << "body: " << response_body << endl; | 357 cout << "body: " << response_body << endl; |
357 } | 358 } |
358 } | 359 } |
359 | 360 |
360 size_t response_code = client.latest_response_code(); | 361 size_t response_code = client.latest_response_code(); |
361 if (response_code >= 200 && response_code < 300) { | 362 if (response_code >= 200 && response_code < 300) { |
362 cout << "Request succeeded (" << response_code << ")." << endl; | 363 cout << "Request succeeded (" << response_code << ")." << endl; |
363 return 0; | 364 return 0; |
364 } else if (response_code >= 300 && response_code < 400) { | 365 } else if (response_code >= 300 && response_code < 400) { |
365 if (FLAGS_redirect_is_success) { | 366 if (FLAGS_redirect_is_success) { |
366 cout << "Request succeeded (redirect " << response_code << ")." << endl; | 367 cout << "Request succeeded (redirect " << response_code << ")." << endl; |
367 return 0; | 368 return 0; |
368 } else { | 369 } else { |
369 cout << "Request failed (redirect " << response_code << ")." << endl; | 370 cout << "Request failed (redirect " << response_code << ")." << endl; |
370 return 1; | 371 return 1; |
371 } | 372 } |
372 } else { | 373 } else { |
373 cerr << "Request failed (" << response_code << ")." << endl; | 374 cerr << "Request failed (" << response_code << ")." << endl; |
374 return 1; | 375 return 1; |
375 } | 376 } |
376 } | 377 } |
OLD | NEW |