当前位置: 首页>>代码示例>>Java>>正文


Java Version类代码示例

本文整理汇总了Java中okhttp3.internal.Version的典型用法代码示例。如果您正苦于以下问题:Java Version类的具体用法?Java Version怎么用?Java Version使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Version类属于okhttp3.internal包,在下文中一共展示了Version类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createTunnelRequest

import okhttp3.internal.Version; //导入依赖的package包/类
/**
 * Returns a request that creates a TLS tunnel via an HTTP proxy. Everything in the tunnel request
 * is sent unencrypted to the proxy server, so tunnels include only the minimum set of headers.
 * This avoids sending potentially sensitive data like HTTP cookies to the proxy unencrypted.
 */
private Request createTunnelRequest() {
  return new Request.Builder()
      .url(route.address().url())
      .header("Host", Util.hostHeader(route.address().url(), true))
      .header("Proxy-Connection", "Keep-Alive") // For HTTP/1.0 proxies like Squid.
      .header("User-Agent", Version.userAgent())
      .build();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:14,代码来源:RealConnection.java

示例2: userAgentIsIncludedByDefault

import okhttp3.internal.Version; //导入依赖的package包/类
@Test public void userAgentIsIncludedByDefault() throws Exception {
  server.enqueue(new MockResponse());

  executeSynchronously("/");

  RecordedRequest recordedRequest = server.takeRequest();
  assertTrue(recordedRequest.getHeader("User-Agent")
      .matches(Version.userAgent()));
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:10,代码来源:CallTest.java

示例3: proxyConnectOmitsApplicationHeaders

import okhttp3.internal.Version; //导入依赖的package包/类
/** Test which headers are sent unencrypted to the HTTP proxy. */
@Test public void proxyConnectOmitsApplicationHeaders() throws Exception {
  server.useHttps(sslClient.socketFactory, true);
  server.enqueue(new MockResponse()
      .setSocketPolicy(SocketPolicy.UPGRADE_TO_SSL_AT_END)
      .clearHeaders());
  server.enqueue(new MockResponse()
      .setBody("encrypted response from the origin server"));

  RecordingHostnameVerifier hostnameVerifier = new RecordingHostnameVerifier();
  client = client.newBuilder()
      .sslSocketFactory(sslClient.socketFactory, sslClient.trustManager)
      .proxy(server.toProxyAddress())
      .hostnameVerifier(hostnameVerifier)
      .build();

  Request request = new Request.Builder()
      .url("https://android.com/foo")
      .header("Private", "Secret")
      .header("User-Agent", "App 1.0")
      .build();
  Response response = client.newCall(request).execute();
  assertEquals("encrypted response from the origin server", response.body().string());

  RecordedRequest connect = server.takeRequest();
  assertNull(connect.getHeader("Private"));
  assertEquals(Version.userAgent(), connect.getHeader("User-Agent"));
  assertEquals("Keep-Alive", connect.getHeader("Proxy-Connection"));
  assertEquals("android.com:443", connect.getHeader("Host"));

  RecordedRequest get = server.takeRequest();
  assertEquals("Secret", get.getHeader("Private"));
  assertEquals("App 1.0", get.getHeader("User-Agent"));

  assertEquals(Arrays.asList("verify android.com"), hostnameVerifier.calls);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:37,代码来源:CallTest.java

示例4: proxyConnectIncludesProxyHeadersOnly

import okhttp3.internal.Version; //导入依赖的package包/类
/** Test which headers are sent unencrypted to the HTTP proxy. */
@Test public void proxyConnectIncludesProxyHeadersOnly()
    throws IOException, InterruptedException {
  RecordingHostnameVerifier hostnameVerifier = new RecordingHostnameVerifier();

  server.useHttps(sslClient.socketFactory, true);
  server.enqueue(
      new MockResponse().setSocketPolicy(UPGRADE_TO_SSL_AT_END).clearHeaders());
  server.enqueue(new MockResponse().setBody("encrypted response from the origin server"));

  urlFactory.setClient(urlFactory.client().newBuilder()
      .proxy(server.toProxyAddress())
      .sslSocketFactory(sslClient.socketFactory, sslClient.trustManager)
      .hostnameVerifier(hostnameVerifier)
      .build());

  URL url = new URL("https://android.com/foo");
  connection = urlFactory.open(url);
  connection.addRequestProperty("Private", "Secret");
  connection.addRequestProperty("Proxy-Authorization", "bar");
  connection.addRequestProperty("User-Agent", "baz");
  assertContent("encrypted response from the origin server", connection);

  RecordedRequest connect = server.takeRequest();
  assertNull(connect.getHeader("Private"));
  assertNull(connect.getHeader("Proxy-Authorization"));
  assertEquals(Version.userAgent(), connect.getHeader("User-Agent"));
  assertEquals("android.com:443", connect.getHeader("Host"));
  assertEquals("Keep-Alive", connect.getHeader("Proxy-Connection"));

  RecordedRequest get = server.takeRequest();
  assertEquals("Secret", get.getHeader("Private"));
  assertEquals(Arrays.asList("verify android.com"), hostnameVerifier.calls);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:35,代码来源:URLConnectionTest.java

示例5: userAgentDefaultsToOkHttpVersion

import okhttp3.internal.Version; //导入依赖的package包/类
@Test public void userAgentDefaultsToOkHttpVersion() throws Exception {
  server.enqueue(new MockResponse().setBody("abc"));

  assertContent("abc", urlFactory.open(server.url("/").url()));

  RecordedRequest request = server.takeRequest();
  assertEquals(Version.userAgent(), request.getHeader("User-Agent"));
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:9,代码来源:URLConnectionTest.java

示例6: networkRequest

import okhttp3.internal.Version; //导入依赖的package包/类
/**
 * Populates request with defaults and cookies.
 *
 * <p>This client doesn't specify a default {@code Accept} header because it doesn't know what
 * content types the application is interested in.
 */
private Request networkRequest(Request request) throws IOException {
  Request.Builder result = request.newBuilder();

  if (request.header("Host") == null) {
    result.header("Host", hostHeader(request.url()));
  }

  if (request.header("Connection") == null) {
    result.header("Connection", "Keep-Alive");
  }

  if (request.header("Accept-Encoding") == null) {
    transparentGzip = true;
    result.header("Accept-Encoding", "gzip");
  }

  List<Cookie> cookies = client.cookieJar().loadForRequest(request.url());
  if (!cookies.isEmpty()) {
    result.header("Cookie", cookieHeader(cookies));
  }

  if (request.header("User-Agent") == null) {
    result.header("User-Agent", Version.userAgent());
  }

  return result.build();
}
 
开发者ID:lizhangqu,项目名称:PriorityOkHttp,代码行数:34,代码来源:HttpEngine.java

示例7: createTunnelRequest

import okhttp3.internal.Version; //导入依赖的package包/类
/**
 * Returns a request that creates a TLS tunnel via an HTTP proxy, or null if no tunnel is
 * necessary. Everything in the tunnel request is sent unencrypted to the proxy server, so tunnels
 * include only the minimum set of headers. This avoids sending potentially sensitive data like
 * HTTP cookies to the proxy unencrypted.
 */
private Request createTunnelRequest() throws IOException {
  return new Request.Builder()
      .url(route.address().url())
      .header("Host", Util.hostHeader(route.address().url()))
      .header("Proxy-Connection", "Keep-Alive")
      .header("User-Agent", Version.userAgent()) // For HTTP/1.0 proxies like Squid.
      .build();
}
 
开发者ID:lizhangqu,项目名称:PriorityOkHttp,代码行数:15,代码来源:RealConnection.java

示例8: userAgentIsIncludedByDefault

import okhttp3.internal.Version; //导入依赖的package包/类
@Test public void userAgentIsIncludedByDefault() throws Exception {
  server.enqueue(new MockResponse());

  executeSynchronously(new Request.Builder().url(server.url("/")).build());

  RecordedRequest recordedRequest = server.takeRequest();
  assertTrue(recordedRequest.getHeader("User-Agent")
      .matches(Version.userAgent()));
}
 
开发者ID:lizhangqu,项目名称:PriorityOkHttp,代码行数:10,代码来源:CallTest.java

示例9: proxyConnectOmitsApplicationHeaders

import okhttp3.internal.Version; //导入依赖的package包/类
/** Test which headers are sent unencrypted to the HTTP proxy. */
@Test public void proxyConnectOmitsApplicationHeaders() throws Exception {
  server.useHttps(sslContext.getSocketFactory(), true);
  server.enqueue(new MockResponse()
      .setSocketPolicy(SocketPolicy.UPGRADE_TO_SSL_AT_END)
      .clearHeaders());
  server.enqueue(new MockResponse()
      .setBody("encrypted response from the origin server"));

  RecordingHostnameVerifier hostnameVerifier = new RecordingHostnameVerifier();
  client = client.newBuilder()
      .sslSocketFactory(sslContext.getSocketFactory())
      .proxy(server.toProxyAddress())
      .hostnameVerifier(hostnameVerifier)
      .build();

  Request request = new Request.Builder()
      .url("https://android.com/foo")
      .header("Private", "Secret")
      .header("User-Agent", "App 1.0")
      .build();
  Response response = client.newCall(request).execute();
  assertEquals("encrypted response from the origin server", response.body().string());

  RecordedRequest connect = server.takeRequest();
  assertNull(connect.getHeader("Private"));
  assertEquals(Version.userAgent(), connect.getHeader("User-Agent"));
  assertEquals("Keep-Alive", connect.getHeader("Proxy-Connection"));
  assertEquals("android.com", connect.getHeader("Host"));

  RecordedRequest get = server.takeRequest();
  assertEquals("Secret", get.getHeader("Private"));
  assertEquals("App 1.0", get.getHeader("User-Agent"));

  assertEquals(Arrays.asList("verify android.com"), hostnameVerifier.calls);
}
 
开发者ID:lizhangqu,项目名称:PriorityOkHttp,代码行数:37,代码来源:CallTest.java

示例10: proxyConnectIncludesProxyHeadersOnly

import okhttp3.internal.Version; //导入依赖的package包/类
/** Test which headers are sent unencrypted to the HTTP proxy. */
@Test public void proxyConnectIncludesProxyHeadersOnly()
    throws IOException, InterruptedException {
  RecordingHostnameVerifier hostnameVerifier = new RecordingHostnameVerifier();

  server.useHttps(sslContext.getSocketFactory(), true);
  server.enqueue(
      new MockResponse().setSocketPolicy(UPGRADE_TO_SSL_AT_END).clearHeaders());
  server.enqueue(new MockResponse().setBody("encrypted response from the origin server"));

  urlFactory.setClient(urlFactory.client().newBuilder()
      .proxy(server.toProxyAddress())
      .sslSocketFactory(sslContext.getSocketFactory())
      .hostnameVerifier(hostnameVerifier)
      .build());

  URL url = new URL("https://android.com/foo");
  connection = urlFactory.open(url);
  connection.addRequestProperty("Private", "Secret");
  connection.addRequestProperty("Proxy-Authorization", "bar");
  connection.addRequestProperty("User-Agent", "baz");
  assertContent("encrypted response from the origin server", connection);

  RecordedRequest connect = server.takeRequest();
  assertNull(connect.getHeader("Private"));
  assertNull(connect.getHeader("Proxy-Authorization"));
  assertEquals(Version.userAgent(), connect.getHeader("User-Agent"));
  assertEquals("android.com", connect.getHeader("Host"));
  assertEquals("Keep-Alive", connect.getHeader("Proxy-Connection"));

  RecordedRequest get = server.takeRequest();
  assertEquals("Secret", get.getHeader("Private"));
  assertEquals(Arrays.asList("verify android.com"), hostnameVerifier.calls);
}
 
开发者ID:lizhangqu,项目名称:PriorityOkHttp,代码行数:35,代码来源:URLConnectionTest.java

示例11: createTunnelRequest

import okhttp3.internal.Version; //导入依赖的package包/类
/**
 * Returns a request that creates a TLS tunnel via an HTTP proxy. Everything in the tunnel request
 * is sent unencrypted to the proxy server, so tunnels include only the minimum set of headers.
 * This avoids sending potentially sensitive data like HTTP cookies to the proxy unencrypted.
 */
private Request createTunnelRequest() {
  return new Request.Builder()
      .url(route.address().url())
      .header("Host", Util.hostHeader(route.address().url(), true))
      .header("Proxy-Connection", "Keep-Alive")
      .header("User-Agent", Version.userAgent()) // For HTTP/1.0 proxies like Squid.
      .build();
}
 
开发者ID:RunningTheSnail,项目名称:Okhttp,代码行数:14,代码来源:RealConnection.java

示例12: intercept

import okhttp3.internal.Version; //导入依赖的package包/类
@Override public Response intercept(Chain chain) throws IOException {
  Request userRequest = chain.request();
  Request.Builder requestBuilder = userRequest.newBuilder();

  RequestBody body = userRequest.body();
  if (body != null) {
    MediaType contentType = body.contentType();
    if (contentType != null) {
      requestBuilder.header("Content-Type", contentType.toString());
    }

    long contentLength = body.contentLength();
    if (contentLength != -1) {
      requestBuilder.header("Content-Length", Long.toString(contentLength));
      requestBuilder.removeHeader("Transfer-Encoding");
    } else {
      requestBuilder.header("Transfer-Encoding", "chunked");
      requestBuilder.removeHeader("Content-Length");
    }
  }

  if (userRequest.header("Host") == null) {
    requestBuilder.header("Host", hostHeader(userRequest.url(), false));
  }

  if (userRequest.header("Connection") == null) {
    requestBuilder.header("Connection", "Keep-Alive");
  }

  // If we add an "Accept-Encoding: gzip" header field we're responsible for also decompressing
  // the transfer stream.
  boolean transparentGzip = false;
  if (userRequest.header("Accept-Encoding") == null && userRequest.header("Range") == null) {
    transparentGzip = true;
    requestBuilder.header("Accept-Encoding", "gzip");
  }

  List<Cookie> cookies = cookieJar.loadForRequest(userRequest.url());
  if (!cookies.isEmpty()) {
    requestBuilder.header("Cookie", cookieHeader(cookies));
  }

  if (userRequest.header("User-Agent") == null) {
    requestBuilder.header("User-Agent", Version.userAgent());
  }

  Response networkResponse = chain.proceed(requestBuilder.build());

  HttpHeaders.receiveHeaders(cookieJar, userRequest.url(), networkResponse.headers());

  Response.Builder responseBuilder = networkResponse.newBuilder()
      .request(userRequest);

  if (transparentGzip
      && "gzip".equalsIgnoreCase(networkResponse.header("Content-Encoding"))
      && HttpHeaders.hasBody(networkResponse)) {
    GzipSource responseBody = new GzipSource(networkResponse.body().source());
    Headers strippedHeaders = networkResponse.headers().newBuilder()
        .removeAll("Content-Encoding")
        .removeAll("Content-Length")
        .build();
    responseBuilder.headers(strippedHeaders);
    responseBuilder.body(new RealResponseBody(strippedHeaders, Okio.buffer(responseBody)));
  }

  return responseBuilder.build();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:68,代码来源:BridgeInterceptor.java

示例13: defaultUserAgent

import okhttp3.internal.Version; //导入依赖的package包/类
private String defaultUserAgent() {
  String agent = System.getProperty("http.agent");
  return agent != null ? Util.toHumanReadableAscii(agent) : Version.userAgent();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:5,代码来源:OkHttpURLConnection.java

示例14: intercept

import okhttp3.internal.Version; //导入依赖的package包/类
@Override
public Response intercept(Chain chain) throws IOException {
    Request userRequest = chain.request();
    Request.Builder requestBuilder = userRequest.newBuilder();

    //post方法
    RequestBody body = userRequest.body();
    if (body != null) {
        MediaType contentType = body.contentType();
        if (contentType != null) {
            //添加content-type请求头
            requestBuilder.header("Content-Type", contentType.toString());
        }

        long contentLength = body.contentLength();
        if (contentLength != -1) {
            requestBuilder.header("Content-Length", Long.toString(contentLength));
            requestBuilder.removeHeader("Transfer-Encoding");
        } else {
            requestBuilder.header("Transfer-Encoding", "chunked");
            requestBuilder.removeHeader("Content-Length");
        }
    }

    if (userRequest.header("Host") == null) {
        requestBuilder.header("Host", hostHeader(userRequest.url(), false));
    }

    //长连接
    if (userRequest.header("Connection") == null) {
        requestBuilder.header("Connection", "Keep-Alive");
    }

    // If we add an "Accept-Encoding: gzip" header field we're responsible for also decompressing
    // the transfer stream.
    boolean transparentGzip = false;
    //支持gzip压缩
    if (userRequest.header("Accept-Encoding") == null) {
        transparentGzip = true;
        requestBuilder.header("Accept-Encoding", "gzip");
    }

    //加载相同域名的cookie
    List<Cookie> cookies = cookieJar.loadForRequest(userRequest.url());
    if (!cookies.isEmpty()) {
        //添加cookie请求头
        requestBuilder.header("Cookie", cookieHeader(cookies));
    }

    if (userRequest.header("User-Agent") == null) {
        //添加us请求头
        requestBuilder.header("User-Agent", Version.userAgent());
    }

    Response networkResponse = chain.proceed(requestBuilder.build());

    HttpHeaders.receiveHeaders(cookieJar, userRequest.url(), networkResponse.headers());

    Response.Builder responseBuilder = networkResponse.newBuilder()
            .request(userRequest);

    if (transparentGzip
            && "gzip".equalsIgnoreCase(networkResponse.header("Content-Encoding"))
            && HttpHeaders.hasBody(networkResponse)) {
        GzipSource responseBody = new GzipSource(networkResponse.body().source());
        Headers strippedHeaders = networkResponse.headers().newBuilder()
                .removeAll("Content-Encoding")
                .removeAll("Content-Length")
                .build();
        responseBuilder.headers(strippedHeaders);
        responseBuilder.body(new RealResponseBody(strippedHeaders, Okio.buffer(responseBody)));
    }

    return responseBuilder.build();
}
 
开发者ID:RunningTheSnail,项目名称:Okhttp,代码行数:76,代码来源:BridgeInterceptor.java

示例15: appendTo

import okhttp3.internal.Version; //导入依赖的package包/类
@Override
public void appendTo(StringBuilder sb)
{
    sb.append(Version.userAgent());
}
 
开发者ID:dmfs,项目名称:http-client-essentials-suite,代码行数:6,代码来源:OkHttpProduct.java


注:本文中的okhttp3.internal.Version类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。