| 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 #include "net/base/net_errors.h" | 51 #include "net/base/net_errors.h" |
| 52 #include "net/base/privacy_mode.h" | 52 #include "net/base/privacy_mode.h" |
| 53 #include "net/cert/cert_verifier.h" | 53 #include "net/cert/cert_verifier.h" |
| 54 #include "net/http/http_request_info.h" | 54 #include "net/http/http_request_info.h" |
| 55 #include "net/http/transport_security_state.h" | 55 #include "net/http/transport_security_state.h" |
| 56 #include "net/log/net_log.h" | 56 #include "net/log/net_log.h" |
| 57 #include "net/quic/crypto/proof_verifier_chromium.h" | 57 #include "net/quic/crypto/proof_verifier_chromium.h" |
| 58 #include "net/quic/quic_protocol.h" | 58 #include "net/quic/quic_protocol.h" |
| 59 #include "net/quic/quic_server_id.h" | 59 #include "net/quic/quic_server_id.h" |
| 60 #include "net/quic/quic_utils.h" | 60 #include "net/quic/quic_utils.h" |
| 61 #include "net/spdy/spdy_header_block.h" |
| 61 #include "net/spdy/spdy_http_utils.h" | 62 #include "net/spdy/spdy_http_utils.h" |
| 62 #include "net/tools/quic/quic_simple_client.h" | 63 #include "net/tools/quic/quic_simple_client.h" |
| 63 #include "net/tools/quic/synchronous_host_resolver.h" | 64 #include "net/tools/quic/synchronous_host_resolver.h" |
| 64 #include "url/gurl.h" | 65 #include "url/gurl.h" |
| 65 | 66 |
| 66 using base::StringPiece; | 67 using base::StringPiece; |
| 67 using net::CertVerifier; | 68 using net::CertVerifier; |
| 68 using net::ProofVerifierChromium; | 69 using net::ProofVerifierChromium; |
| 69 using net::TransportSecurityState; | 70 using net::TransportSecurityState; |
| 70 using std::cout; | 71 using std::cout; |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 net::SpdyHeaderBlock header_block; | 272 net::SpdyHeaderBlock header_block; |
| 272 net::CreateSpdyHeadersFromHttpRequest(request, request.extra_headers, | 273 net::CreateSpdyHeadersFromHttpRequest(request, request.extra_headers, |
| 273 net::HTTP2, /*direct=*/true, | 274 net::HTTP2, /*direct=*/true, |
| 274 &header_block); | 275 &header_block); |
| 275 client.SendRequestAndWaitForResponse(request, FLAGS_body, /*fin=*/true); | 276 client.SendRequestAndWaitForResponse(request, FLAGS_body, /*fin=*/true); |
| 276 | 277 |
| 277 // Print request and response details. | 278 // Print request and response details. |
| 278 if (!FLAGS_quiet) { | 279 if (!FLAGS_quiet) { |
| 279 cout << "Request:" << endl; | 280 cout << "Request:" << endl; |
| 280 cout << "headers:" << endl; | 281 cout << "headers:" << endl; |
| 281 for (const std::pair<string, string>& kv : header_block) { | 282 for (const auto& kv : header_block) { |
| 282 cout << " " << kv.first << ": " << kv.second << endl; | 283 cout << " " << kv.first << ": " << kv.second << endl; |
| 283 } | 284 } |
| 284 cout << "body: " << FLAGS_body << endl; | 285 cout << "body: " << FLAGS_body << endl; |
| 285 cout << endl; | 286 cout << endl; |
| 286 cout << "Response:" << endl; | 287 cout << "Response:" << endl; |
| 287 cout << "headers: " << client.latest_response_headers() << endl; | 288 cout << "headers: " << client.latest_response_headers() << endl; |
| 288 cout << "body: " << client.latest_response_body() << endl; | 289 cout << "body: " << client.latest_response_body() << endl; |
| 289 } | 290 } |
| 290 | 291 |
| 291 size_t response_code = client.latest_response_code(); | 292 size_t response_code = client.latest_response_code(); |
| 292 if (response_code >= 200 && response_code < 300) { | 293 if (response_code >= 200 && response_code < 300) { |
| 293 cout << "Request succeeded (" << response_code << ")." << endl; | 294 cout << "Request succeeded (" << response_code << ")." << endl; |
| 294 return 0; | 295 return 0; |
| 295 } else if (response_code >= 300 && response_code < 400) { | 296 } else if (response_code >= 300 && response_code < 400) { |
| 296 if (FLAGS_redirect_is_success) { | 297 if (FLAGS_redirect_is_success) { |
| 297 cout << "Request succeeded (redirect " << response_code << ")." << endl; | 298 cout << "Request succeeded (redirect " << response_code << ")." << endl; |
| 298 return 0; | 299 return 0; |
| 299 } else { | 300 } else { |
| 300 cout << "Request failed (redirect " << response_code << ")." << endl; | 301 cout << "Request failed (redirect " << response_code << ")." << endl; |
| 301 return 1; | 302 return 1; |
| 302 } | 303 } |
| 303 } else { | 304 } else { |
| 304 cerr << "Request failed (" << response_code << ")." << endl; | 305 cerr << "Request failed (" << response_code << ")." << endl; |
| 305 return 1; | 306 return 1; |
| 306 } | 307 } |
| 307 } | 308 } |
| OLD | NEW |