| 42 | import javax.net.ssl.SSLSocketFactory; |
| 43 | |
| 44 | public class DefaultClient implements Client { |
| 45 | |
| 46 | private final SSLSocketFactory sslContextFactory; |
| 47 | private final HostnameVerifier hostnameVerifier; |
| 48 | |
| 49 | /** |
| 50 | * Disable the request body internal buffering for {@code HttpURLConnection}. |
| 51 | * |
| 52 | * @see HttpURLConnection#setFixedLengthStreamingMode(int) |
| 53 | * @see HttpURLConnection#setFixedLengthStreamingMode(long) |
| 54 | * @see HttpURLConnection#setChunkedStreamingMode(int) |
| 55 | */ |
| 56 | private final boolean disableRequestBuffering; |
| 57 | |
| 58 | /** |
| 59 | * Create a new client, which disable request buffering by default. |
| 60 | * |
| 61 | * @param sslContextFactory SSLSocketFactory for secure https URL connections. |
| 62 | * @param hostnameVerifier the host name verifier. |
| 63 | */ |
| 64 | public DefaultClient(SSLSocketFactory sslContextFactory, HostnameVerifier hostnameVerifier) { |
| 65 | this.sslContextFactory = sslContextFactory; |
| 66 | this.hostnameVerifier = hostnameVerifier; |
| 67 | this.disableRequestBuffering = true; |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * Create a new client. |
| 72 | * |
| 73 | * @param sslContextFactory SSLSocketFactory for secure https URL connections. |
| 74 | * @param hostnameVerifier the host name verifier. |
| 75 | * @param disableRequestBuffering Disable the request body internal buffering for {@code |
| 76 | * HttpURLConnection}. |
| 77 | */ |
| 78 | public DefaultClient( |
| 79 | SSLSocketFactory sslContextFactory, |
| 80 | HostnameVerifier hostnameVerifier, |
| 81 | boolean disableRequestBuffering) { |
| 82 | super(); |
| 83 | this.sslContextFactory = sslContextFactory; |
| 84 | this.hostnameVerifier = hostnameVerifier; |
| 85 | this.disableRequestBuffering = disableRequestBuffering; |
| 86 | } |
| 87 | |
| 88 | @Override |
| 89 | public Response execute(Request request, Options options) throws IOException { |
| 90 | HttpURLConnection connection = convertAndSend(request, options); |
| 91 | return convertResponse(connection, request); |
| 92 | } |
| 93 | |
| 94 | Response convertResponse(HttpURLConnection connection, Request request) throws IOException { |
| 95 | int status = connection.getResponseCode(); |
| 96 | String reason = connection.getResponseMessage(); |
| 97 | |
| 98 | if (status < 0) { |
| 99 | throw new IOException( |
| 100 | format( |
| 101 | "Invalid status(%s) executing %s %s", |
nothing calls this directly
no outgoing calls
no test coverage detected