• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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  */
16 package com.google.mockwebserver;
17 
18 /**
19  * Handler for mock server requests.
20  */
21 public 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      */
dispatch(RecordedRequest request)26     public abstract MockResponse dispatch(RecordedRequest request) throws InterruptedException;
27 
28     /**
29      * 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.
34      */
peek()35     public MockResponse peek() {
36         return new MockResponse().setSocketPolicy(SocketPolicy.KEEP_OPEN);
37     }
38 }
39