blob: 226e647351a8f3d45a591aa28a068545cd09060f [file] [log] [blame]
QUICHE teama6ef0a62019-03-07 20:34:33 -05001// 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:
wubbdacc702019-07-17 05:15:55 -070023// quic_client www.google.com --headers="header-a: 1234; header-b: 5678"
QUICHE teama6ef0a62019-03-07 20:34:33 -050024//
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 team2252b702019-05-14 23:55:14 -040037//
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 teama6ef0a62019-03-07 20:34:33 -050042
QUICHE teama6ef0a62019-03-07 20:34:33 -050043#include <iostream>
44#include <memory>
vasilvv872e7a32019-03-12 16:42:44 -070045#include <string>
QUICHE teama6ef0a62019-03-07 20:34:33 -050046
QUICHE teama6ef0a62019-03-07 20:34:33 -050047#include "net/third_party/quiche/src/quic/platform/api/quic_system_event_loop.h"
rchd3faf902019-05-17 14:41:52 -070048#include "net/third_party/quiche/src/quic/tools/quic_epoll_client_factory.h"
rch86a45622019-05-15 19:19:04 -070049#include "net/third_party/quiche/src/quic/tools/quic_toy_client.h"
QUICHE teama6ef0a62019-03-07 20:34:33 -050050
QUICHE teama6ef0a62019-03-07 20:34:33 -050051int 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.
vasilvvc48c8712019-03-11 13:38:16 -070056 std::vector<std::string> urls =
QUICHE teama6ef0a62019-03-07 20:34:33 -050057 quic::QuicParseCommandLineFlags(usage, argc, argv);
58 if (urls.size() != 1) {
59 quic::QuicPrintCommandLineFlagHelp(usage);
60 exit(0);
61 }
62
rchd3faf902019-05-17 14:41:52 -070063 quic::QuicEpollClientFactory factory;
rchd9142502019-05-17 14:31:14 -070064 quic::QuicToyClient client(&factory);
rch86a45622019-05-15 19:19:04 -070065 return client.SendRequestsAndPrintResponses(urls);
QUICHE teama6ef0a62019-03-07 20:34:33 -050066}