QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | // A binary wrapper for QuicClient. |
| 6 | // Connects to a host using QUIC, sends a request to the provided URL, and |
| 7 | // displays the response. |
| 8 | // |
| 9 | // Some usage examples: |
| 10 | // |
| 11 | // Standard request/response: |
| 12 | // quic_client www.google.com |
| 13 | // quic_client www.google.com --quiet |
| 14 | // quic_client www.google.com --port=443 |
| 15 | // |
| 16 | // Use a specific version: |
| 17 | // quic_client www.google.com --quic_version=23 |
| 18 | // |
| 19 | // Send a POST instead of a GET: |
| 20 | // quic_client www.google.com --body="this is a POST body" |
| 21 | // |
| 22 | // Append additional headers to the request: |
wub | bdacc70 | 2019-07-17 05:15:55 -0700 | [diff] [blame] | 23 | // quic_client www.google.com --headers="header-a: 1234; header-b: 5678" |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 24 | // |
| 25 | // Connect to a host different to the URL being requested: |
| 26 | // quic_client mail.google.com --host=www.google.com |
| 27 | // |
| 28 | // Connect to a specific IP: |
| 29 | // IP=`dig www.google.com +short | head -1` |
| 30 | // quic_client www.google.com --host=${IP} |
| 31 | // |
| 32 | // Send repeated requests and change ephemeral port between requests |
| 33 | // quic_client www.google.com --num_requests=10 |
| 34 | // |
| 35 | // Try to connect to a host which does not speak QUIC: |
| 36 | // quic_client www.example.com |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 37 | // |
| 38 | // This tool is available as a built binary at: |
| 39 | // /google/data/ro/teams/quic/tools/quic_client |
| 40 | // After submitting changes to this file, you will need to follow the |
| 41 | // instructions at go/quic_client_binary_update |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 42 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 43 | #include <iostream> |
| 44 | #include <memory> |
vasilvv | 872e7a3 | 2019-03-12 16:42:44 -0700 | [diff] [blame] | 45 | #include <string> |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 46 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 47 | #include "net/third_party/quiche/src/quic/platform/api/quic_system_event_loop.h" |
rch | d3faf90 | 2019-05-17 14:41:52 -0700 | [diff] [blame] | 48 | #include "net/third_party/quiche/src/quic/tools/quic_epoll_client_factory.h" |
rch | 86a4562 | 2019-05-15 19:19:04 -0700 | [diff] [blame] | 49 | #include "net/third_party/quiche/src/quic/tools/quic_toy_client.h" |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 50 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 51 | int main(int argc, char* argv[]) { |
| 52 | QuicSystemEventLoop event_loop("quic_client"); |
| 53 | const char* usage = "Usage: quic_client [options] <url>"; |
| 54 | |
| 55 | // All non-flag arguments should be interpreted as URLs to fetch. |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 56 | std::vector<std::string> urls = |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 57 | quic::QuicParseCommandLineFlags(usage, argc, argv); |
| 58 | if (urls.size() != 1) { |
| 59 | quic::QuicPrintCommandLineFlagHelp(usage); |
| 60 | exit(0); |
| 61 | } |
| 62 | |
rch | d3faf90 | 2019-05-17 14:41:52 -0700 | [diff] [blame] | 63 | quic::QuicEpollClientFactory factory; |
rch | d914250 | 2019-05-17 14:31:14 -0700 | [diff] [blame] | 64 | quic::QuicToyClient client(&factory); |
rch | 86a4562 | 2019-05-15 19:19:04 -0700 | [diff] [blame] | 65 | return client.SendRequestsAndPrintResponses(urls); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 66 | } |