Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(22)

Side by Side Diff: net/tools/quic/quic_client.h

Issue 847813005: Updates quic_client_bin.cc to be more user friendly, and support more (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@Refactoring_code_for_readability_83493327
Patch Set: Added DumpHeadersToString to dump response headers Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 toy client, which connects to a specified port and sends QUIC 5 // A toy client, which connects to a specified port and sends QUIC
6 // request to that endpoint. 6 // request to that endpoint.
7 7
8 #ifndef NET_TOOLS_QUIC_QUIC_CLIENT_H_ 8 #ifndef NET_TOOLS_QUIC_QUIC_CLIENT_H_
9 #define NET_TOOLS_QUIC_QUIC_CLIENT_H_ 9 #define NET_TOOLS_QUIC_QUIC_CLIENT_H_
10 10
11 #include <string> 11 #include <string>
12 12
13 #include "base/basictypes.h" 13 #include "base/basictypes.h"
14 #include "base/command_line.h" 14 #include "base/command_line.h"
15 #include "base/memory/scoped_ptr.h" 15 #include "base/memory/scoped_ptr.h"
16 #include "base/strings/string_piece.h"
16 #include "net/base/ip_endpoint.h" 17 #include "net/base/ip_endpoint.h"
17 #include "net/quic/crypto/crypto_handshake.h" 18 #include "net/quic/crypto/crypto_handshake.h"
18 #include "net/quic/quic_config.h" 19 #include "net/quic/quic_config.h"
19 #include "net/quic/quic_framer.h" 20 #include "net/quic/quic_framer.h"
20 #include "net/quic/quic_packet_creator.h" 21 #include "net/quic/quic_packet_creator.h"
22 #include "net/tools/balsa/balsa_headers.h"
21 #include "net/tools/epoll_server/epoll_server.h" 23 #include "net/tools/epoll_server/epoll_server.h"
22 #include "net/tools/quic/quic_client_session.h" 24 #include "net/tools/quic/quic_client_session.h"
23 #include "net/tools/quic/quic_spdy_client_stream.h" 25 #include "net/tools/quic/quic_spdy_client_stream.h"
24 26
25 namespace net { 27 namespace net {
26 28
27 class ProofVerifier; 29 class ProofVerifier;
28 class QuicServerId; 30 class QuicServerId;
29 31
30 namespace tools { 32 namespace tools {
(...skipping 14 matching lines...) Expand all
45 virtual void OnCompleteResponse(QuicStreamId id, 47 virtual void OnCompleteResponse(QuicStreamId id,
46 const BalsaHeaders& response_headers, 48 const BalsaHeaders& response_headers,
47 const std::string& response_body) = 0; 49 const std::string& response_body) = 0;
48 }; 50 };
49 51
50 // Create a quic client, which will have events managed by an externally owned 52 // Create a quic client, which will have events managed by an externally owned
51 // EpollServer. 53 // EpollServer.
52 QuicClient(IPEndPoint server_address, 54 QuicClient(IPEndPoint server_address,
53 const QuicServerId& server_id, 55 const QuicServerId& server_id,
54 const QuicVersionVector& supported_versions, 56 const QuicVersionVector& supported_versions,
55 bool print_response,
56 EpollServer* epoll_server); 57 EpollServer* epoll_server);
57 QuicClient(IPEndPoint server_address, 58 QuicClient(IPEndPoint server_address,
58 const QuicServerId& server_id, 59 const QuicServerId& server_id,
59 const QuicVersionVector& supported_versions, 60 const QuicVersionVector& supported_versions,
60 bool print_response,
61 const QuicConfig& config, 61 const QuicConfig& config,
62 EpollServer* epoll_server); 62 EpollServer* epoll_server);
63 63
64 ~QuicClient() override; 64 ~QuicClient() override;
65 65
66 // Initializes the client to create a connection. Should be called exactly 66 // Initializes the client to create a connection. Should be called exactly
67 // once before calling StartConnect or Connect. Returns true if the 67 // once before calling StartConnect or Connect. Returns true if the
68 // initialization succeeds, false otherwise. 68 // initialization succeeds, false otherwise.
69 bool Initialize(); 69 bool Initialize();
70 70
71 // "Connect" to the QUIC server, including performing synchronous crypto 71 // "Connect" to the QUIC server, including performing synchronous crypto
72 // handshake. 72 // handshake.
73 bool Connect(); 73 bool Connect();
74 74
75 // Start the crypto handshake. This can be done in place of the synchronous 75 // Start the crypto handshake. This can be done in place of the synchronous
76 // Connect(), but callers are responsible for making sure the crypto handshake 76 // Connect(), but callers are responsible for making sure the crypto handshake
77 // completes. 77 // completes.
78 void StartConnect(); 78 void StartConnect();
79 79
80 // Returns true if the crypto handshake has yet to establish encryption. 80 // Returns true if the crypto handshake has yet to establish encryption.
81 // Returns false if encryption is active (even if the server hasn't confirmed 81 // Returns false if encryption is active (even if the server hasn't confirmed
82 // the handshake) or if the connection has been closed. 82 // the handshake) or if the connection has been closed.
83 bool EncryptionBeingEstablished(); 83 bool EncryptionBeingEstablished();
84 84
85 // Disconnects from the QUIC server. 85 // Disconnects from the QUIC server.
86 void Disconnect(); 86 void Disconnect();
87 87
88 // Sends an HTTP request and does not wait for response before returning.
89 void SendRequest(const BalsaHeaders& headers,
90 base::StringPiece body,
91 bool fin);
92
93 // Sends an HTTP request and waits for response before returning.
94 void SendRequestAndWaitForResponse(const BalsaHeaders& headers,
95 base::StringPiece body,
96 bool fin);
97
88 // Sends a request simple GET for each URL in |args|, and then waits for 98 // Sends a request simple GET for each URL in |args|, and then waits for
89 // each to complete. 99 // each to complete.
90 void SendRequestsAndWaitForResponse(const 100 void SendRequestsAndWaitForResponse(const
91 base::CommandLine::StringVector& args); 101 base::CommandLine::StringVector& args);
92 102
93 // Returns a newly created QuicSpdyClientStream, owned by the 103 // Returns a newly created QuicSpdyClientStream, owned by the
94 // QuicClient. 104 // QuicClient.
95 QuicSpdyClientStream* CreateReliableClientStream(); 105 QuicSpdyClientStream* CreateReliableClientStream();
96 106
97 // Wait for events until the stream with the given ID is closed. 107 // Wait for events until the stream with the given ID is closed.
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 supported_versions_ = versions; 176 supported_versions_ = versions;
167 } 177 }
168 178
169 // Takes ownership of the listener. 179 // Takes ownership of the listener.
170 void set_response_listener(ResponseListener* listener) { 180 void set_response_listener(ResponseListener* listener) {
171 response_listener_.reset(listener); 181 response_listener_.reset(listener);
172 } 182 }
173 183
174 QuicConfig* config() { return &config_; } 184 QuicConfig* config() { return &config_; }
175 185
186 void set_store_response(bool val) { store_response_ = val; }
187
188 size_t latest_response_code() const;
189 const std::string& latest_response_headers() const;
190 const std::string& latest_response_body() const;
191
176 protected: 192 protected:
177 virtual QuicConnectionId GenerateConnectionId(); 193 virtual QuicConnectionId GenerateConnectionId();
178 virtual QuicEpollConnectionHelper* CreateQuicConnectionHelper(); 194 virtual QuicEpollConnectionHelper* CreateQuicConnectionHelper();
179 virtual QuicPacketWriter* CreateQuicPacketWriter(); 195 virtual QuicPacketWriter* CreateQuicPacketWriter();
180 196
181 virtual int ReadPacket(char* buffer, 197 virtual int ReadPacket(char* buffer,
182 int buffer_len, 198 int buffer_len,
183 IPEndPoint* server_address, 199 IPEndPoint* server_address,
184 IPAddressNumber* client_ip); 200 IPAddressNumber* client_ip);
185 201
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 // because the socket would otherwise overflow. 273 // because the socket would otherwise overflow.
258 bool overflow_supported_; 274 bool overflow_supported_;
259 275
260 // This vector contains QUIC versions which we currently support. 276 // This vector contains QUIC versions which we currently support.
261 // This should be ordered such that the highest supported version is the first 277 // This should be ordered such that the highest supported version is the first
262 // element, with subsequent elements in descending order (versions can be 278 // element, with subsequent elements in descending order (versions can be
263 // skipped as necessary). We will always pick supported_versions_[0] as the 279 // skipped as necessary). We will always pick supported_versions_[0] as the
264 // initial version to use. 280 // initial version to use.
265 QuicVersionVector supported_versions_; 281 QuicVersionVector supported_versions_;
266 282
267 // If true, then the contents of each response will be printed to stdout 283 // If true, store the latest response code, headers, and body.
268 // when the stream is closed (in OnClose). 284 bool store_response_;
269 bool print_response_; 285 // HTTP response code from most recent response.
286 size_t latest_response_code_;
287 // HTTP headers from most recent response.
288 std::string latest_response_headers_;
289 // Body of most recent response.
290 std::string latest_response_body_;
270 291
271 DISALLOW_COPY_AND_ASSIGN(QuicClient); 292 DISALLOW_COPY_AND_ASSIGN(QuicClient);
272 }; 293 };
273 294
274 } // namespace tools 295 } // namespace tools
275 } // namespace net 296 } // namespace net
276 297
277 #endif // NET_TOOLS_QUIC_QUIC_CLIENT_H_ 298 #endif // NET_TOOLS_QUIC_QUIC_CLIENT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698