• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2012 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_EMBEDDED_TEST_SERVER_EMBEDDED_TEST_SERVER_H_
6 #define NET_TEST_EMBEDDED_TEST_SERVER_EMBEDDED_TEST_SERVER_H_
7 
8 #include <stdint.h>
9 
10 #include <map>
11 #include <memory>
12 #include <string>
13 #include <vector>
14 
15 #include "base/files/file_path.h"
16 #include "base/functional/callback.h"
17 #include "base/memory/raw_ptr.h"
18 #include "base/memory/raw_ptr_exclusion.h"
19 #include "base/memory/scoped_refptr.h"
20 #include "base/memory/weak_ptr.h"
21 #include "base/strings/string_piece.h"
22 #include "base/threading/thread.h"
23 #include "base/threading/thread_checker.h"
24 #include "net/base/address_list.h"
25 #include "net/base/host_port_pair.h"
26 #include "net/base/ip_endpoint.h"
27 #include "net/cert/ocsp_revocation_status.h"
28 #include "net/cert/test_root_certs.h"
29 #include "net/cert/x509_certificate.h"
30 #include "net/socket/ssl_server_socket.h"
31 #include "net/socket/stream_socket.h"
32 #include "net/socket/tcp_server_socket.h"
33 #include "net/ssl/ssl_server_config.h"
34 #include "net/test/embedded_test_server/http_connection.h"
35 #include "third_party/abseil-cpp/absl/types/optional.h"
36 #include "url/gurl.h"
37 #include "url/origin.h"
38 
39 namespace net {
40 
41 class StreamSocket;
42 class TCPServerSocket;
43 
44 namespace test_server {
45 
46 class EmbeddedTestServerConnectionListener;
47 class HttpConnection;
48 class HttpResponse;
49 class HttpResponseDelegate;
50 struct HttpRequest;
51 
52 class EmbeddedTestServer;
53 
54 // Returned by the Start[AcceptingConnections]WithHandle() APIs, to simplify
55 // correct shutdown ordering of the EmbeddedTestServer. Shutdown() is invoked
56 // on the associated test server when the handle goes out of scope. The handle
57 // must therefore be destroyed before the test server.
58 class EmbeddedTestServerHandle {
59  public:
60   EmbeddedTestServerHandle() = default;
61   EmbeddedTestServerHandle(EmbeddedTestServerHandle&& other);
62   EmbeddedTestServerHandle& operator=(EmbeddedTestServerHandle&& other);
63   ~EmbeddedTestServerHandle();
64 
is_valid()65   bool is_valid() const { return test_server_; }
66   explicit operator bool() const { return test_server_; }
67 
68  private:
69   friend class EmbeddedTestServer;
70 
71   explicit EmbeddedTestServerHandle(EmbeddedTestServer* test_server);
72   // This field is not a raw_ptr<> because it was filtered by the rewriter for:
73   // #constexpr-ctor-field-initializer
74   RAW_PTR_EXCLUSION EmbeddedTestServer* test_server_ = nullptr;
75 };
76 
77 // Class providing an HTTP server for testing purpose. This is a basic server
78 // providing only an essential subset of HTTP/1.1 protocol. Especially,
79 // it assumes that the request syntax is correct. It *does not* support
80 // a Chunked Transfer Encoding.
81 //
82 // The common use case for unit tests is below:
83 //
84 // void SetUp() {
85 //   test_server_ = std::make_unique<EmbeddedTestServer>();
86 //   test_server_->RegisterRequestHandler(
87 //       base::BindRepeating(&FooTest::HandleRequest, base::Unretained(this)));
88 //   ASSERT_TRUE((test_server_handle_ = test_server_.StartAndReturnHandle()));
89 // }
90 //
91 // std::unique_ptr<HttpResponse> HandleRequest(const HttpRequest& request) {
92 //   GURL absolute_url = test_server_->GetURL(request.relative_url);
93 //   if (absolute_url.path() != "/test")
94 //     return nullptr;
95 //
96 //   auto http_response = std::make_unique<BasicHttpResponse>();
97 //   http_response->set_code(net::HTTP_OK);
98 //   http_response->set_content("hello");
99 //   http_response->set_content_type("text/plain");
100 //   return http_response;
101 // }
102 //
103 // For a test that spawns another process such as browser_tests, it is
104 // suggested to call Start in SetUpOnMainThread after the process is spawned.
105 //  If you have to do it before the process spawns, you need to first setup the
106 // listen socket so that there is no no other threads running while spawning
107 // the process. To do so, please follow the following example:
108 //
109 // void SetUp() {
110 //   ASSERT_TRUE(embedded_test_server()->InitializeAndListen());
111 //   ...
112 //   InProcessBrowserTest::SetUp();
113 // }
114 //
115 // void SetUpOnMainThread() {
116 //   // Starts the accept IO thread.
117 //   embedded_test_server()->StartAcceptingConnections();
118 // }
119 //
120 class EmbeddedTestServer {
121  public:
122   enum Type {
123     TYPE_HTTP,
124     TYPE_HTTPS,
125   };
126 
127   // A Java counterpart will be generated for this enum.
128   // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.net.test
129   enum ServerCertificate {
130     CERT_OK,
131 
132     CERT_MISMATCHED_NAME,
133     CERT_EXPIRED,
134 
135     // Cross-signed certificate to test PKIX path building. Contains an
136     // intermediate cross-signed by an unknown root, while the client (via
137     // TestRootStore) is expected to have a self-signed version of the
138     // intermediate.
139     CERT_CHAIN_WRONG_ROOT,
140 
141     // Causes the testserver to use a hostname that is a domain
142     // instead of an IP.
143     CERT_COMMON_NAME_IS_DOMAIN,
144 
145     // A certificate that only contains a commonName, rather than also
146     // including a subjectAltName extension.
147     CERT_COMMON_NAME_ONLY,
148 
149     // A certificate that is a leaf certificate signed with SHA-1.
150     CERT_SHA1_LEAF,
151 
152     // A certificate that is signed by an intermediate certificate.
153     CERT_OK_BY_INTERMEDIATE,
154 
155     // A certificate with invalid notBefore and notAfter times. Windows'
156     // certificate library will not parse this certificate.
157     CERT_BAD_VALIDITY,
158 
159     // A certificate that covers a number of test names. See [test_names] in
160     // net/data/ssl/scripts/ee.cnf. More may be added by editing this list and
161     // and rerunning net/data/ssl/scripts/generate-test-certs.sh.
162     CERT_TEST_NAMES,
163 
164     // An RSA certificate with the keyUsage extension specifying that the key
165     // is only for encipherment.
166     CERT_KEY_USAGE_RSA_ENCIPHERMENT,
167 
168     // An RSA certificate with the keyUsage extension specifying that the key
169     // is only for digital signatures.
170     CERT_KEY_USAGE_RSA_DIGITAL_SIGNATURE,
171 
172     // A certificate will be generated at runtime. A ServerCertificateConfig
173     // passed to SetSSLConfig may be used to configure the details of the
174     // generated certificate.
175     CERT_AUTO,
176   };
177 
178   enum class IntermediateType {
179     // Generated cert is issued directly by the CA.
180     kNone,
181     // Generated cert is issued by a generated intermediate cert, which is
182     // included in the TLS handshake.
183     kInHandshake,
184     // Generated cert is issued by a generated intermediate, which is NOT
185     // included in the TLS handshake, but is available through the leaf's
186     // AIA caIssuers URL.
187     kByAIA,
188   };
189 
190   struct OCSPConfig {
191     // Enumerates the types of OCSP response that the testserver can produce.
192     enum class ResponseType {
193       // OCSP will not be enabled for the corresponding config.
194       kOff,
195       // These correspond to the OCSPResponseStatus enumeration in RFC
196       // 6960.
197       kSuccessful,
198       kMalformedRequest,
199       kInternalError,
200       kTryLater,
201       kSigRequired,
202       kUnauthorized,
203       // The response will not be valid OCSPResponse DER.
204       kInvalidResponse,
205       // OCSPResponse will be valid DER but the contained ResponseData will not.
206       kInvalidResponseData,
207     };
208 
209     // OCSPProduced describes the time of the producedAt field in the
210     // OCSP response relative to the certificate the response is for.
211     enum class Produced {
212       // producedAt is between certificate's notBefore and notAfter dates.
213       kValid,
214       // producedAt is before certificate's notBefore date.
215       kBeforeCert,
216       // producedAt is after certificate's notAfter date.
217       kAfterCert,
218     };
219 
220     struct SingleResponse {
221       // Date describes the thisUpdate..nextUpdate ranges for OCSP
222       // singleResponses, relative to the current time.
223       enum class Date {
224         // The singleResponse is valid for 7 days, and includes the current
225         // time.
226         kValid,
227         // The singleResponse is valid for 7 days, but nextUpdate is before the
228         // current time.
229         kOld,
230         // The singleResponse is valid for 7 days, but thisUpdate is after the
231         // current time.
232         kEarly,
233         // The singleResponse is valid for 366 days, and includes the current
234         // time.
235         kLong,
236         // The singleResponse is valid for 368 days, and includes the current
237         // time.
238         kLonger,
239       };
240 
241       // Configures whether a generated OCSP singleResponse's serial field
242       // matches the serial number of the target certificate.
243       enum class Serial {
244         kMatch,
245         kMismatch,
246       };
247 
248       OCSPRevocationStatus cert_status = OCSPRevocationStatus::GOOD;
249       Date ocsp_date = Date::kValid;
250       Serial serial = Serial::kMatch;
251     };
252 
253     OCSPConfig();
254     // Configure OCSP response with |response_type|.
255     explicit OCSPConfig(ResponseType response_type);
256     // Configure a successful OCSP response with |single_responses|. |produced|
257     // specifies the response's producedAt value, relative to the validity
258     // period of the certificate the OCSPConfig is for.
259     explicit OCSPConfig(std::vector<SingleResponse> single_responses,
260                         Produced produced = Produced::kValid);
261     OCSPConfig(const OCSPConfig&);
262     OCSPConfig(OCSPConfig&&);
263     ~OCSPConfig();
264     OCSPConfig& operator=(const OCSPConfig&);
265     OCSPConfig& operator=(OCSPConfig&&);
266 
267     ResponseType response_type = ResponseType::kOff;
268     Produced produced = Produced::kValid;
269     std::vector<SingleResponse> single_responses;
270   };
271 
272   // Configuration for generated server certificate.
273   struct ServerCertificateConfig {
274     ServerCertificateConfig();
275     ServerCertificateConfig(const ServerCertificateConfig&);
276     ServerCertificateConfig(ServerCertificateConfig&&);
277     ~ServerCertificateConfig();
278     ServerCertificateConfig& operator=(const ServerCertificateConfig&);
279     ServerCertificateConfig& operator=(ServerCertificateConfig&&);
280 
281     // Configure whether the generated certificate chain should include an
282     // intermediate, and if so, how it is delivered to the client.
283     IntermediateType intermediate = IntermediateType::kNone;
284 
285     // Configure OCSP handling.
286     // Note: In the current implementation the AIA request handler does not
287     // actually parse the OCSP request (a different OCSP URL is used for each
288     // cert). So this is useful for testing the client's handling of the OCSP
289     // response, but not for testing that the client is sending a proper OCSP
290     // request.
291     //
292     // AIA OCSP for the leaf cert. If |kOff|, no AIA OCSP URL will be included
293     // in the leaf cert.
294     OCSPConfig ocsp_config;
295     // Stapled OCSP for the leaf cert. If |kOff|, OCSP Stapling will not be
296     // used.
297     OCSPConfig stapled_ocsp_config;
298     // AIA OCSP for the intermediate cert. If |kOff|, no AIA OCSP URL will be
299     // included in the intermediate cert. It is invalid to supply a
300     // configuration other than |kOff| if |intermediate| is |kNone|.
301     OCSPConfig intermediate_ocsp_config;
302 
303     // Certificate policy OIDs, in text notation (e.g. "1.2.3.4"). If
304     // non-empty, the policies will be added to the leaf cert and the
305     // intermediate cert (if an intermediate is configured).
306     std::vector<std::string> policy_oids;
307 
308     // A list of DNS names to include in the leaf subjectAltName extension.
309     std::vector<std::string> dns_names;
310 
311     // A list of IP addresses to include in the leaf subjectAltName extension.
312     std::vector<net::IPAddress> ip_addresses;
313   };
314 
315   typedef base::RepeatingCallback<std::unique_ptr<HttpResponse>(
316       const HttpRequest& request)>
317       HandleRequestCallback;
318   typedef base::RepeatingCallback<void(const HttpRequest& request)>
319       MonitorRequestCallback;
320 
321   // Creates a http test server. StartAndReturnHandle() must be called to start
322   // the server.
323   // |type| indicates the protocol type of the server (HTTP/HTTPS).
324   //
325   //  When a TYPE_HTTPS server is created, EmbeddedTestServer will call
326   // EmbeddedTestServer::RegisterTestCerts(), so that when the default
327   // CertVerifiers are run in-process, they will recognize the test server's
328   // certs. However, if the test server is running in a different process from
329   // the CertVerifiers, EmbeddedTestServer::RegisterTestCerts() must be called
330   // in any process where CertVerifiers are expected to accept the
331   // EmbeddedTestServer's certs.
332   EmbeddedTestServer();
333   explicit EmbeddedTestServer(
334       Type type,
335       HttpConnection::Protocol protocol = HttpConnection::Protocol::kHttp1);
336   ~EmbeddedTestServer();
337 
338   //  Send a request to the server to be handled. If a response is created,
339   //  SendResponseBytes() should be called on the provided HttpConnection.
340   void HandleRequest(base::WeakPtr<HttpResponseDelegate> connection,
341                      std::unique_ptr<HttpRequest> request);
342 
343   // Notify the server that a connection is no longer usable and is safe to
344   // destroy. For H/1 connections, this means a single request/response
345   // interaction, as keep-alive connections are not supported. If the
346   // connection listener is present and the socket is still connected, the
347   // listener will be notified.
348   void RemoveConnection(
349       HttpConnection* connection,
350       EmbeddedTestServerConnectionListener* listener = nullptr);
351 
352   // Registers the EmbeddedTestServer's certs for the current process. See
353   // constructor documentation for more information.
354   [[nodiscard]] static ScopedTestRoot RegisterTestCerts();
355 
356   // Sets a connection listener, that would be notified when various connection
357   // events happen. May only be called before the server is started. Caller
358   // maintains ownership of the listener.
359   void SetConnectionListener(EmbeddedTestServerConnectionListener* listener);
360 
361   // Initializes and waits until the server is ready to accept requests.
362   // This is the equivalent of calling InitializeAndListen() followed by
363   // StartAcceptingConnectionsAndReturnHandle().
364   // Returns a "handle" which will ShutdownAndWaitUntilComplete() when
365   // destroyed, or null if the listening socket could not be created.
366   [[nodiscard]] EmbeddedTestServerHandle StartAndReturnHandle(int port = 0);
367 
368   // Equivalent of StartAndReturnHandle(), but requires manual Shutdown() by
369   // the caller.
370   [[nodiscard]] bool Start(int port = 0);
371 
372   // Starts listening for incoming connections but will not yet accept them.
373   // Returns whether a listening socket has been succesfully created.
374   [[nodiscard]] bool InitializeAndListen(int port = 0);
375 
376   // Starts the Accept IO Thread and begins accepting connections.
377   [[nodiscard]] EmbeddedTestServerHandle
378   StartAcceptingConnectionsAndReturnHandle();
379 
380   // Equivalent of StartAcceptingConnectionsAndReturnHandle(), but requires
381   // manual Shutdown() by the caller.
382   void StartAcceptingConnections();
383 
384   // Shuts down the http server and waits until the shutdown is complete.
385   // Prefer to use the Start*AndReturnHandle() APIs to manage shutdown, if
386   // possible.
387   [[nodiscard]] bool ShutdownAndWaitUntilComplete();
388 
389   // Checks if the server has started listening for incoming connections.
Started()390   bool Started() const { return listen_socket_.get() != nullptr; }
391 
392   static base::FilePath GetRootCertPemPath();
393 
host_port_pair()394   HostPortPair host_port_pair() const {
395     return HostPortPair::FromURL(base_url_);
396   }
397 
398   // Returns the base URL to the server, which looks like
399   // http://127.0.0.1:<port>/, where <port> is the actual port number used by
400   // the server.
base_url()401   const GURL& base_url() const { return base_url_; }
402 
403   // Returns a URL to the server based on the given relative URL, which
404   // should start with '/'. For example: GetURL("/path?query=foo") =>
405   // http://127.0.0.1:<port>/path?query=foo.
406   GURL GetURL(base::StringPiece relative_url) const;
407 
408   // Similar to the above method with the difference that it uses the supplied
409   // |hostname| for the URL instead of 127.0.0.1. The hostname should be
410   // resolved to 127.0.0.1.
411   GURL GetURL(base::StringPiece hostname, base::StringPiece relative_url) const;
412 
413   // Convenience function equivalent to calling url::Origin::Create(base_url()).
414   // Will use the GetURL() variant that takes a hostname as the base URL, if
415   // `hostname` is non-null.
416   url::Origin GetOrigin(
417       const absl::optional<std::string>& hostname = absl::nullopt) const;
418 
419   // Returns the address list needed to connect to the server.
420   [[nodiscard]] bool GetAddressList(AddressList* address_list) const;
421 
422   // Returns the IP Address to connect to the server as a string.
423   std::string GetIPLiteralString() const;
424 
425   // Returns the port number used by the server.
port()426   uint16_t port() const { return port_; }
427 
428   // SetSSLConfig sets the SSL configuration for the server. It is invalid to
429   // call after the server is started. If called multiple times, the last call
430   // will have effect.
431   void SetSSLConfig(ServerCertificate cert, const SSLServerConfig& ssl_config);
432   void SetSSLConfig(ServerCertificate cert);
433   void SetSSLConfig(const ServerCertificateConfig& cert_config,
434                     const SSLServerConfig& ssl_config);
435   void SetSSLConfig(const ServerCertificateConfig& cert_config);
436 
437   // TODO(mattm): make this [[nodiscard]]
438   bool ResetSSLConfig(ServerCertificate cert,
439                       const SSLServerConfig& ssl_config);
440 
441   // Returns the certificate that the server is using.
442   // If using a generated ServerCertificate type, this must not be called before
443   // InitializeAndListen() has been called.
444   scoped_refptr<X509Certificate> GetCertificate();
445 
446   // Registers request handler which serves files from |directory|.
447   // For instance, a request to "/foo.html" is served by "foo.html" under
448   // |directory|. Files under sub directories are also handled in the same way
449   // (i.e. "/foo/bar.html" is served by "foo/bar.html" under |directory|).
450   // TODO(svaldez): Merge ServeFilesFromDirectory and
451   // ServeFilesFromSourceDirectory.
452   void ServeFilesFromDirectory(const base::FilePath& directory);
453 
454   // Serves files relative to DIR_SOURCE_ROOT.
455   void ServeFilesFromSourceDirectory(base::StringPiece relative);
456   void ServeFilesFromSourceDirectory(const base::FilePath& relative);
457 
458   // Registers the default handlers and serve additional files from the
459   // |directory| directory, relative to DIR_SOURCE_ROOT.
460   void AddDefaultHandlers(const base::FilePath& directory);
461 
462   // Returns the directory that files will be served from if |relative| is
463   // passed to ServeFilesFromSourceDirectory().
464   static base::FilePath GetFullPathFromSourceDirectory(
465       const base::FilePath& relative);
466 
467   // Adds all default handlers except, without serving additional files from any
468   // directory.
469   void AddDefaultHandlers();
470 
471   // Adds a request handler that can perform any general-purpose processing.
472   // |callback| will be invoked on the server's IO thread. Note that:
473   // 1. All handlers must be registered before the server is Start()ed.
474   // 2. The server should be Shutdown() before any variables referred to by
475   //    |callback| (e.g. via base::Unretained(&local)) are deleted. Using the
476   //    Start*WithHandle() API variants is recommended for this reason.
477   void RegisterRequestHandler(const HandleRequestCallback& callback);
478 
479   // Adds a request monitor that will be called before any handlers. Monitors
480   // can be used to observe requests, but not to respond to them.
481   // See RegisterRequestHandler() for notes on usage.
482   void RegisterRequestMonitor(const MonitorRequestCallback& callback);
483 
484   // Adds a default request handler, to be called if no user-specified handler
485   // handles the request.
486   // See RegisterRequestHandler() for notes on usage.
487   void RegisterDefaultHandler(const HandleRequestCallback& callback);
488 
489   bool FlushAllSocketsAndConnectionsOnUIThread();
490   void FlushAllSocketsAndConnections();
491 
492   // Adds an origin/accept_ch pair to add to an ACCEPT_CH HTTP/2 frame. If any
493   // pairs have been added, the ALPS TLS extension will be populated, which
494   // will act as though an ACCEPT_CH frame was sent by the server before the
495   // first frame is sent by a client. For more information, see
496   // draft-vvv-tls-alps-01 and section 4.1 (HTTP/2 ACCEPT_CH Frame) of
497   // draft-davidben-http-client-hint-reliability
498   //
499   // Only valid before Start() or ResetSSLServerConfig(). Only valid when
500   // constructed with PROTOCOL_HTTP2. For the default host, use an empty
501   // string.
502   void SetAlpsAcceptCH(std::string hostname, std::string accept_ch);
503 
504  private:
505   // Returns the file name of the certificate the server is using. The test
506   // certificates can be found in net/data/ssl/certificates/.
507   std::string GetCertificateName() const;
508 
509   // Shuts down the server.
510   void ShutdownOnIOThread();
511 
512   // Sets the SSL configuration for the server. It is invalid for |cert_config|
513   // to be non-null if |cert| is not CERT_AUTO.
514   void SetSSLConfigInternal(ServerCertificate cert,
515                             const ServerCertificateConfig* cert_config,
516                             const SSLServerConfig& ssl_config);
517 
518   // Resets the SSLServerConfig on the IO thread.
519   bool ResetSSLConfigOnIOThread(ServerCertificate cert,
520                                 const SSLServerConfig& ssl_config);
521 
522   // Upgrade the TCP connection to one over SSL.
523   std::unique_ptr<SSLServerSocket> DoSSLUpgrade(
524       std::unique_ptr<StreamSocket> connection);
525   // Handles async callback when the SSL handshake has been completed.
526   void OnHandshakeDone(HttpConnection* http_connection, int rv);
527   // Begins new connection if handshake resulted in a connection
528   void HandleHandshakeResults();
529 
530   // Begins accepting new client connections.
531   void DoAcceptLoop();
532   // Handles async callback when there is a new client socket. |rv| is the
533   // return value of the socket Accept.
534   void OnAcceptCompleted(int rv);
535   // Adds the new |socket| to the list of clients and begins the reading
536   // data.
537   void HandleAcceptResult(std::unique_ptr<StreamSocket> socket_ptr);
538 
539   // Create a connection with a socket, add it to the map, and return pointers
540   // to both.
541   HttpConnection* AddConnection(std::unique_ptr<StreamSocket> socket_ptr);
542 
543   // Handles async callback when new data has been read from the |connection|.
544   void OnReadCompleted(HttpConnection* connection, int rv);
545 
546   // Returns true if the current |cert_| configuration uses a static
547   // pre-generated cert loaded from the filesystem.
548   bool UsingStaticCert() const;
549 
550   // Reads server certificate and private key from file. May only be called if
551   // |cert_| refers to a file-based cert & key.
552   [[nodiscard]] bool InitializeCertAndKeyFromFile();
553 
554   // Generate server certificate and private key. May only be called if |cert_|
555   // refers to a generated cert & key.
556   [[nodiscard]] bool GenerateCertAndKey();
557 
558   // Initializes the SSLServerContext so that SSLServerSocket connections may
559   // share the same cache
560   [[nodiscard]] bool InitializeSSLServerContext();
561 
562   // Posts a task to the |io_thread_| and waits for a reply.
563   [[nodiscard]] bool PostTaskToIOThreadAndWait(base::OnceClosure closure);
564 
565   // Posts a task that returns a true/false success/fail value to the
566   // |io_thread_| and waits for a reply.
567   [[nodiscard]] bool PostTaskToIOThreadAndWaitWithResult(
568       base::OnceCallback<bool()> task);
569 
570   const bool is_using_ssl_;
571   const HttpConnection::Protocol protocol_;
572 
573   std::unique_ptr<base::Thread> io_thread_;
574 
575   std::unique_ptr<TCPServerSocket> listen_socket_;
576   std::unique_ptr<StreamSocket> accepted_socket_;
577 
578   raw_ptr<EmbeddedTestServerConnectionListener, DanglingUntriaged>
579       connection_listener_ = nullptr;
580   uint16_t port_ = 0;
581   GURL base_url_;
582   IPEndPoint local_endpoint_;
583 
584   std::map<const StreamSocket*, std::unique_ptr<HttpConnection>> connections_;
585 
586   // Vector of registered and default request handlers and monitors.
587   std::vector<HandleRequestCallback> request_handlers_;
588   std::vector<MonitorRequestCallback> request_monitors_;
589   std::vector<HandleRequestCallback> default_request_handlers_;
590 
591   base::ThreadChecker thread_checker_;
592 
593   ScopedTestRoot scoped_test_root_;
594   net::SSLServerConfig ssl_config_;
595   ServerCertificate cert_ = CERT_OK;
596   ServerCertificateConfig cert_config_;
597   scoped_refptr<X509Certificate> x509_cert_;
598   bssl::UniquePtr<EVP_PKEY> private_key_;
599   base::flat_map<std::string, std::string> alps_accept_ch_;
600   std::unique_ptr<SSLServerContext> context_;
601 
602   // HTTP server that handles AIA URLs that are embedded in this test server's
603   // certificate when the server certificate is one of the CERT_AUTO variants.
604   std::unique_ptr<EmbeddedTestServer> aia_http_server_;
605 
606   base::WeakPtrFactory<EmbeddedTestServer> weak_factory_{this};
607 };
608 
609 }  // namespace test_server
610 
611 // TODO(svaldez): Refactor EmbeddedTestServer to be in the net namespace.
612 using test_server::EmbeddedTestServer;
613 
614 }  // namespace net
615 
616 #endif  // NET_TEST_EMBEDDED_TEST_SERVER_EMBEDDED_TEST_SERVER_H_
617