okhttp3.Request.isHttps()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(8.9k)|赞(0)|评价(0)|浏览(371)

本文整理了Java中okhttp3.Request.isHttps方法的一些代码示例,展示了Request.isHttps的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Request.isHttps方法的具体详情如下:
包路径:okhttp3.Request
类名称:Request
方法名:isHttps

Request.isHttps介绍

暂无

代码示例

代码示例来源:origin: square/okhttp

  1. /**
  2. * Returns true if the request line should contain the full URL with host and port (like "GET
  3. * http://android.com/foo HTTP/1.1") or only the path (like "GET /foo HTTP/1.1").
  4. */
  5. private static boolean includeAuthorityInRequestLine(Request request, Proxy.Type proxyType) {
  6. return !request.isHttps() && proxyType == Proxy.Type.HTTP;
  7. }

代码示例来源:origin: com.squareup.okhttp3/okhttp

  1. /**
  2. * Returns true if the request line should contain the full URL with host and port (like "GET
  3. * http://android.com/foo HTTP/1.1") or only the path (like "GET /foo HTTP/1.1").
  4. */
  5. private static boolean includeAuthorityInRequestLine(Request request, Proxy.Type proxyType) {
  6. return !request.isHttps() && proxyType == Proxy.Type.HTTP;
  7. }

