okhttp3.Protocol类的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(6.4k)|赞(0)|评价(0)|浏览(127)

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

Protocol介绍

[英]Protocols that OkHttp implements for ALPN selection.

Protocol vs Scheme

Despite its name, java.net.URL#getProtocol() returns the java.net.URI#getScheme() (http, https, etc.) of the URL, not the protocol (http/1.1, spdy/3.1, etc.). OkHttp uses the word protocol to identify how HTTP messages are framed.
[中]OkHttp为ALPN选择实现的协议。
####协议与方案
尽管它的名字叫java。网URL#getProtocol()返回java。网URL的URI#getScheme()(http、https等),而不是协议(http/1.1、spdy/3.1等)。OkHttp使用“协议”一词来标识HTTP消息的框架。

代码示例

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

public static List<String> alpnProtocolNames(List<Protocol> protocols) {
 List<String> names = new ArrayList<>(protocols.size());
 for (int i = 0, size = protocols.size(); i < size; i++) {
  Protocol protocol = protocols.get(i);
  if (protocol == Protocol.HTTP_1_0) continue; // No HTTP/1.0 for ALPN.
  names.add(protocol.toString());
 }
 return names;
}

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

protocol = protocolString != null ? Protocol.get(protocolString) : Protocol.HTTP_1_1;

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

private static String protocols() {
 return Joiner.on(", ").join(Protocol.values());
}

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

/**
 * Returns the concatenation of 8-bit, length prefixed protocol names.
 * http://tools.ietf.org/html/draft-agl-tls-nextprotoneg-04#page-4
 */
static byte[] concatLengthPrefixed(List<Protocol> protocols) {
 Buffer result = new Buffer();
 for (int i = 0, size = protocols.size(); i < size; i++) {
  Protocol protocol = protocols.get(i);
  if (protocol == Protocol.HTTP_1_0) continue; // No HTTP/1.0 for ALPN.
  result.writeByte(protocol.toString().length());
  result.writeUtf8(protocol.toString());
 }
 return result.readByteArray();
}

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

handshake = unverifiedHandshake;
protocol = maybeProtocol != null
  ? Protocol.get(maybeProtocol)
  : Protocol.HTTP_1_1;
success = true;

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

private static String protocols() {
 return Joiner.on(", ").join(Protocol.values());
}

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

public static List<String> alpnProtocolNames(List<Protocol> protocols) {
 List<String> names = new ArrayList<>(protocols.size());
 for (int i = 0, size = protocols.size(); i < size; i++) {
  Protocol protocol = protocols.get(i);
  if (protocol == Protocol.HTTP_1_0) continue; // No HTTP/1.0 for ALPN.
  names.add(protocol.toString());
 }
 return names;
}

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

handshake = unverifiedHandshake;
protocol = maybeProtocol != null
  ? Protocol.get(maybeProtocol)
  : Protocol.HTTP_1_1;
success = true;

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

/**
 * Returns the concatenation of 8-bit, length prefixed protocol names.
 * http://tools.ietf.org/html/draft-agl-tls-nextprotoneg-04#page-4
 */
static byte[] concatLengthPrefixed(List<Protocol> protocols) {
 Buffer result = new Buffer();
 for (int i = 0, size = protocols.size(); i < size; i++) {
  Protocol protocol = protocols.get(i);
  if (protocol == Protocol.HTTP_1_0) continue; // No HTTP/1.0 for ALPN.
  result.writeByte(protocol.toString().length());
  result.writeUtf8(protocol.toString());
 }
 return result.readByteArray();
}

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

protocol = protocolString != null ? Protocol.get(protocolString) : Protocol.HTTP_1_1;

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

private Headers getHeaders() throws IOException {
 if (responseHeaders == null) {
  Response response = getResponse(true);
  Headers headers = response.headers();
  responseHeaders = headers.newBuilder()
    .add(SELECTED_PROTOCOL, response.protocol().toString())
    .add(RESPONSE_SOURCE, responseSourceHeader(response))
    .build();
 }
 return responseHeaders;
}

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

private void run() throws Exception {
 ServerSocket serverSocket = new ServerSocket(8888);
 serverSocket.setReuseAddress(true);
 while (true) {
  Socket socket = null;
  try {
   socket = serverSocket.accept();
   SSLSocket sslSocket = doSsl(socket);
   String protocolString = Platform.get().getSelectedProtocol(sslSocket);
   Protocol protocol = protocolString != null ? Protocol.get(protocolString) : null;
   if (protocol != Protocol.HTTP_2) {
    throw new ProtocolException("Protocol " + protocol + " unsupported");
   }
   Http2Connection connection = new Http2Connection.Builder(false)
     .socket(sslSocket)
     .listener(this)
     .build();
   connection.start();
  } catch (IOException e) {
   logger.log(Level.INFO, "Http2Server connection failure: " + e);
   Util.closeQuietly(socket);
  } catch (Exception e) {
   logger.log(Level.WARNING, "Http2Server unexpected failure", e);
   Util.closeQuietly(socket);
  }
 }
}

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

if (logger.isLoggable(Level.INFO)) {
 logger.info(MockWebServer.this + " received request: " + request
   + " and responded: " + response + " protocol is " + protocol.toString());

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

handshake = unverifiedHandshake;
protocol = maybeProtocol != null
  ? Protocol.get(maybeProtocol)
  : Protocol.HTTP_1_1;
success = true;

代码示例来源:origin: jgilfelt/chuck

transaction.setProtocol(response.protocol().toString());
transaction.setResponseCode(response.code());
transaction.setResponseMessage(response.message());

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

handshake = unverifiedHandshake;
protocol = maybeProtocol != null
  ? Protocol.get(maybeProtocol)
  : Protocol.HTTP_1_1;
success = true;

代码示例来源:origin: foxinmy/weixin4j

@Override
public HttpVersion getProtocol() {
  if (protocol == null) {
    String protocol = this.response.protocol().toString().split("/")[0];
    boolean keepAlive = KEEP_ALIVE.equalsIgnoreCase(this.response
        .header("Connection"));
    if (this.response.protocol() == Protocol.HTTP_1_0) {
      return new HttpVersion(protocol, 1, 0, keepAlive);
    } else if (this.response.protocol() == Protocol.HTTP_1_1) {
      return new HttpVersion(protocol, 1, 1, keepAlive);
    } else if (this.response.protocol() == Protocol.HTTP_2) {
      return new HttpVersion(protocol, 2, 0, keepAlive);
    } else if (this.response.protocol() == Protocol.SPDY_3) {
      return new HttpVersion(protocol, 3, 0, keepAlive);
    } else {
      this.protocol = new HttpVersion(protocol, keepAlive);
    }
  }
  return protocol;
}

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

handshake = unverifiedHandshake;
protocol = maybeProtocol != null
  ? Protocol.get(maybeProtocol)
  : Protocol.HTTP_1_1;
success = true;

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

public static List<String> alpnProtocolNames(List<Protocol> protocols) {
 List<String> names = new ArrayList<>(protocols.size());
 for (int i = 0, size = protocols.size(); i < size; i++) {
  Protocol protocol = protocols.get(i);
  if (protocol == Protocol.HTTP_1_0) continue; // No HTTP/1.0 for ALPN.
  names.add(protocol.toString());
 }
 return names;
}

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

handshake = unverifiedHandshake;
protocol = maybeProtocol != null
  ? Protocol.get(maybeProtocol)
  : Protocol.HTTP_1_1;
success = true;

相关文章

微信公众号

最新文章

更多