public OkHttpsURLConnection(URL url, OkHttpClient client, URLFilter filter) { this(new OkHttpURLConnection(url, client, filter)); }
if (callFailure != null) { if (networkResponseOnError && networkResponse != null) return networkResponse; throw propagate(callFailure); Call call = buildCall(); networkInterceptor.proceed(); executed = true; try { onResponse(call, call.execute()); } catch (IOException e) { onFailure(call, e); if (callFailure != null) throw propagate(callFailure); if (response != null) return response;
@Override public OutputStream getOutputStream() throws IOException { OutputStreamRequestBody requestBody = (OutputStreamRequestBody) buildCall().request().body(); if (requestBody == null) { throw new ProtocolException("method does not support a request body: " + method); } // If this request needs to stream bytes to the server, build a physical connection immediately // and start streaming those bytes over that connection. if (requestBody instanceof StreamedRequestBody) { connect(); networkInterceptor.proceed(); } if (requestBody.isClosed()) { throw new ProtocolException("cannot write request body after response has been read"); } return requestBody.outputStream(); }
@Override public void connect() throws IOException { if (executed) return; Call call = buildCall(); executed = true; call.enqueue(this); synchronized (lock) { try { while (connectPending && response == null && callFailure == null) { lock.wait(); // Wait 'til the network interceptor is reached or the call fails. } if (callFailure != null) { throw propagate(callFailure); } } catch (InterruptedException e) { Thread.currentThread().interrupt(); // Retain interrupted status. throw new InterruptedIOException(); } } }
@Override public Map<String, List<String>> getHeaderFields() { try { return JavaNetHeaders.toMultimap(getHeaders(), StatusLine.get(getResponse(true)).toString()); } catch (IOException e) { return Collections.emptyMap(); } }
@Override public Permission getPermission() throws IOException { URL url = getURL(); String hostname = url.getHost(); int hostPort = url.getPort() != -1 ? url.getPort() : HttpUrl.defaultPort(url.getProtocol()); if (usingProxy()) { InetSocketAddress proxyAddress = (InetSocketAddress) client.proxy().address(); hostname = proxyAddress.getHostName(); hostPort = proxyAddress.getPort(); } return new SocketPermission(hostname + ":" + hostPort, "connect, resolve"); }
requestHeaders.add("User-Agent", defaultUserAgent()); url = HttpUrl.get(getURL().toString()); } catch (IllegalArgumentException e) { if (Internal.instance.isInvalidHttpUrlHost(e)) { if (!getUseCaches()) { clientBuilder.cache(null);
private Headers getHeaders() throws IOException { if (responseHeaders == null) { Response response = getResponse(true); Headers headers = response.headers(); responseHeaders = headers.newBuilder() .add(SELECTED_PROTOCOL, response.protocol().toString()) .add(RESPONSE_SOURCE, responseSourceHeader(response)) .build(); } return responseHeaders; }
@Override public String getResponseMessage() throws IOException { return getResponse(true).message(); }
@Override public String getHeaderFieldKey(int position) { try { Headers headers = getHeaders(); if (position < 0 || position >= headers.size()) return null; return headers.name(position); } catch (IOException e) { return null; } }
requestHeaders.add("User-Agent", defaultUserAgent()); .url(Internal.instance.getHttpUrlChecked(getURL().toString())) .headers(requestHeaders.build()) .method(method, requestBody) if (!getUseCaches()) { clientBuilder.cache(null);
/** * Returns the value of the field corresponding to the {@code fieldName}, or null if there is no * such field. If the field has multiple values, the last value is returned. */ @Override public String getHeaderField(String fieldName) { try { return fieldName == null ? StatusLine.get(getResponse(true)).toString() : getHeaders().get(fieldName); } catch (IOException e) { return null; } }
private Headers getHeaders() throws IOException { if (responseHeaders == null) { Response response = getResponse(true); Headers headers = response.headers(); responseHeaders = headers.newBuilder() .add(SELECTED_PROTOCOL, response.protocol().toString()) .add(RESPONSE_SOURCE, responseSourceHeader(response)) .build(); } return responseHeaders; }
@Override public int getResponseCode() throws IOException { return getResponse(true).code(); }
@Override public Permission getPermission() throws IOException { URL url = getURL(); String hostname = url.getHost(); int hostPort = url.getPort() != -1 ? url.getPort() : HttpUrl.defaultPort(url.getProtocol()); if (usingProxy()) { InetSocketAddress proxyAddress = (InetSocketAddress) client.proxy().address(); hostname = proxyAddress.getHostName(); hostPort = proxyAddress.getPort(); } return new SocketPermission(hostname + ":" + hostPort, "connect, resolve"); }
@Override public void connect() throws IOException { if (executed) return; Call call = buildCall(); executed = true; call.enqueue(this); synchronized (lock) { try { while (connectPending && response == null && callFailure == null) { lock.wait(); // Wait 'til the network interceptor is reached or the call fails. } if (callFailure != null) { throw propagate(callFailure); } } catch (InterruptedException e) { throw new InterruptedIOException(); } } }
/** * Returns the value of the field at {@code position}. Returns null if there are fewer than {@code * position} headers. */ @Override public String getHeaderField(int position) { try { Headers headers = getHeaders(); if (position < 0 || position >= headers.size()) return null; return headers.value(position); } catch (IOException e) { return null; } }
if (callFailure != null) { if (networkResponseOnError && networkResponse != null) return networkResponse; throw propagate(callFailure); Call call = buildCall(); networkInterceptor.proceed(); executed = true; try { onResponse(call, call.execute()); } catch (IOException e) { onFailure(call, e); if (callFailure != null) throw propagate(callFailure); if (response != null) return response;
public OkHttpsURLConnection(URL url, OkHttpClient client) { this(new OkHttpURLConnection(url, client)); }
requestHeaders.add("User-Agent", defaultUserAgent()); url = HttpUrl.get(getURL().toString()); } catch (IllegalArgumentException e) { if (Internal.instance.isInvalidHttpUrlHost(e)) { if (!getUseCaches()) { clientBuilder.cache(null);