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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 #include "net/cert/multi_log_ct_verifier.h" | 56 #include "net/cert/multi_log_ct_verifier.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_flags.h" | 59 #include "net/quic/core/quic_flags.h" |
60 #include "net/quic/core/quic_protocol.h" | 60 #include "net/quic/core/quic_protocol.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/core/quic_utils.h" |
63 #include "net/spdy/spdy_header_block.h" | 63 #include "net/spdy/spdy_header_block.h" |
64 #include "net/tools/epoll_server/epoll_server.h" | 64 #include "net/tools/epoll_server/epoll_server.h" |
65 #include "net/tools/quic/quic_client.h" | 65 #include "net/tools/quic/quic_client.h" |
66 #include "net/tools/quic/spdy_balsa_utils.h" | |
67 #include "net/tools/quic/synchronous_host_resolver.h" | 66 #include "net/tools/quic/synchronous_host_resolver.h" |
68 #include "url/gurl.h" | 67 #include "url/gurl.h" |
69 | 68 |
70 using base::StringPiece; | 69 using base::StringPiece; |
71 using net::CertVerifier; | 70 using net::CertVerifier; |
72 using net::CTPolicyEnforcer; | 71 using net::CTPolicyEnforcer; |
73 using net::CTVerifier; | 72 using net::CTVerifier; |
74 using net::MultiLogCTVerifier; | 73 using net::MultiLogCTVerifier; |
75 using net::ProofVerifierChromium; | 74 using net::ProofVerifierChromium; |
| 75 using net::SpdyHeaderBlock; |
76 using net::TransportSecurityState; | 76 using net::TransportSecurityState; |
77 using std::cout; | 77 using std::cout; |
78 using std::cerr; | 78 using std::cerr; |
79 using std::string; | 79 using std::string; |
80 using std::vector; | 80 using std::vector; |
81 using std::endl; | 81 using std::endl; |
82 | 82 |
83 // The IP or hostname the quic client will connect to. | 83 // The IP or hostname the quic client will connect to. |
84 string FLAGS_host = ""; | 84 string FLAGS_host = ""; |
85 // The port to connect to. | 85 // The port to connect to. |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 cout << "Connected to " << host_port << endl; | 280 cout << "Connected to " << host_port << endl; |
281 | 281 |
282 // Construct the string body from flags, if provided. | 282 // Construct the string body from flags, if provided. |
283 string body = FLAGS_body; | 283 string body = FLAGS_body; |
284 if (!FLAGS_body_hex.empty()) { | 284 if (!FLAGS_body_hex.empty()) { |
285 DCHECK(FLAGS_body.empty()) << "Only set one of --body and --body_hex."; | 285 DCHECK(FLAGS_body.empty()) << "Only set one of --body and --body_hex."; |
286 body = net::QuicUtils::HexDecode(FLAGS_body_hex); | 286 body = net::QuicUtils::HexDecode(FLAGS_body_hex); |
287 } | 287 } |
288 | 288 |
289 // Construct a GET or POST request for supplied URL. | 289 // Construct a GET or POST request for supplied URL. |
290 net::BalsaHeaders headers; | 290 SpdyHeaderBlock header_block; |
291 headers.SetRequestFirstlineFromStringPieces(body.empty() ? "GET" : "POST", | 291 header_block[":method"] = body.empty() ? "GET" : "POST"; |
292 url.spec(), "HTTP/1.1"); | 292 header_block[":scheme"] = url.scheme(); |
| 293 header_block[":authority"] = url.host(); |
| 294 header_block[":path"] = url.path(); |
293 | 295 |
294 // Append any additional headers supplied on the command line. | 296 // Append any additional headers supplied on the command line. |
295 for (const std::string& header : | 297 for (const std::string& header : |
296 base::SplitString(FLAGS_headers, ";", base::KEEP_WHITESPACE, | 298 base::SplitString(FLAGS_headers, ";", base::KEEP_WHITESPACE, |
297 base::SPLIT_WANT_NONEMPTY)) { | 299 base::SPLIT_WANT_NONEMPTY)) { |
298 string sp; | 300 string sp; |
299 base::TrimWhitespaceASCII(header, base::TRIM_ALL, &sp); | 301 base::TrimWhitespaceASCII(header, base::TRIM_ALL, &sp); |
300 if (sp.empty()) { | 302 if (sp.empty()) { |
301 continue; | 303 continue; |
302 } | 304 } |
303 vector<string> kv = | 305 vector<string> kv = |
304 base::SplitString(sp, ":", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); | 306 base::SplitString(sp, ":", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
305 CHECK_EQ(2u, kv.size()); | 307 CHECK_EQ(2u, kv.size()); |
306 string key; | 308 string key; |
307 base::TrimWhitespaceASCII(kv[0], base::TRIM_ALL, &key); | 309 base::TrimWhitespaceASCII(kv[0], base::TRIM_ALL, &key); |
308 string value; | 310 string value; |
309 base::TrimWhitespaceASCII(kv[1], base::TRIM_ALL, &value); | 311 base::TrimWhitespaceASCII(kv[1], base::TRIM_ALL, &value); |
310 headers.AppendHeader(key, value); | 312 header_block[kv[0]] = kv[1]; |
311 } | 313 } |
312 | 314 |
313 // Make sure to store the response, for later output. | 315 // Make sure to store the response, for later output. |
314 client.set_store_response(true); | 316 client.set_store_response(true); |
315 // Send the request. | 317 // Send the request. |
316 net::SpdyHeaderBlock header_block = | |
317 net::SpdyBalsaUtils::RequestHeadersToSpdyHeaders(headers); | |
318 client.SendRequestAndWaitForResponse(header_block, body, /*fin=*/true); | 318 client.SendRequestAndWaitForResponse(header_block, body, /*fin=*/true); |
319 | 319 |
320 // Print request and response details. | 320 // Print request and response details. |
321 if (!FLAGS_quiet) { | 321 if (!FLAGS_quiet) { |
322 cout << "Request:" << endl; | 322 cout << "Request:" << endl; |
323 cout << "headers:" << header_block.DebugString(); | 323 cout << "headers:" << header_block.DebugString(); |
324 if (!FLAGS_body_hex.empty()) { | 324 if (!FLAGS_body_hex.empty()) { |
325 // Print the user provided hex, rather than binary body. | 325 // Print the user provided hex, rather than binary body. |
326 cout << "body:\n" | 326 cout << "body:\n" |
327 << net::QuicUtils::HexDump(net::QuicUtils::HexDecode(FLAGS_body_hex)) | 327 << net::QuicUtils::HexDump(net::QuicUtils::HexDecode(FLAGS_body_hex)) |
(...skipping 24 matching lines...) Expand all Loading... |
352 return 0; | 352 return 0; |
353 } else { | 353 } else { |
354 cout << "Request failed (redirect " << response_code << ")." << endl; | 354 cout << "Request failed (redirect " << response_code << ")." << endl; |
355 return 1; | 355 return 1; |
356 } | 356 } |
357 } else { | 357 } else { |
358 cerr << "Request failed (" << response_code << ")." << endl; | 358 cerr << "Request failed (" << response_code << ")." << endl; |
359 return 1; | 359 return 1; |
360 } | 360 } |
361 } | 361 } |
OLD | NEW |