blob: 48541a479196639dc70124022d634bb51e874064 [file] [log] [blame]
jwilson7a68ed62013-04-02 22:15:19 -04001/*
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.google.mockwebserver;
17
18/**
19 * Handler for mock server requests.
20 */
21public abstract class Dispatcher {
22 /**
23 * Returns a response to satisfy {@code request}. This method may block (for
24 * instance, to wait on a CountdownLatch).
25 */
26 public abstract MockResponse dispatch(RecordedRequest request) throws InterruptedException;
27
28 /**
Neil Fullerd5e25502014-10-24 15:58:48 +010029 * Returns an early guess of the next response, used for policy on how an
30 * incoming request should be received. The default implementation returns an
31 * empty response. Mischievous implementations can return other values to test
32 * HTTP edge cases, such as unhappy socket policies or throttled request
33 * bodies.
jwilson7a68ed62013-04-02 22:15:19 -040034 */
Neil Fullerd5e25502014-10-24 15:58:48 +010035 public MockResponse peek() {
36 return new MockResponse().setSocketPolicy(SocketPolicy.KEEP_OPEN);
jwilson7a68ed62013-04-02 22:15:19 -040037 }
38}