代码示例来源:origin: square/okhttp

  1. final Headers headers = withSyntheticHeaders(response);
  2. final ResponseBody body = response.body();
  3. if (response.request().isHttps()) {
  4. final Handshake handshake = response.handshake();
  5. return new SecureCacheResponse() {

代码示例来源:origin: square/okhttp

  1. /**
  2. * Creates an {@link java.net.HttpURLConnection} of the correct subclass from the supplied OkHttp
  3. * {@link Response}.
  4. */
  5. static HttpURLConnection createJavaUrlConnectionForCachePut(Response okResponse) {
  6. okResponse = okResponse.newBuilder()
  7. .body(null)
  8. .headers(withSyntheticHeaders(okResponse))
  9. .build();
  10. Request request = okResponse.request();
  11. // Create an object of the correct class in case the ResponseCache uses instanceof.
  12. if (request.isHttps()) {
  13. return new CacheHttpsURLConnection(new CacheHttpURLConnection(okResponse));
  14. } else {
  15. return new CacheHttpURLConnection(okResponse);
  16. }
  17. }

代码示例来源:origin: apache/nifi

  1. /**
  2. * Returns a Map of flowfile attributes from the response http headers. Multivalue headers are naively converted to comma separated strings.
  3. */
  4. private Map<String, String> convertAttributesFromHeaders(URL url, Response responseHttp){
  5. // create a new hashmap to store the values from the connection
  6. Map<String, String> map = new HashMap<>();
  7. responseHttp.headers().names().forEach( (key) -> {
  8. if (key == null) {
  9. return;
  10. }
  11. List<String> values = responseHttp.headers().values(key);
  12. // we ignore any headers with no actual values (rare)
  13. if (values == null || values.isEmpty()) {
  14. return;
  15. }
  16. // create a comma separated string from the values, this is stored in the map
  17. String value = csv(values);
  18. // put the csv into the map
  19. map.put(key, value);
  20. });
  21. if (responseHttp.request().isHttps()) {
  22. Principal principal = responseHttp.handshake().peerPrincipal();
  23. if (principal != null) {
  24. map.put(REMOTE_DN, principal.getName());
  25. }
  26. }
  27. return map;
  28. }

代码示例来源:origin: square/okhttp

  1. if (request.isHttps() && cacheResponse.handshake() == null) {
  2. return new CacheStrategy(request, null);

代码示例来源:origin: com.squareup.okhttp3/okhttp

  1. if (request.isHttps() && cacheResponse.handshake() == null) {
  2. return new CacheStrategy(request, null);

代码示例来源:origin: huxq17/SwipeCardsView

  1. /**
  2. * Returns true if the request line should contain the full URL with host
  3. * and port (like "GET http://android.com/foo HTTP/1.1") or only the path
  4. * (like "GET /foo HTTP/1.1").
  5. */
  6. private static boolean includeAuthorityInRequestLine(Request request, Proxy.Type proxyType) {
  7. return !request.isHttps() && proxyType == Proxy.Type.HTTP;
  8. }

代码示例来源:origin: com.github.ljun20160606/okhttp

  1. /**
  2. * Returns true if the request line should contain the full URL with host and port (like "GET
  3. * http://android.com/foo HTTP/1.1") or only the path (like "GET /foo HTTP/1.1").
  4. */
  5. private static boolean includeAuthorityInRequestLine(Request request, Proxy.Type proxyType) {
  6. return !request.isHttps() && proxyType == Proxy.Type.HTTP;
  7. }

代码示例来源:origin: huxq17/tractor

  1. /**
  2. * Returns true if the request line should contain the full URL with host
  3. * and port (like "GET http://android.com/foo HTTP/1.1") or only the path
  4. * (like "GET /foo HTTP/1.1").
  5. */
  6. private static boolean includeAuthorityInRequestLine(Request request, Proxy.Type proxyType) {
  7. return !request.isHttps() && proxyType == Proxy.Type.HTTP;
  8. }

代码示例来源:origin: apache/servicemix-bundles

  1. /**
  2. * Returns true if the request line should contain the full URL with host and port (like "GET
  3. * http://android.com/foo HTTP/1.1") or only the path (like "GET /foo HTTP/1.1").
  4. */
  5. private static boolean includeAuthorityInRequestLine(Request request, Proxy.Type proxyType) {
  6. return !request.isHttps() && proxyType == Proxy.Type.HTTP;
  7. }

代码示例来源:origin: duzechao/OKHttpUtils

  1. /**
  2. * Returns true if the request line should contain the full URL with host and port (like "GET
  3. * http://android.com/foo HTTP/1.1") or only the path (like "GET /foo HTTP/1.1").
  4. */
  5. private static boolean includeAuthorityInRequestLine(Request request, Proxy.Type proxyType) {
  6. return !request.isHttps() && proxyType == Proxy.Type.HTTP;
  7. }

代码示例来源:origin: charbgr/SeismicInterceptor

  1. private void setupRequestValues() {
  2. this.httpVerb = request.method();
  3. this.httpsBadgeTintColor = ContextCompat.getColor(
  4. context, request.isHttps() ? R.color.gray_30 : R.color.gray_70
  5. );
  6. }

代码示例来源:origin: net.sf.sprockets/sprockets

  1. private void setHeaders(Request request, URL url, URLConnection con) {
  2. Headers headers = request.headers();
  3. for (String header : headers.names()) {
  4. // TODO_: Support multiple values/header
  5. con.setRequestProperty(header, headers.get(header));
  6. }
  7. // HttpsUrlConnection isn't supported on App Engine, so add a new Header to fix that.
  8. if (request.isHttps()) {
  9. int port = url.getPort();
  10. if (port == -1) {
  11. port = 443;
  12. }
  13. con.setRequestProperty("Host", url.getHost() + ":" + port);
  14. }
  15. }

代码示例来源:origin: pushbit/sprockets

  1. private void setHeaders(Request request, URL url, URLConnection con) {
  2. Headers headers = request.headers();
  3. for (String header : headers.names()) {
  4. // TODO_: Support multiple values/header
  5. con.setRequestProperty(header, headers.get(header));
  6. }
  7. // HttpsUrlConnection isn't supported on App Engine, so add a new Header to fix that.
  8. if (request.isHttps()) {
  9. int port = url.getPort();
  10. if (port == -1) {
  11. port = 443;
  12. }
  13. con.setRequestProperty("Host", url.getHost() + ":" + port);
  14. }
  15. }

代码示例来源:origin: io.takari.aether/aether-connector-okhttp

  1. private Request authenticateProxy(Proxy proxy, okhttp3.Response response)
  2. throws IOException {
  3. Request req = response.request();
  4. if(req.header("Proxy-Authorization") == null && config.getProxy() != null &&
  5. config.getProxy().getAuthentication() != null) {
  6. String value = toHeaderValue(config.getProxy().getAuthentication());
  7. boolean tunneled = req.isHttps() && proxy.type() == Type.HTTP;
  8. if(!tunneled) {
  9. // start including proxy-auth on each request
  10. headers.put("Proxy-Authorization", value);
  11. }
  12. return req.newBuilder().header("Proxy-Authorization", value).build();
  13. }
  14. return null;
  15. }
  16. };

代码示例来源:origin: com.squareup.okhttp3/okhttp-android-support

  1. /**
  2. * Creates an {@link java.net.HttpURLConnection} of the correct subclass from the supplied OkHttp
  3. * {@link Response}.
  4. */
  5. static HttpURLConnection createJavaUrlConnectionForCachePut(Response okResponse) {
  6. okResponse = okResponse.newBuilder()
  7. .body(null)
  8. .headers(withSyntheticHeaders(okResponse))
  9. .build();
  10. Request request = okResponse.request();
  11. // Create an object of the correct class in case the ResponseCache uses instanceof.
  12. if (request.isHttps()) {
  13. return new CacheHttpsURLConnection(new CacheHttpURLConnection(okResponse));
  14. } else {
  15. return new CacheHttpURLConnection(okResponse);
  16. }
  17. }

代码示例来源:origin: duzechao/OKHttpUtils

  1. private static Address createAddress(OkHttpClient client, Request request) {
  2. SSLSocketFactory sslSocketFactory = null;
  3. HostnameVerifier hostnameVerifier = null;
  4. CertificatePinner certificatePinner = null;
  5. if (request.isHttps()) {
  6. sslSocketFactory = client.sslSocketFactory();
  7. hostnameVerifier = client.hostnameVerifier();
  8. certificatePinner = client.certificatePinner();
  9. }
  10. return new Address(request.url().host(), request.url().port(), client.dns(),
  11. client.socketFactory(), sslSocketFactory, hostnameVerifier, certificatePinner,
  12. client.proxyAuthenticator(), client.proxy(), client.protocols(),
  13. client.connectionSpecs(), client.proxySelector());
  14. }
  15. }

代码示例来源:origin: huxq17/tractor

  1. private static Address createAddress(OkHttpClient client, Request request) {
  2. SSLSocketFactory sslSocketFactory = null;
  3. HostnameVerifier hostnameVerifier = null;
  4. CertificatePinner certificatePinner = null;
  5. if (request.isHttps()) {
  6. sslSocketFactory = client.getSslSocketFactory();
  7. hostnameVerifier = client.getHostnameVerifier();
  8. certificatePinner = client.getCertificatePinner();
  9. }
  10. return new Address(request.url().host(), request.url().port(), client.getDns(),
  11. client.getSocketFactory(), sslSocketFactory, hostnameVerifier, certificatePinner,
  12. client.getAuthenticator(), client.getProxy(), client.getProtocols(),
  13. client.getConnectionSpecs(), client.getProxySelector());
  14. }
  15. }

代码示例来源:origin: huxq17/SwipeCardsView

  1. private static Address createAddress(OkHttpClient client, Request request) {
  2. SSLSocketFactory sslSocketFactory = null;
  3. HostnameVerifier hostnameVerifier = null;
  4. CertificatePinner certificatePinner = null;
  5. if (request.isHttps()) {
  6. sslSocketFactory = client.getSslSocketFactory();
  7. hostnameVerifier = client.getHostnameVerifier();
  8. certificatePinner = client.getCertificatePinner();
  9. }
  10. return new Address(request.url().host(), request.url().port(), client.getDns(),
  11. client.getSocketFactory(), sslSocketFactory, hostnameVerifier, certificatePinner,
  12. client.getAuthenticator(), client.getProxy(), client.getProtocols(),
  13. client.getConnectionSpecs(), client.getProxySelector());
  14. }
  15. }

相关文章