MockWebServer
A scriptable web server. Callers supply canned responses and the server replays them upon request in sequence.
Properties
The dispatcher used to respond to HTTP requests. The default dispatcher is a QueueDispatcher, which serves a fixed sequence of responses from a queue.
True if ALPN is used on incoming HTTPS connections to negotiate a protocol like HTTP/1.1 or HTTP/2. This is true by default; set to false to disable negotiation and restrict connections to HTTP/1.1.
The protocols supported by ALPN on incoming HTTPS connections in order of preference. The list must contain Protocol.HTTP_1_1. It must not contain null.
The number of HTTP requests received thus far by this server. This may exceed the number of HTTP connections when connection reuse is in practice.
Functions
Scripts response to be returned to a request made in sequence. The first request is served by the first enqueued response; the second request by the second enqueued response; and so on.
Configure the server to not perform SSL authentication of the client. This leaves authentication to another layer such as in an HTTP cookie or header. This is the default and most common configuration.
Configure the server to want client auth. If the client presents a certificate that is trusted the handshake will proceed normally. The connection will also proceed normally if the client presents no certificate at all! But if the client presents an untrusted certificate the handshake will fail and no connection will be established.
Configure the server to need client auth. If the client presents a certificate that is trusted the handshake will proceed normally. If the client presents an untrusted certificate or no certificate at all the handshake will fail and no connection will be established.
Starts the server on the loopback interface for the given port.
Starts the server on the given address and port.
Awaits the next HTTP request, removes it, and returns it. Callers should use this to verify the request was sent as intended. This method will block until the request is available, possibly forever.
Awaits the next HTTP request (waiting up to the specified wait time if necessary), removes it, and returns it. Callers should use this to verify the request was sent as intended within the given time.
Serve requests with HTTPS rather than otherwise.