1166772be0e5cfdaea1a64b9f63e4c8dbfe48cba3Narayan Kamath/* 2166772be0e5cfdaea1a64b9f63e4c8dbfe48cba3Narayan Kamath * Copyright (C) 2012 Google Inc. 3166772be0e5cfdaea1a64b9f63e4c8dbfe48cba3Narayan Kamath * 4166772be0e5cfdaea1a64b9f63e4c8dbfe48cba3Narayan Kamath * Licensed under the Apache License, Version 2.0 (the "License"); 5166772be0e5cfdaea1a64b9f63e4c8dbfe48cba3Narayan Kamath * you may not use this file except in compliance with the License. 6166772be0e5cfdaea1a64b9f63e4c8dbfe48cba3Narayan Kamath * You may obtain a copy of the License at 7166772be0e5cfdaea1a64b9f63e4c8dbfe48cba3Narayan Kamath * 8166772be0e5cfdaea1a64b9f63e4c8dbfe48cba3Narayan Kamath * http://www.apache.org/licenses/LICENSE-2.0 9166772be0e5cfdaea1a64b9f63e4c8dbfe48cba3Narayan Kamath * 10166772be0e5cfdaea1a64b9f63e4c8dbfe48cba3Narayan Kamath * Unless required by applicable law or agreed to in writing, software 11166772be0e5cfdaea1a64b9f63e4c8dbfe48cba3Narayan Kamath * distributed under the License is distributed on an "AS IS" BASIS, 12166772be0e5cfdaea1a64b9f63e4c8dbfe48cba3Narayan Kamath * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13166772be0e5cfdaea1a64b9f63e4c8dbfe48cba3Narayan Kamath * See the License for the specific language governing permissions and 14166772be0e5cfdaea1a64b9f63e4c8dbfe48cba3Narayan Kamath * limitations under the License. 15166772be0e5cfdaea1a64b9f63e4c8dbfe48cba3Narayan Kamath */ 16166772be0e5cfdaea1a64b9f63e4c8dbfe48cba3Narayan Kamathpackage com.squareup.okhttp.mockwebserver; 17166772be0e5cfdaea1a64b9f63e4c8dbfe48cba3Narayan Kamath 18166772be0e5cfdaea1a64b9f63e4c8dbfe48cba3Narayan Kamath/** Handler for mock server requests. */ 19166772be0e5cfdaea1a64b9f63e4c8dbfe48cba3Narayan Kamathpublic abstract class Dispatcher { 20166772be0e5cfdaea1a64b9f63e4c8dbfe48cba3Narayan Kamath /** 21166772be0e5cfdaea1a64b9f63e4c8dbfe48cba3Narayan Kamath * Returns a response to satisfy {@code request}. This method may block (for 22166772be0e5cfdaea1a64b9f63e4c8dbfe48cba3Narayan Kamath * instance, to wait on a CountdownLatch). 23166772be0e5cfdaea1a64b9f63e4c8dbfe48cba3Narayan Kamath */ 24166772be0e5cfdaea1a64b9f63e4c8dbfe48cba3Narayan Kamath public abstract MockResponse dispatch(RecordedRequest request) throws InterruptedException; 25166772be0e5cfdaea1a64b9f63e4c8dbfe48cba3Narayan Kamath 26166772be0e5cfdaea1a64b9f63e4c8dbfe48cba3Narayan Kamath /** 2778092f38ebd93018ead53a87b53118dc829cbb8aNeil Fuller * Returns an early guess of the next response, used for policy on how an 2878092f38ebd93018ead53a87b53118dc829cbb8aNeil Fuller * incoming request should be received. The default implementation returns an 2978092f38ebd93018ead53a87b53118dc829cbb8aNeil Fuller * empty response. Mischievous implementations can return other values to test 3078092f38ebd93018ead53a87b53118dc829cbb8aNeil Fuller * HTTP edge cases, such as unhappy socket policies or throttled request 3178092f38ebd93018ead53a87b53118dc829cbb8aNeil Fuller * bodies. 32166772be0e5cfdaea1a64b9f63e4c8dbfe48cba3Narayan Kamath */ 3378092f38ebd93018ead53a87b53118dc829cbb8aNeil Fuller public MockResponse peek() { 3478092f38ebd93018ead53a87b53118dc829cbb8aNeil Fuller return new MockResponse().setSocketPolicy(SocketPolicy.KEEP_OPEN); 3578092f38ebd93018ead53a87b53118dc829cbb8aNeil Fuller } 3678092f38ebd93018ead53a87b53118dc829cbb8aNeil Fuller 3778092f38ebd93018ead53a87b53118dc829cbb8aNeil Fuller /** @deprecated replaced with {@link #peek}. */ 3878092f38ebd93018ead53a87b53118dc829cbb8aNeil Fuller protected final SocketPolicy peekSocketPolicy() { 3978092f38ebd93018ead53a87b53118dc829cbb8aNeil Fuller throw new UnsupportedOperationException("This API is obsolete. Override peek() instead!"); 40166772be0e5cfdaea1a64b9f63e4c8dbfe48cba3Narayan Kamath } 41166772be0e5cfdaea1a64b9f63e4c8dbfe48cba3Narayan Kamath} 42