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

How to use
header
method
in
okhttp3.Request

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

  • Common ways to obtain Request
private void myMethod () {
Request r =
  • Codota IconString url;new Request.Builder().url(url).build()
  • Codota IconURL url1;new Request.Builder().url(url1).build()
  • Smart code suggestions by Tabnine
}
origin: square/okhttp

 /**
  * Returns true if the request contains conditions that save the server from sending a response
  * that the client has locally. When a request is enqueued with its own conditions, the built-in
  * response cache won't be used.
  */
 private static boolean hasConditions(Request request) {
  return request.header("If-Modified-Since") != null || request.header("If-None-Match") != null;
 }
}
origin: square/okhttp

public static List<Header> http2HeadersList(Request request) {
 Headers headers = request.headers();
 List<Header> result = new ArrayList<>(headers.size() + 4);
 result.add(new Header(TARGET_METHOD, request.method()));
 result.add(new Header(TARGET_PATH, RequestLine.requestPath(request.url())));
 String host = request.header("Host");
 if (host != null) {
  result.add(new Header(TARGET_AUTHORITY, host)); // Optional.
 }
 result.add(new Header(TARGET_SCHEME, request.url().scheme()));
 for (int i = 0, size = headers.size(); i < size; i++) {
  // header names must be lowercase.
  String name = headers.name(i).toLowerCase(Locale.US);
  if (!HTTP_2_SKIPPED_REQUEST_HEADERS.contains(name)
    || name.equals(TE) && headers.value(i).equals("trailers")) {
   result.add(new Header(name, headers.value(i)));
  }
 }
 return result;
}
origin: square/okhttp

@Override
public String getRequestProperty(String key) {
 return request.header(key);
}
origin: com.squareup.okhttp3/okhttp

 /**
  * Returns true if the request contains conditions that save the server from sending a response
  * that the client has locally. When a request is enqueued with its own conditions, the built-in
  * response cache won't be used.
  */
 private static boolean hasConditions(Request request) {
  return request.header("If-Modified-Since") != null || request.header("If-None-Match") != null;
 }
}
origin: square/okhttp

public void run() throws Exception {
 Request request = new Request.Builder()
   .url("https://publicobject.com/helloworld.txt")
   .build();
 try (Response response = client.newCall(request).execute()) {
  System.out.println(response.request().header("Date"));
 }
}
origin: facebook/stetho

 @Nullable
 @Override
 public String firstHeaderValue(String name) {
  return mRequest.header(name);
 }
}
origin: square/okhttp

 @Override public Request authenticate(Route route, Response response) throws IOException {
  if (response.request().header("Authorization") != null) {
   return null; // Give up, we've already attempted to authenticate.
  }
  System.out.println("Authenticating for response: " + response);
  System.out.println("Challenges: " + response.challenges());
  String credential = Credentials.basic("jesse", "password1");
  return response.request().newBuilder()
    .header("Authorization", credential)
    .build();
 }
})
origin: square/okhttp

@Override public Response intercept(Chain chain) throws IOException {
 Request originalRequest = chain.request();
 if (originalRequest.body() == null || originalRequest.header("Content-Encoding") != null) {
  return chain.proceed(originalRequest);
 }
 Request compressedRequest = originalRequest.newBuilder()
   .header("Content-Encoding", "gzip")
   .method(originalRequest.method(), gzip(originalRequest.body()))
   .build();
 return chain.proceed(compressedRequest);
}
origin: square/okhttp

@Override public Sink createRequestBody(Request request, long contentLength) {
 if ("chunked".equalsIgnoreCase(request.header("Transfer-Encoding"))) {
  // Stream a request body of unknown length.
  return newChunkedSink();
 }
 if (contentLength != -1) {
  // Stream a request body of a known length.
  return newFixedLengthSink(contentLength);
 }
 throw new IllegalStateException(
   "Cannot stream a request body without chunked encoding or a known content length!");
}
origin: square/okhttp

/**
 * Now that we've buffered the entire request body, update the request headers and the body
 * itself. This happens late to enable HttpURLConnection users to complete the socket connection
 * before sending request body bytes.
 */
@Override public Request prepareToSendRequest(Request request) throws IOException {
 if (request.header("Content-Length") != null) return request;
 outputStream().close();
 contentLength = buffer.size();
 return request.newBuilder()
   .removeHeader("Transfer-Encoding")
   .header("Content-Length", Long.toString(buffer.size()))
   .build();
}
origin: com.squareup.okhttp3/okhttp

@Override public Sink createRequestBody(Request request, long contentLength) {
 if ("chunked".equalsIgnoreCase(request.header("Transfer-Encoding"))) {
  // Stream a request body of unknown length.
  return newChunkedSink();
 }
 if (contentLength != -1) {
  // Stream a request body of a known length.
  return newFixedLengthSink(contentLength);
 }
 throw new IllegalStateException(
   "Cannot stream a request body without chunked encoding or a known content length!");
}
origin: amitshekhariitbhu/Fast-Android-Networking

