• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java Version类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: addUserAgentHeader

import okhttp3.internal.Version; //导入依赖的package包/类
private void addUserAgentHeader(OkHttpRestfulRequest theHttpRequest, FhirContext theContext) {
    theHttpRequest.addHeader("User-Agent", HttpClientUtil.createUserAgentString(theContext, Version.userAgent()));
}
 
开发者ID:jamesagnew,项目名称:hapi-fhir,代码行数:4,代码来源:OkHttpRestfulClient.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java MockHttpRequest类代码示例发布时间:2022-05-22
下一篇:
Java LinearObjectiveFunction类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap