Forward actions contain:

  • host - the host to forward to i.e. www.mock-server.com
  • port - the port to forward to, this defaults to 80 if not specified
  • scheme - the scheme to use, either HTTP or HTTPS, this defaults to HTTP if not specified

Forward actions can be further controlled using:

  • the number of times the request is forwarded (including unlimited)
  • a time to live the response will be continued to be returned (including unlimited)

Java

When mocking a forward in Java use the org.mockserver.model.HttpForward class which specifies the details of each HTTP(S) forward with a fluent API, for example:

HttpForward httpForward =
        forward()
                .withHost("www.mock-server.com")
                .withPort(80)
                .withScheme(HttpForward.Scheme.HTTP);

The full specification of org.mockserver.model.HttpForward is as follows:

public class HttpForward {

    /**
     * The host or ip address to forward the request to i.e. "www.mock-server.com"
     *
     * @param host a hostname or ip address as a string
     */
    public HttpForward withHost(String host);

    /**
     * The port to forward the request to i.e. 80.  If not specified the port defaults to 80.
     *
     * @param port a port as an integer
     */
    public HttpForward withPort(Integer port);

    /**
     * The scheme to use when forwarded the request, either HTTP or HTTPS.  If not specified the scheme defaults to HTTP.
     *
     * @param scheme the scheme as a HttpForward.Scheme value
     */
    public HttpForward withScheme(Scheme scheme);
}

JavaScript

To mock a response in javascript use JSON to specify the details with the following format:

"httpForward": {
    "host": "",
    "port": 80,
    "scheme": "HTTP"
}

The "scheme" value in can be:

"HTTP"
"HTTPS"

The same example as above would be:

"httpForward": {
    "host": "www.mock-server.com",
    "port": 80,
    "scheme": "HTTP"
}