@Override
public void onResponse(Response okHttpResponse, String response) {
  responseRef.set(response);
  responseBodySuccess.set(okHttpResponse.isSuccessful());
  headerRef.set(okHttpResponse.request().header("headerKey"));
  latch.countDown();
}
origin: amitshekhariitbhu/Fast-Android-Networking

@Override
public void onResponse(Response okHttpResponse, String response) {
  responseRef.set(response);
  responseBodySuccess.set(okHttpResponse.isSuccessful());
  headerRef.set(okHttpResponse.request().header("headerKey"));
  latch.countDown();
}
origin: amitshekhariitbhu/Fast-Android-Networking

@Override
public void onResponse(Response okHttpResponse, User user) {
  firstNameRef.set(user.firstName);
  lastNameRef.set(user.lastName);
  responseBodySuccess.set(okHttpResponse.isSuccessful());
  headerRef.set(okHttpResponse.request().header("headerKey"));
  latch.countDown();
}
origin: amitshekhariitbhu/Fast-Android-Networking

@Override
public void onResponse(Response okHttpResponse, User user) {
  firstNameRef.set(user.firstName);
  lastNameRef.set(user.lastName);
  responseBodySuccess.set(okHttpResponse.isSuccessful());
  headerRef.set(okHttpResponse.request().header("headerKey"));
  latch.countDown();
}
origin: amitshekhariitbhu/Fast-Android-Networking

@Override
public void onResponse(Response okHttpResponse, User user) {
  firstNameRef.set(user.firstName);
  lastNameRef.set(user.lastName);
  responseBodySuccess.set(okHttpResponse.isSuccessful());
  headerRef.set(okHttpResponse.request().header("headerKey"));
  latch.countDown();
}
origin: amitshekhariitbhu/Fast-Android-Networking

@Override
public void onResponse(Response okHttpResponse, User user) {
  firstNameRef.set(user.firstName);
  lastNameRef.set(user.lastName);
  responseBodySuccess.set(okHttpResponse.isSuccessful());
  headerRef.set(okHttpResponse.request().header("headerKey"));
  latch.countDown();
}
origin: amitshekhariitbhu/Fast-Android-Networking

@Override
public void onResponse(Response okHttpResponse, JSONObject response) {
  try {
    firstNameRef.set(response.getString("firstName"));
    lastNameRef.set(response.getString("lastName"));
    responseBodySuccess.set(okHttpResponse.isSuccessful());
    headerRef.set(okHttpResponse.request().header("headerKey"));
    latch.countDown();
  } catch (JSONException e) {
    assertTrue(false);
  }
}
origin: amitshekhariitbhu/Fast-Android-Networking

@Override
public void onResponse(Response okHttpResponse, JSONObject response) {
  try {
    firstNameRef.set(response.getString("firstName"));
    lastNameRef.set(response.getString("lastName"));
    responseBodySuccess.set(okHttpResponse.isSuccessful());
    headerRef.set(okHttpResponse.request().header("headerKey"));
    latch.countDown();
  } catch (JSONException e) {
    assertTrue(false);
  }
}
origin: SonarSource/sonarqube

@Test
public void get_returns_a_OkHttpClient_with_proxy_authentication() throws Exception {
 settings.setProperty("http.proxyUser", "the-login");
 settings.setProperty("http.proxyPassword", "the-password");
 OkHttpClient client = underTest.provide(settings.asConfig(), runtime);
 Response response = new Response.Builder().protocol(Protocol.HTTP_1_1).request(new Request.Builder().url("http://foo").build()).code(407).build();
 Request request = client.proxyAuthenticator().authenticate(null, response);
 assertThat(request.header("Proxy-Authorization")).isEqualTo("Basic " + Base64.getEncoder().encodeToString("the-login:the-password".getBytes()));
}
okhttp3Requestheader

Popular methods of Request

  • newBuilder
  • url
  • method
  • body
  • headers
  • cacheControl
    Returns the cache control directives for this response. This is never null, even if this response co
  • tag
    Returns the tag attached with type as a key, or null if no tag is attached with that key.
  • toString
  • isHttps
  • <init>
  • content
  • httpUrl
  • content,
  • httpUrl,
  • requestMethod,
  • send,
  • urlString

Popular in Java

  • Reactive rest calls using spring rest template
  • onRequestPermissionsResult (Fragment)
  • getSupportFragmentManager (FragmentActivity)
  • getContentResolver (Context)
  • Color (java.awt)
    The Color class is used to encapsulate colors in the default sRGB color space or colors in arbitrary
  • GridBagLayout (java.awt)
    The GridBagLayout class is a flexible layout manager that aligns components vertically and horizonta
  • PrintWriter (java.io)
    Wraps either an existing OutputStream or an existing Writerand provides convenience methods for prin
  • TreeSet (java.util)
    TreeSet is an implementation of SortedSet. All optional operations (adding and removing) are support
  • Runner (org.openjdk.jmh.runner)
  • Location (org.springframework.beans.factory.parsing)
    Class that models an arbitrary location in a Resource.Typically used to track the location of proble
  • Top 17 Free Sublime Text Plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

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