本文整理了Java中okhttp3.Request.headers
方法的一些代码示例,展示了Request.headers
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Request.headers
方法的具体详情如下:
包路径:okhttp3.Request
类名称:Request
方法名:headers
暂无
代码示例来源:origin: square/okhttp
@Override public Response intercept(Chain chain) throws IOException {
long t1 = System.nanoTime();
Request request = chain.request();
logger.info(String.format("Sending request %s on %s%n%s",
request.url(), chain.connection(), request.headers()));
Response response = chain.proceed(request);
long t2 = System.nanoTime();
logger.info(String.format("Received response for %s in %.1fms%n%s",
request.url(), (t2 - t1) / 1e6d, response.headers()));
return response;
}
}
代码示例来源:origin: square/okhttp
/**
* Extracts an immutable request header map from the supplied {@link Headers}.
*/
static Map<String, List<String>> extractJavaHeaders(Request request) {
return JavaNetHeaders.toMultimap(request.headers(), null);
}
代码示例来源:origin: square/okhttp
@Override
public Map<String, List<String>> getRequestProperties() {
// The RI and OkHttp's HttpURLConnectionImpl fail this call after connect() as required by the
// spec. There seems no good reason why this should fail while getRequestProperty() is ok.
// We don't fail here, because we need all request header values for caching Vary responses
// correctly.
return JavaNetHeaders.toMultimap(request.headers(), null);
}
代码示例来源:origin: square/okhttp
@Override
public long getIfModifiedSince() {
return stringToLong(request.headers().get("If-Modified-Since"));
}
代码示例来源:origin: square/okhttp
/**
* Returns the subset of the headers in {@code response}'s request that impact the content of
* response's body.
*/
public static Headers varyHeaders(Response response) {
// Use the request headers sent over the network, since that's what the
// response varies on. Otherwise OkHttp-supplied headers like
// "Accept-Encoding: gzip" may be lost.
Headers requestHeaders = response.networkResponse().request().headers();
Headers responseHeaders = response.headers();
return varyHeaders(requestHeaders, responseHeaders);
}
代码示例来源:origin: prestodb/presto
@Override
public Request authenticate(Route route, Response response)
{
// skip if we already tried or were not asked for Kerberos
if (response.request().headers(AUTHORIZATION).stream().anyMatch(SpnegoHandler::isNegotiate) ||
response.headers(WWW_AUTHENTICATE).stream().noneMatch(SpnegoHandler::isNegotiate)) {
return null;
}
return authenticate(response.request());
}
代码示例来源:origin: square/okhttp
/**
* Returns true if none of the Vary headers have changed between {@code cachedRequest} and {@code
* newRequest}.
*/
public static boolean varyMatches(
Response cachedResponse, Headers cachedRequest, Request newRequest) {
for (String field : varyFields(cachedResponse)) {
if (!Objects.equals(cachedRequest.values(field), newRequest.headers(field))) return false;
}
return true;
}
代码示例来源:origin: facebook/stetho
@Override
public int headerCount() {
return mRequest.headers().size();
}
代码示例来源:origin: square/okhttp
@Override public Response intercept(Chain chain) throws IOException {
Request request = chain.request();
Headers newHeaders = request.headers()
.newBuilder()
.add("Date", new Date())
.build();
Request newRequest = request.newBuilder()
.headers(newHeaders)
.build();
return chain.proceed(newRequest);
}
}
代码示例来源:origin: facebook/stetho
@Override
public String headerName(int index) {
return mRequest.headers().name(index);
}
代码示例来源:origin: facebook/stetho
@Override
public String headerValue(int index) {
return mRequest.headers().value(index);
}
代码示例来源:origin: lingochamp/okdownload
@Override public Map<String, List<String>> getRequestProperties() {
if (request != null) {
return request.headers().toMultimap();
} else {
return requestBuilder.build().headers().toMultimap();
}
}
代码示例来源:origin: com.squareup.okhttp3/okhttp
/**
* Returns the subset of the headers in {@code response}'s request that impact the content of
* response's body.
*/
public static Headers varyHeaders(Response response) {
// Use the request headers sent over the network, since that's what the
// response varies on. Otherwise OkHttp-supplied headers like
// "Accept-Encoding: gzip" may be lost.
Headers requestHeaders = response.networkResponse().request().headers();
Headers responseHeaders = response.headers();
return varyHeaders(requestHeaders, responseHeaders);
}
代码示例来源:origin: com.squareup.okhttp3/okhttp
/**
* Returns true if none of the Vary headers have changed between {@code cachedRequest} and {@code
* newRequest}.
*/
public static boolean varyMatches(
Response cachedResponse, Headers cachedRequest, Request newRequest) {
for (String field : varyFields(cachedResponse)) {
if (!Objects.equals(cachedRequest.values(field), newRequest.headers(field))) return false;
}
return true;
}
代码示例来源:origin: JessYanCoding/MVPArms
private static String[] getRequest(Request request) {
String log;
String header = request.headers().toString();
log = METHOD_TAG + request.method() + DOUBLE_SEPARATOR +
(isEmpty(header) ? "" : HEADERS_TAG + LINE_SEPARATOR + dotHeaders(header));
return log.split(LINE_SEPARATOR);
}
代码示例来源: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
/**
* Prepares the HTTP headers and sends them to the server.
*
* <p>For streaming requests with a body, headers must be prepared <strong>before</strong> the
* output stream has been written to. Otherwise the body would need to be buffered!
*
* <p>For non-streaming requests with a body, headers must be prepared <strong>after</strong> the
* output stream has been written to and closed. This ensures that the {@code Content-Length}
* header field receives the proper value.
*/
@Override public void writeRequestHeaders(Request request) throws IOException {
String requestLine = RequestLine.get(
request, streamAllocation.connection().route().proxy().type());
writeRequest(request.headers(), requestLine);
}
代码示例来源:origin: square/okhttp
varyHeaders = HttpHeaders.varyHeaders(request.headers(), responseHeaders);
代码示例来源:origin: square/okhttp
source.timeout().timeout(readTimeout, MILLISECONDS);
sink.timeout().timeout(writeTimeout, MILLISECONDS);
tunnelConnection.writeRequest(tunnelRequest.headers(), requestLine);
tunnelConnection.finishRequest();
Response response = tunnelConnection.readResponseHeaders(false)
代码示例来源:origin: square/okhttp
Headers.Builder conditionalRequestHeaders = request.headers().newBuilder();
Internal.instance.addLenient(conditionalRequestHeaders, conditionName, conditionValue);
内容来源于网络,如有侵权,请联系作者删除!