okhttp3.Protocol.toString()方法的使用及代码示例

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

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

Protocol.toString介绍

[英]Returns the string used to identify this protocol for ALPN, like "http/1.1", "spdy/3.1" or "h2".
[中]返回用于为ALPN标识此协议的字符串,如“http/1.1”、“spdy/3.1”或“h2”。

代码示例

代码示例来源: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

/**
 * 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.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

/**
 * 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

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: square/okhttp

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

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

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

代码示例来源: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

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.github.ljun20160606/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: zalando/logbook

@Override
public String getProtocolVersion() {
  // see https://tools.ietf.org/html/rfc7230#section-2.6
  return response.protocol().toString().toUpperCase(Locale.ROOT);
}

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

/**
  * 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/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: duzechao/OKHttpUtils

/**
  * 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: apache/servicemix-bundles

/**
 * 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.simonpercic/oklog3-java

@Override protected String protocol(Chain chain) {
  Connection connection = chain.connection();
  Protocol protocol = connection != null ? connection.protocol() : Protocol.HTTP_1_1;
  return protocol.toString();
}

代码示例来源:origin: allegro/hermes

HermesResponse fromOkHttpResponse(Response response) throws IOException {
    return hermesResponse()
        .withHeaderSupplier(response::header)
        .withHttpStatus(response.code())
        .withBody(response.body().string())
        .withProtocol(response.protocol().toString())
        .build();
  }
}

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

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.squareup.okhttp3/okhttp-urlconnection

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/okhttp-urlconnection

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;
}

相关文章

微信公众号

最新文章

更多