1 // Copyright 2016 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef NET_TEST_QUIC_SIMPLE_TEST_SERVER_H_ 6 #define NET_TEST_QUIC_SIMPLE_TEST_SERVER_H_ 7 8 #include <string> 9 #include <vector> 10 11 #include "base/time/time.h" 12 #include "net/base/host_port_pair.h" 13 #include "net/third_party/quiche/src/quiche/spdy/core/http2_header_block.h" 14 #include "url/gurl.h" 15 16 namespace net { 17 18 class QuicSimpleTestServer { 19 public: 20 static bool Start(); 21 static void Shutdown(); 22 23 // Shuts down the server dispatcher, which results in sending ConnectionClose 24 // frames to all connected clients. 25 static void ShutdownDispatcherForTesting(); 26 27 // Add a response to `path`. 28 static void AddResponse(const std::string& path, 29 spdy::Http2HeaderBlock response_headers, 30 const std::string& response_body); 31 32 // Add a response to `path` with Early Hints. 33 static void AddResponseWithEarlyHints( 34 const std::string& path, 35 const spdy::Http2HeaderBlock& response_headers, 36 const std::string& response_body, 37 const std::vector<spdy::Http2HeaderBlock>& early_hints); 38 39 // Set a delay to `path`. 40 static void SetResponseDelay(const std::string& path, base::TimeDelta delay); 41 42 // Returns example.com 43 static std::string const GetDomain(); 44 // Returns test.example.com 45 static std::string const GetHost(); 46 // Returns port number of the server. 47 static int GetPort(); 48 // Returns test.example.com:port 49 static HostPortPair const GetHostPort(); 50 51 // Returns URL with host, port and file path, for example 52 // https://test.example.com:12345/{file_path} 53 static GURL GetFileURL(const std::string& file_path); 54 55 static std::string const GetStatusHeaderName(); 56 57 // Server returns response with HTTP/2 headers and trailers. Does not include 58 // |port| as it is resolved differently: https://test.example.com/hello.txt 59 static GURL GetHelloURL(); 60 static std::string const GetHelloPath(); 61 static std::string const GetHelloBodyValue(); 62 static std::string const GetHelloStatus(); 63 static std::string const GetHelloHeaderName(); 64 static std::string const GetHelloHeaderValue(); 65 static std::string const GetCombinedHeaderName(); 66 static std::string const GetHelloTrailerName(); 67 static std::string const GetHelloTrailerValue(); 68 69 // Server returns response without HTTP/2 trailers. 70 // https://test.example.com/simple.txt 71 static GURL GetSimpleURL(); 72 static std::string const GetSimpleBodyValue(); 73 static std::string const GetSimpleStatus(); 74 static std::string const GetSimpleHeaderName(); 75 static std::string const GetSimpleHeaderValue(); 76 }; 77 78 } // namespace net 79 80 #endif // NET_TEST_QUIC_SIMPLE_TEST_SERVER_H_ 81