Tabnine Logo
Response.header
Code IndexAdd Tabnine to your IDE (free)

How to use
header
method
in
okhttp3.Response

Best Java code snippets using okhttp3.Response.header (Showing top 20 results out of 1,521)

origin: square/okhttp

public @Nullable String header(String name) {
 return header(name, null);
}
origin: square/okhttp

public void run() throws Exception {
 Request request = new Request.Builder()
   .url("https://api.github.com/repos/square/okhttp/issues")
   .header("User-Agent", "OkHttp Headers.java")
   .addHeader("Accept", "application/json; q=0.5")
   .addHeader("Accept", "application/vnd.github.v3+json")
   .build();
 try (Response response = client.newCall(request).execute()) {
  if (!response.isSuccessful()) throw new IOException("Unexpected code " + response);
  System.out.println("Server: " + response.header("Server"));
  System.out.println("Date: " + response.header("Date"));
  System.out.println("Vary: " + response.headers("Vary"));
 }
}
origin: square/okhttp

private int retryAfter(Response userResponse, int defaultDelay) {
 String header = userResponse.header("Retry-After");
 if (header == null) {
  return defaultDelay;
 }
 // https://tools.ietf.org/html/rfc7231#section-7.1.3
 // currently ignores a HTTP-date, and assumes any non int 0 is a delay
 if (header.matches("\\d+")) {
  return Integer.valueOf(header);
 }
 return Integer.MAX_VALUE;
}
origin: square/okhttp

 && "gzip".equalsIgnoreCase(networkResponse.header("Content-Encoding"))
 && HttpHeaders.hasBody(networkResponse)) {
GzipSource responseBody = new GzipSource(networkResponse.body().source());
  .build();
responseBuilder.headers(strippedHeaders);
String contentType = networkResponse.header("Content-Type");
responseBuilder.body(new RealResponseBody(contentType, -1L, Okio.buffer(responseBody)));
origin: SonarSource/sonarqube

@Override
public String contentType() {
 return okResponse.header("Content-Type");
}
origin: facebook/stetho

 @Nullable
 @Override
 public String firstHeaderValue(String name) {
  return mResponse.header(name);
 }
}
origin: SonarSource/sonarqube

@Override
public Optional<String> header(String name) {
 return Optional.ofNullable(okResponse.header(name));
}
origin: com.squareup.okhttp3/okhttp

private int retryAfter(Response userResponse, int defaultDelay) {
 String header = userResponse.header("Retry-After");
 if (header == null) {
  return defaultDelay;
 }
 // https://tools.ietf.org/html/rfc7231#section-7.1.3
 // currently ignores a HTTP-date, and assumes any non int 0 is a delay
 if (header.matches("\\d+")) {
  return Integer.valueOf(header);
 }
 return Integer.MAX_VALUE;
}
origin: square/okhttp

/** Returns true if the response must have a (possibly 0-length) body. See RFC 7231. */
public static boolean hasBody(Response response) {
 // HEAD requests never yield a body regardless of the response headers.
 if (response.request().method().equals("HEAD")) {
  return false;
 }
 int responseCode = response.code();
 if ((responseCode < HTTP_CONTINUE || responseCode >= 200)
   && responseCode != HTTP_NO_CONTENT
   && responseCode != HTTP_NOT_MODIFIED) {
  return true;
 }
 // If the Content-Length or Transfer-Encoding headers disagree with the response code, the
 // response is malformed. For best compatibility, we honor the headers.
 if (contentLength(response) != -1
   || "chunked".equalsIgnoreCase(response.header("Transfer-Encoding"))) {
  return true;
 }
 return false;
}
origin: square/okhttp

void checkResponse(Response response) throws ProtocolException {
 if (response.code() != 101) {
  throw new ProtocolException("Expected HTTP 101 response but was '"
    + response.code() + " " + response.message() + "'");
 }
 String headerConnection = response.header("Connection");
 if (!"Upgrade".equalsIgnoreCase(headerConnection)) {
  throw new ProtocolException("Expected 'Connection' header value 'Upgrade' but was '"
    + headerConnection + "'");
 }
 String headerUpgrade = response.header("Upgrade");
 if (!"websocket".equalsIgnoreCase(headerUpgrade)) {
  throw new ProtocolException(
    "Expected 'Upgrade' header value 'websocket' but was '" + headerUpgrade + "'");
 }
 String headerAccept = response.header("Sec-WebSocket-Accept");
 String acceptExpected = ByteString.encodeUtf8(key + WebSocketProtocol.ACCEPT_MAGIC)
   .sha1().base64();
 if (!acceptExpected.equals(headerAccept)) {
  throw new ProtocolException("Expected 'Sec-WebSocket-Accept' header value '"
    + acceptExpected + "' but was '" + headerAccept + "'");
 }
}
origin: square/okhttp

