• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2011 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 
17 package com.squareup.okhttp.mockwebserver;
18 
19 /**
20  * What should be done with the incoming socket.
21  *
22  * <p>Be careful when using values like {@link #DISCONNECT_AT_END}, {@link #SHUTDOWN_INPUT_AT_END}
23  * and {@link #SHUTDOWN_OUTPUT_AT_END} that close a socket after a response, and where there are
24  * follow-up requests. The client is unblocked and free to continue as soon as it has received the
25  * entire response body. If and when the client makes a subsequent request using a pooled socket the
26  * server may not have had time to close the socket. The socket will be closed at an indeterminate
27  * point before or during the second request. It may be closed after client has started sending the
28  * request body. If a request body is not retryable then the client may fail the request, making
29  * client behavior non-deterministic. Add delays in the client to improve the chances that the
30  * server has closed the socket before follow up requests are made.
31  */
32 public enum SocketPolicy {
33 
34   /**
35    * Keep the socket open after the response. This is the default HTTP/1.1
36    * behavior.
37    */
38   KEEP_OPEN,
39 
40   /**
41    * Close the socket after the response. This is the default HTTP/1.0
42    * behavior.
43    *
44    * <p>See {@link SocketPolicy} for reasons why this can cause test flakiness and how to avoid it.
45    */
46   DISCONNECT_AT_END,
47 
48   /**
49    * Wrap the socket with SSL at the completion of this request/response pair.
50    * Used for CONNECT messages to tunnel SSL over an HTTP proxy.
51    */
52   UPGRADE_TO_SSL_AT_END,
53 
54   /**
55    * Request immediate close of connection without even reading the request. Use
56    * to simulate buggy SSL servers closing connections in response to
57    * unrecognized TLS extensions.
58    */
59   DISCONNECT_AT_START,
60 
61   /**
62    * Close connection after reading the request but before writing the response.
63    * Use this to simulate late connection pool failures.
64    */
65   DISCONNECT_AFTER_REQUEST,
66 
67   /** Close connection after reading half of the request body (if present). */
68   DISCONNECT_DURING_REQUEST_BODY,
69 
70   /** Close connection after writing half of the response body (if present). */
71   DISCONNECT_DURING_RESPONSE_BODY,
72 
73   /** Don't trust the client during the SSL handshake. */
74   FAIL_HANDSHAKE,
75 
76   /**
77    * Shutdown the socket input after sending the response. For testing bad
78    * behavior.
79    *
80    * <p>See {@link SocketPolicy} for reasons why this can cause test flakiness and how to avoid it.
81    */
82   SHUTDOWN_INPUT_AT_END,
83 
84   /**
85    * Shutdown the socket output after sending the response. For testing bad
86    * behavior.
87    *
88    * <p>See {@link SocketPolicy} for reasons why this can cause test flakiness and how to avoid it.
89    */
90   SHUTDOWN_OUTPUT_AT_END,
91 
92   /**
93    * Don't respond to the request but keep the socket open. For testing
94    * read response header timeout issue.
95    */
96   NO_RESPONSE
97 }
98