Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / net / tools / quic / test_tools / simple_client.h
blobb483491387fe433743e40d4d6e072ae29cd6fc68
1 // Copyright 2014 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.
5 #ifndef NET_TOOLS_QUIC_TEST_TOOLS_SIMPLE_CLIENT_H_
6 #define NET_TOOLS_QUIC_TEST_TOOLS_SIMPLE_CLIENT_H_
8 #include <string>
9 #include <vector>
11 #include "net/base/ip_endpoint.h"
12 #include "net/tools/balsa/balsa_frame.h"
14 namespace net {
15 namespace tools {
16 namespace test {
18 class HTTPMessage;
20 class SimpleClient {
21 public:
22 virtual ~SimpleClient() {}
24 // Clears any outstanding state and sends 'size' bytes from 'buffer' to the
25 // server, possibly with multiple send operations. Returns 'size' on success
26 // and -1 on error. Callers should assume that any return value other than
27 // 'size' indicates failure.
28 virtual ssize_t Send(const void *buffer, size_t size) = 0;
30 // Serialize and send an HTTP request.
31 virtual ssize_t SendMessage(const HTTPMessage& message) = 0;
33 // Clears any outstanding state, sends 'size' bytes from 'buffer' and waits
34 // for a response or an error.
35 virtual ssize_t SendAndWaitForResponse(const void *buffer, size_t size) = 0;
37 // Clears any outstanding state and sends a simple GET of 'uri' to the
38 // server.
39 virtual ssize_t SendRequest(const std::string& uri) = 0;
41 // The response body is returned as a string.
42 virtual std::string SendCustomSynchronousRequest(
43 const HTTPMessage& message) = 0;
44 virtual std::string SendSynchronousRequest(const std::string& url) = 0;
46 // Returns once a complete response or a connection close has been received
47 // from the server.
48 virtual void WaitForResponse();
50 // Waits for some data or response from the server.
51 virtual void WaitForInitialResponse();
53 // Returns once a complete response or a connection close has been received
54 // from the server, or once the timeout expires. -1 for no timeout.
55 virtual void WaitForResponseForMs(int timeout_ms) = 0;
57 // Waits for some data or response from the server, or once the timeout
58 // expires. -1 for no timeout.
59 virtual void WaitForInitialResponseForMs(int timeout_ms) = 0;
61 // Clears any outstanding state from the last request.
62 virtual void ClearPerRequestState() = 0;
64 // Closes and reopens the connection to the server.
65 virtual void ResetConnection() = 0;
67 // Closes the connection to the server.
68 virtual void Disconnect() = 0;
70 // Both will return 0 on success, -1 otherwise.
71 // Sends out RST packet to peer.
72 // TODO(yongfa): Probably should be an interface too. LOG(FATAL) here
73 // to prevent accidental invocation.
74 virtual int ResetSocket();
76 virtual int HalfClose();
78 // Connects to the server. This should be done implicitly by Send*
79 // functions, but can be done explicitly as well.
80 virtual void Connect() = 0;
82 // Bind to the specified address. If set_bind_to_address() is called, this
83 // is called automatically on connect, but can be done explicitly to make
84 // LocalIPEndPoint() meaningful before actually connecting.
85 // Sets *local_address to the actual address bound to, which can be different
86 // if the given address has port 0.
87 virtual void Bind(IPEndPoint* local_address) = 0;
89 virtual void MigrateSocket(const IPAddressNumber& new_host) = 0;
91 // Returns the local socket address of the client fd. Call only when
92 // connected.
93 // To get the local IPAdress, use local_address().host().
94 // To get the local port, use local_address.port().
95 virtual IPEndPoint local_address() const = 0;
97 // Returns the serialized message that would be sent by any of the HTTPMessage
98 // functions above.
99 virtual std::string SerializeMessage(const HTTPMessage& message) = 0;
101 // Sets the IP address to bind to on future Connect()s in case Bind() is not
102 // called in advance. If it's set to uninitialized IPAddress, default loopback
103 // address will be used.
104 virtual IPAddressNumber bind_to_address() const = 0;
105 virtual void set_bind_to_address(IPAddressNumber address) = 0;
107 // Returns true if the headers have been processed and are available.
108 virtual bool response_headers_complete() const = 0;
110 // Returns the response headers, if a response was completely framed.
111 // Undefined behavior otherwise.
112 virtual const BalsaHeaders* response_headers() const = 0;
114 // Returns true iff response has been fully received.
115 virtual bool response_complete() const = 0;
117 // Returns the number of bytes read from the server during this request.
118 virtual int64 response_size() const = 0;
120 // Returns the number of header bytes received during this request, if
121 // meaningful for the protocol.
122 virtual int response_header_size() const;
124 // Returns the number of body bytes received during this request, if
125 // meaningful for the protocol.
126 virtual int64 response_body_size() const;
128 // Returns the response body, if there was one. If there was no response, or
129 // if buffer_body() is false, returns an empty string.
130 virtual const std::string& response_body() = 0;
132 // The address the client is connected to.
133 virtual const IPEndPoint& address() const = 0;
135 // Returns true if the client is connected, false otherwise.
136 virtual bool connected() const = 0;
138 // Returns true if the server has informed the client that it is
139 // in "lame duck" mode, indicating intent to shut down and
140 // requesting that no further connections be established.
141 virtual bool ServerInLameDuckMode() const = 0;
143 // Return the number of bytes read off the wire by this client.
144 virtual size_t bytes_read() const = 0;
146 // Returns the number of bytes written to the wire by this client.
147 virtual size_t bytes_written() const = 0;
149 // Return the number of requests sent.
150 virtual size_t requests_sent() const = 0;
152 // Instructs the client to populate response_body().
153 virtual bool buffer_body() const = 0;
154 virtual void set_buffer_body(bool buffer_body) = 0;
157 } // namespace test
158 } // namespace tools
159 } // namespace net
161 #endif // NET_TOOLS_QUIC_TEST_TOOLS_SIMPLE_CLIENT_H_