public Response(int statusCode, InputStream body, Map<String, ? extends List<String>> headers) { this.statusCode = statusCode; this.body = body; this.headers = asUnmodifiableCaseInsensitiveMap(headers); }
/** * Returns a new builder for creating a copy of this * config. The builder is configured to use this config's * values as its default. * * @return builder for creating a copy of this config. */ public Builder copy() { return new Builder(proxy, connectTimeoutMillis, readTimeoutMillis); }
/** * Aborts this upload request and closes its underlying connection. */ public void abort() { httpUploader.abort(); }
@Override public void writeTo(BufferedSink sink) throws IOException { CountingSink countingSink = new CountingSink(sink); BufferedSink bufferedSink = Okio.buffer(countingSink); stream.writeTo(bufferedSink); bufferedSink.flush(); close(); }
@Override public void writeTo(BufferedSink sink) throws IOException { CountingSink countingSink = new CountingSink(sink); BufferedSink bufferedSink = Okio.buffer(countingSink); stream.writeTo(bufferedSink); bufferedSink.flush(); close(); }
private Response toResponse(HttpURLConnection conn) throws IOException { int responseCode = conn.getResponseCode(); InputStream bodyStream; if (responseCode >= 400 || responseCode == -1) { bodyStream = conn.getErrorStream(); } else { bodyStream = conn.getInputStream(); } interceptResponse(conn); return new Response(responseCode, bodyStream, conn.getHeaderFields()); }
@Override public Uploader startPost(String url, Iterable<Header> headers) throws IOException { HttpURLConnection conn = prepRequest(url, headers); conn.setRequestMethod("POST"); return new Uploader(conn); }
@Override public Uploader startPost(String url, Iterable<Header> headers) throws IOException { HTTPRequest request = newRequest(url, HTTPMethod.POST, headers); return new FetchServiceUploader(service, request, new ByteArrayOutputStream()); }
private void setBody(RequestBody body) { assertNoBody(); this.body = body; this.request.method(method, body); configureRequest(request); }
private BufferedUploader startUpload(String url, Iterable<Header> headers, String method) { Request.Builder builder = new Request.Builder() .url(url); toOkHttpHeaders(headers, builder); return new BufferedUploader(method, builder); }
private void setBody(RequestBody body) { assertNoBody(); this.body = body; this.request.method(method, body); configureRequest(request); }
private BufferedUploader startUpload(String url, Iterable<Header> headers, String method) { Request.Builder builder = new Request.Builder() .url(url); toOkHttpHeaders(headers, builder); return new BufferedUploader(method, builder); }
/** * Disables timeouts for opening a connection to the * servers. * * @return this builder */ public Builder withNoConnectTimeout() { return withConnectTimeout(0L, TimeUnit.MILLISECONDS); }
/** * Returns a {@link Config} with the values set by this builder. * * @return {@link Config} with this builder's values */ public Config build() { return new Config( proxy, connectTimeoutMillis, readTimeoutMillis ); }
/** * Disables timeout for receiving a response from the servers. * * @return this builder */ public Builder withNoReadTimeout() { return withReadTimeout(0L, TimeUnit.MILLISECONDS); }
@Override public void close() { stream.close(); }
@Override public HttpRequestor.Uploader startPut(String url, Iterable<Header> headers) throws IOException { return startUpload(url, headers, "PUT"); }
@Override public Uploader startPut(String url, Iterable<Header> headers) throws IOException { HttpURLConnection conn = prepRequest(url, headers); conn.setRequestMethod("PUT"); return new Uploader(conn); }
@Override public Uploader startPut(String url, Iterable<Header> headers) throws IOException { HTTPRequest request = newRequest(url, HTTPMethod.POST, headers); return new FetchServiceUploader(service, request, new ByteArrayOutputStream()); }
/** * Returns a new builder for creating a {@link Config}. * * @return builder for creating an instance of this class */ public static Builder builder() { return new Builder(); }