String contentType = response.header("Content-Type");
if (responseCode != 200 || contentType == null) {
 return;
origin: openzipkin/brave

@Test public void currentSpanVisibleToOtherFilters() throws Exception {
 delegate = userFilter;
 String path = "/foo";
 Request request = new Request.Builder().url(url(path))
   .header(EXTRA_KEY, "abcdefg").build();
 try (Response response = client.newCall(request).execute()) {
  assertThat(response.isSuccessful()).isTrue();
  assertThat(response.header(EXTRA_KEY))
    .isEqualTo("abcdefg");
 }
 takeSpan();
}
origin: apollographql/apollo-android

ResponseBodyProxy(@NotNull HttpCacheRecordEditor cacheRecordEditor, @NotNull Response sourceResponse,
  @NotNull ApolloLogger logger) {
 checkNotNull(cacheRecordEditor, "cacheRecordEditor == null");
 checkNotNull(sourceResponse, "sourceResponse == null");
 checkNotNull(logger, "logger == null");
 this.contentType = sourceResponse.header("Content-Type");
 this.contentLength = sourceResponse.header("Content-Length");
 this.responseBodySource = new ProxySource(cacheRecordEditor, sourceResponse.body().source(), logger);
}
origin: square/okhttp

@Override public ResponseBody openResponseBody(Response response) throws IOException {
 streamAllocation.eventListener.responseBodyStart(streamAllocation.call);
 String contentType = response.header("Content-Type");
 if (!HttpHeaders.hasBody(response)) {
  Source source = newFixedLengthSource(0);
  return new RealResponseBody(contentType, 0, Okio.buffer(source));
 }
 if ("chunked".equalsIgnoreCase(response.header("Transfer-Encoding"))) {
  Source source = newChunkedSource(response.request().url());
  return new RealResponseBody(contentType, -1L, Okio.buffer(source));
 }
 long contentLength = HttpHeaders.contentLength(response);
 if (contentLength != -1) {
  Source source = newFixedLengthSource(contentLength);
  return new RealResponseBody(contentType, contentLength, Okio.buffer(source));
 }
 return new RealResponseBody(contentType, -1L, Okio.buffer(newUnknownLengthSource()));
}
origin: square/okhttp

String contentType = response.header("Content-Type");
long contentLength = response.body().contentLength();
return response.newBuilder()
origin: square/okhttp

@Override public ResponseBody openResponseBody(Response response) throws IOException {
 streamAllocation.eventListener.responseBodyStart(streamAllocation.call);
 String contentType = response.header("Content-Type");
 long contentLength = HttpHeaders.contentLength(response);
 Source source = new StreamFinishingSource(stream.getSource());
 return new RealResponseBody(contentType, contentLength, Okio.buffer(source));
}
origin: SonarSource/sonarqube

@Test
public void mime_type_is_set_on_response() throws Exception {
 system.pluginStream = IOUtils.toInputStream("bar");
 when(pluginRepository.hasPlugin("myplugin")).thenReturn(true);
 Response response = call("/static/myplugin/foo.css");
 assertThat(response.header("Content-Type")).isEqualTo("text/css");
 assertThat(response.body().string()).isEqualTo("bar");
}
origin: com.squareup.okhttp3/okhttp

@Override public ResponseBody openResponseBody(Response response) throws IOException {
 streamAllocation.eventListener.responseBodyStart(streamAllocation.call);
 String contentType = response.header("Content-Type");
 long contentLength = HttpHeaders.contentLength(response);
 Source source = new StreamFinishingSource(stream.getSource());
 return new RealResponseBody(contentType, contentLength, Okio.buffer(source));
}
origin: square/okhttp

if (tunnelRequest == null) throw new IOException("Failed to authenticate with proxy");
if ("close".equalsIgnoreCase(response.header("Connection"))) {
 return tunnelRequest;
origin: square/okhttp

if (response.header("Expires") != null
  || response.cacheControl().maxAgeSeconds() != -1
  || response.cacheControl().isPublic()
okhttp3Responseheader

Popular methods of Response

  • body
    Returns a non-null value if this response was passed to Callback#onResponse or returned from Call#ex
  • code
    Returns the HTTP status code.
  • isSuccessful
    Returns true if the code is in [200..300), which means the request was successfully received, unders
  • headers
  • request
    The wire-level request that initiated this HTTP response. This is not necessarily the same request i
  • newBuilder
  • message
    Returns the HTTP status message.
  • close
    Closes the response body. Equivalent to body().close().It is an error to close a response that is no
  • protocol
    Returns the HTTP protocol, such as Protocol#HTTP_1_1 or Protocol#HTTP_1_0.
  • networkResponse
    Returns the raw response received from the network. Will be null if this response didn't use the net
  • cacheResponse
    Returns the raw response received from the cache. Will be null if this response didn't use the cache
  • toString
  • cacheResponse,
  • toString,
  • handshake,
  • priorResponse,
  • sentRequestAtMillis,
  • cacheControl,
  • challenges,
  • peekBody,
  • receivedResponseAtMillis

Popular in Java

  • Finding current android device location
  • getSharedPreferences (Context)
  • getContentResolver (Context)
  • startActivity (Activity)
  • File (java.io)
    An "abstract" representation of a file system entity identified by a pathname. The pathname may be a
  • OutputStream (java.io)
    A writable sink for bytes.Most clients will use output streams that write data to the file system (
  • StringTokenizer (java.util)
    Breaks a string into tokens; new code should probably use String#split.> // Legacy code: StringTo
  • ExecutorService (java.util.concurrent)
    An Executor that provides methods to manage termination and methods that can produce a Future for tr
  • XPath (javax.xml.xpath)
    XPath provides access to the XPath evaluation environment and expressions. Evaluation of XPath Expr
  • IsNull (org.hamcrest.core)
    Is the value null?
  • Top 12 Jupyter Notebook extensions
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now