1/*
2 * Copyright (C) 2012 Google Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package com.squareup.okhttp.mockwebserver;
17
18/** Handler for mock server requests. */
19public abstract class Dispatcher {
20  /**
21   * Returns a response to satisfy {@code request}. This method may block (for
22   * instance, to wait on a CountdownLatch).
23   */
24  public abstract MockResponse dispatch(RecordedRequest request) throws InterruptedException;
25
26  /**
27   * Returns an early guess of the next response, used for policy on how an
28   * incoming request should be received. The default implementation returns an
29   * empty response. Mischievous implementations can return other values to test
30   * HTTP edge cases, such as unhappy socket policies or throttled request
31   * bodies.
32   */
33  public MockResponse peek() {
34    return new MockResponse().setSocketPolicy(SocketPolicy.KEEP_OPEN);
35  }
36}
37