public Builder method(String method, @Nullable RequestBody body) { if (method == null) throw new NullPointerException("method == null"); if (method.length() == 0) throw new IllegalArgumentException("method.length() == 0"); if (body != null && !HttpMethod.permitsRequestBody(method)) { throw new IllegalArgumentException("method " + method + " must not have a request body."); } if (body == null && HttpMethod.requiresRequestBody(method)) { throw new IllegalArgumentException("method " + method + " must have a request body."); } this.method = method; this.body = body; return this; }
@Nullable CacheRequest put(Response response) { String requestMethod = response.request().method(); if (HttpMethod.invalidatesCache(response.request().method())) { try { remove(response.request());
if (HttpMethod.permitsRequestBody(method)) { final boolean maintainBody = HttpMethod.redirectsWithBody(method); if (HttpMethod.redirectsToGet(method)) { requestBuilder.method("GET", null); } else {
static Request buildRequest(HttpHeaders headers, byte[] content, URI uri, HttpMethod method) throws MalformedURLException { okhttp3.MediaType contentType = getContentType(headers); RequestBody body = (content.length > 0 || okhttp3.internal.http.HttpMethod.requiresRequestBody(method.name()) ? RequestBody.create(contentType, content) : null); Request.Builder builder = new Request.Builder().url(uri.toURL()).method(method.name(), body); headers.forEach((headerName, headerValues) -> { for (String headerValue : headerValues) { builder.addHeader(headerName, headerValue); } }); return builder.build(); }
if (hasBody && !HttpMethod.permitsRequestBody(method)) { throw new IllegalArgumentException("Request must not have a body: " + request);
if (HttpMethod.permitsRequestBody(method)) { if (HttpMethod.redirectsToGet(method)) { requestBuilder.method("GET", null); } else {
/** * Creates an OkHttp {@link Request} from the supplied information. * * <p>This method allows a {@code null} value for {@code requestHeaders} for situations where a * connection is already connected and access to the headers has been lost. See {@link * java.net.HttpURLConnection#getRequestProperties()} for details. */ public static Request createOkRequest( URI uri, String requestMethod, Map<String, List<String>> requestHeaders) { // OkHttp's Call API requires a placeholder body; the real body will be streamed separately. RequestBody placeholderBody = HttpMethod.requiresRequestBody(requestMethod) ? Util.EMPTY_REQUEST : null; Request.Builder builder = new Request.Builder() .url(uri.toString()) .method(requestMethod, placeholderBody); if (requestHeaders != null) { Headers headers = extractOkHeaders(requestHeaders, null); builder.headers(headers); } return builder.build(); }
} else if (!HttpMethod.permitsRequestBody(method)) { throw new ProtocolException(method + " does not support writing"); if (HttpMethod.permitsRequestBody(method)) {
if (HttpMethod.permitsRequestBody(method)) { if (HttpMethod.redirectsToGet(method)) { requestBuilder.method("GET", null); } else {
public Builder method(String method, @Nullable RequestBody body) { if (method == null) throw new NullPointerException("method == null"); if (method.length() == 0) throw new IllegalArgumentException("method.length() == 0"); if (body != null && !HttpMethod.permitsRequestBody(method)) { throw new IllegalArgumentException("method " + method + " must not have a request body."); } if (body == null && HttpMethod.requiresRequestBody(method)) { throw new IllegalArgumentException("method " + method + " must have a request body."); } this.method = method; this.body = body; return this; }
static Request buildRequest(HttpHeaders headers, byte[] content, URI uri, HttpMethod method) throws MalformedURLException { okhttp3.MediaType contentType = getContentType(headers); RequestBody body = (content.length > 0 || okhttp3.internal.http.HttpMethod.requiresRequestBody(method.name()) ? RequestBody.create(contentType, content) : null); Request.Builder builder = new Request.Builder().url(uri.toURL()).method(method.name(), body); headers.forEach((headerName, headerValues) -> { for (String headerValue : headerValues) { builder.addHeader(headerName, headerValue); } }); return builder.build(); }
if (HttpMethod.permitsRequestBody(request.method()) && request.body() != null) {
if (HttpMethod.permitsRequestBody(method)) { final boolean maintainBody = HttpMethod.redirectsWithBody(method); if (HttpMethod.redirectsToGet(method)) { requestBuilder.method("GET", null); } else {
if (HttpMethod.permitsRequestBody(method)) { if (HttpMethod.redirectsToGet(method)) { requestBuilder.method("GET", null); } else {
@Nullable CacheRequest put(Response response) { String requestMethod = response.request().method(); if (HttpMethod.invalidatesCache(response.request().method())) { try { remove(response.request());
@Override public ServerResponse getResponse(final RequestBodyDelegate delegate) throws IOException { if (HttpMethod.permitsRequestBody(mMethod) || HttpMethod.requiresRequestBody(mMethod)) { RequestBody body = new RequestBody() { @Override public long contentLength() throws IOException { return mBodyLength; } @Override public MediaType contentType() { if (mContentType == null) return null; return MediaType.parse(mContentType); } @Override public void writeTo(BufferedSink sink) throws IOException { final OkHttpBodyWriter bodyWriter = new OkHttpBodyWriter(sink); delegate.onBodyReady(bodyWriter); bodyWriter.flush(); } }; mRequestBuilder.method(mMethod, body); } else { mRequestBuilder.method(mMethod, null); } mResponse = mClient.newCall(mRequestBuilder.build()).execute(); return new ServerResponse(mResponse.code(), mResponse.body().bytes(), getServerResponseHeaders(mResponse.headers())); }
RequestBody placeholderBody = HttpMethod.requiresRequestBody(requestMethod) ? Util.EMPTY_REQUEST : null;
if (HttpMethod.permitsRequestBody(request.method()) && request.body() != null) {
if (HttpMethod.permitsRequestBody(method)) { final boolean maintainBody = HttpMethod.redirectsWithBody(method); if (HttpMethod.redirectsToGet(method)) { requestBuilder.method("GET", null); } else {
if (HttpMethod.invalidatesCache(networkRequest.method())) { try { cache.remove(networkRequest);