17a68ed6a49c3060b235810391a82412a95f9c979jwilson/* 27a68ed6a49c3060b235810391a82412a95f9c979jwilson * Copyright (C) 2012 Google Inc. 37a68ed6a49c3060b235810391a82412a95f9c979jwilson * 47a68ed6a49c3060b235810391a82412a95f9c979jwilson * Licensed under the Apache License, Version 2.0 (the "License"); 57a68ed6a49c3060b235810391a82412a95f9c979jwilson * you may not use this file except in compliance with the License. 67a68ed6a49c3060b235810391a82412a95f9c979jwilson * You may obtain a copy of the License at 77a68ed6a49c3060b235810391a82412a95f9c979jwilson * 87a68ed6a49c3060b235810391a82412a95f9c979jwilson * http://www.apache.org/licenses/LICENSE-2.0 97a68ed6a49c3060b235810391a82412a95f9c979jwilson * 107a68ed6a49c3060b235810391a82412a95f9c979jwilson * Unless required by applicable law or agreed to in writing, software 117a68ed6a49c3060b235810391a82412a95f9c979jwilson * distributed under the License is distributed on an "AS IS" BASIS, 127a68ed6a49c3060b235810391a82412a95f9c979jwilson * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 137a68ed6a49c3060b235810391a82412a95f9c979jwilson * See the License for the specific language governing permissions and 147a68ed6a49c3060b235810391a82412a95f9c979jwilson * limitations under the License. 157a68ed6a49c3060b235810391a82412a95f9c979jwilson */ 167a68ed6a49c3060b235810391a82412a95f9c979jwilsonpackage com.google.mockwebserver; 177a68ed6a49c3060b235810391a82412a95f9c979jwilson 187a68ed6a49c3060b235810391a82412a95f9c979jwilson/** 197a68ed6a49c3060b235810391a82412a95f9c979jwilson * Handler for mock server requests. 207a68ed6a49c3060b235810391a82412a95f9c979jwilson */ 217a68ed6a49c3060b235810391a82412a95f9c979jwilsonpublic abstract class Dispatcher { 227a68ed6a49c3060b235810391a82412a95f9c979jwilson /** 237a68ed6a49c3060b235810391a82412a95f9c979jwilson * Returns a response to satisfy {@code request}. This method may block (for 247a68ed6a49c3060b235810391a82412a95f9c979jwilson * instance, to wait on a CountdownLatch). 257a68ed6a49c3060b235810391a82412a95f9c979jwilson */ 267a68ed6a49c3060b235810391a82412a95f9c979jwilson public abstract MockResponse dispatch(RecordedRequest request) throws InterruptedException; 277a68ed6a49c3060b235810391a82412a95f9c979jwilson 287a68ed6a49c3060b235810391a82412a95f9c979jwilson /** 29d5e25502a3ed333011753d5f2e1484072a7f5617Neil Fuller * Returns an early guess of the next response, used for policy on how an 30d5e25502a3ed333011753d5f2e1484072a7f5617Neil Fuller * incoming request should be received. The default implementation returns an 31d5e25502a3ed333011753d5f2e1484072a7f5617Neil Fuller * empty response. Mischievous implementations can return other values to test 32d5e25502a3ed333011753d5f2e1484072a7f5617Neil Fuller * HTTP edge cases, such as unhappy socket policies or throttled request 33d5e25502a3ed333011753d5f2e1484072a7f5617Neil Fuller * bodies. 347a68ed6a49c3060b235810391a82412a95f9c979jwilson */ 35d5e25502a3ed333011753d5f2e1484072a7f5617Neil Fuller public MockResponse peek() { 36d5e25502a3ed333011753d5f2e1484072a7f5617Neil Fuller return new MockResponse().setSocketPolicy(SocketPolicy.KEEP_OPEN); 377a68ed6a49c3060b235810391a82412a95f9c979jwilson } 387a68ed6a49c3060b235810391a82412a95f9c979jwilson} 39