xref: /aosp_15_r20/external/cronet/net/third_party/quiche/src/quiche/quic/tools/quic_client_bin.cc (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
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:
23 //   quic_client www.google.com --headers="header-a: 1234; header-b: 5678"
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
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
42 
43 #include <iostream>
44 #include <memory>
45 #include <string>
46 
47 #include "quiche/quic/tools/quic_epoll_client_factory.h"
48 #include "quiche/quic/tools/quic_toy_client.h"
49 #include "quiche/common/platform/api/quiche_command_line_flags.h"
50 #include "quiche/common/platform/api/quiche_system_event_loop.h"
51 
main(int argc,char * argv[])52 int main(int argc, char* argv[]) {
53   quiche::QuicheSystemEventLoop event_loop("quic_client");
54   const char* usage = "Usage: quic_client [options] <url>";
55 
56   // All non-flag arguments should be interpreted as URLs to fetch.
57   std::vector<std::string> urls =
58       quiche::QuicheParseCommandLineFlags(usage, argc, argv);
59   if (urls.size() != 1) {
60     quiche::QuichePrintCommandLineFlagHelp(usage);
61     exit(0);
62   }
63 
64   quic::QuicEpollClientFactory factory;
65   quic::QuicToyClient client(&factory);
66   return client.SendRequestsAndPrintResponses(urls);
67 }
68