本文整理汇总了Java中com.squareup.okhttp.Protocol.HTTP_1_0属性的典型用法代码示例。如果您正苦于以下问题:Java Protocol.HTTP_1_0属性的具体用法?Java Protocol.HTTP_1_0怎么用?Java Protocol.HTTP_1_0使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类com.squareup.okhttp.Protocol
的用法示例。
在下文中一共展示了Protocol.HTTP_1_0属性的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parse
public static StatusLine parse(String statusLine) throws IOException {
int codeStart;
Protocol protocol;
if (statusLine.startsWith("HTTP/1.")) {
if (statusLine.length() < 9 || statusLine.charAt(8) != ' ') {
throw new ProtocolException("Unexpected status line: " + statusLine);
}
int httpMinorVersion = statusLine.charAt(7) - 48;
codeStart = 9;
if (httpMinorVersion == 0) {
protocol = Protocol.HTTP_1_0;
} else if (httpMinorVersion == 1) {
protocol = Protocol.HTTP_1_1;
} else {
throw new ProtocolException("Unexpected status line: " + statusLine);
}
} else if (statusLine.startsWith("ICY ")) {
protocol = Protocol.HTTP_1_0;
codeStart = 4;
} else {
throw new ProtocolException("Unexpected status line: " + statusLine);
}
if (statusLine.length() < codeStart + 3) {
throw new ProtocolException("Unexpected status line: " + statusLine);
}
try {
int code = Integer.parseInt(statusLine.substring(codeStart, codeStart + 3));
String message = "";
if (statusLine.length() > codeStart + 3) {
if (statusLine.charAt(codeStart + 3) != ' ') {
throw new ProtocolException("Unexpected status line: " + statusLine);
}
message = statusLine.substring(codeStart + 4);
}
return new StatusLine(protocol, code, message);
} catch (NumberFormatException e) {
throw new ProtocolException("Unexpected status line: " + statusLine);
}
}
示例2: concatLengthPrefixed
static byte[] concatLengthPrefixed(List<Protocol> protocols) {
Buffer result = new Buffer();
int size = protocols.size();
for (int i = 0; i < size; i++) {
Protocol protocol = (Protocol) protocols.get(i);
if (protocol != Protocol.HTTP_1_0) {
result.writeByte(protocol.toString().length());
result.writeUtf8(protocol.toString());
}
}
return result.readByteArray();
}
示例3: toString
public final String toString()
{
StringBuilder localStringBuilder = new StringBuilder();
if (this.protocol == Protocol.HTTP_1_0) {}
for (String str = "HTTP/1.0";; str = "HTTP/1.1")
{
localStringBuilder.append(str);
localStringBuilder.append(' ').append(this.code);
if (this.message != null) {
localStringBuilder.append(' ').append(this.message);
}
return localStringBuilder.toString();
}
}
示例4: version
public static String version(Protocol paramProtocol)
{
if (paramProtocol == Protocol.HTTP_1_0) {
return "HTTP/1.0";
}
return "HTTP/1.1";
}
示例5: configureTlsExtensions
public final void configureTlsExtensions(SSLSocket paramSSLSocket, String paramString, List<Protocol> paramList)
{
if (paramString != null)
{
OptionalMethod localOptionalMethod = SET_USE_SESSION_TICKETS;
Object[] arrayOfObject2 = new Object[1];
arrayOfObject2[0] = Boolean.valueOf(true);
localOptionalMethod.invokeOptionalWithoutCheckedException(paramSSLSocket, arrayOfObject2);
SET_HOSTNAME.invokeOptionalWithoutCheckedException(paramSSLSocket, new Object[] { paramString });
}
boolean bool1 = SET_NPN_PROTOCOLS.isSupported(paramSSLSocket);
boolean bool2 = SET_ALPN_PROTOCOLS.isSupported(paramSSLSocket);
if ((!bool1) && (!bool2)) {}
Object[] arrayOfObject1;
do
{
return;
arrayOfObject1 = new Object[1];
Buffer localBuffer = new Buffer();
int i = paramList.size();
for (int j = 0; j < i; j++)
{
Protocol localProtocol = (Protocol)paramList.get(j);
if (localProtocol != Protocol.HTTP_1_0)
{
localBuffer.writeByte(localProtocol.toString().length());
localBuffer.writeUtf8(localProtocol.toString());
}
}
arrayOfObject1[0] = localBuffer.readByteArray();
if (bool1) {
SET_NPN_PROTOCOLS.invokeWithoutCheckedException(paramSSLSocket, arrayOfObject1);
}
} while (!bool2);
SET_ALPN_PROTOCOLS.invokeWithoutCheckedException(paramSSLSocket, arrayOfObject1);
}
示例6: networkRequest
/**
* 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 ((connection == null || connection.getProtocol() != Protocol.HTTP_1_0)
&& request.header("Connection") == null) {
result.header("Connection", "Keep-Alive");
}
if (request.header("Accept-Encoding") == null) {
transparentGzip = true;
result.header("Accept-Encoding", "gzip");
}
CookieHandler cookieHandler = client.getCookieHandler();
if (cookieHandler != null) {
// Capture the request headers added so far so that they can be offered to the CookieHandler.
// This is mostly to stay close to the RI; it is unlikely any of the headers above would
// affect cookie choice besides "Host".
Map<String, List<String>> headers = OkHeaders.toMultimap(result.build().headers(), null);
Map<String, List<String>> cookies = cookieHandler.get(request.uri(), headers);
// Add any new cookies to the request.
OkHeaders.addCookies(result, cookies);
}
return result.build();
}
示例7: concatLengthPrefixed
/**
* 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 NPN.
result.writeByte(protocol.toString().length());
result.writeUtf8(protocol.toString());
}
return result.readByteArray();
}
示例8: parse
public static StatusLine parse(String statusLine) throws IOException {
// H T T P / 1 . 1 2 0 0 T e m p o r a r y R e d i r e c t
// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0
// Parse protocol like "HTTP/1.1" followed by a space.
int codeStart;
Protocol protocol;
if (statusLine.startsWith("HTTP/1.")) {
if (statusLine.length() < 9 || statusLine.charAt(8) != ' ') {
throw new ProtocolException("Unexpected status line: " + statusLine);
}
int httpMinorVersion = statusLine.charAt(7) - '0';
codeStart = 9;
if (httpMinorVersion == 0) {
protocol = Protocol.HTTP_1_0;
} else if (httpMinorVersion == 1) {
protocol = Protocol.HTTP_1_1;
} else {
throw new ProtocolException("Unexpected status line: " + statusLine);
}
} else if (statusLine.startsWith("ICY ")) {
// Shoutcast uses ICY instead of "HTTP/1.0".
protocol = Protocol.HTTP_1_0;
codeStart = 4;
} else {
throw new ProtocolException("Unexpected status line: " + statusLine);
}
// Parse response code like "200". Always 3 digits.
if (statusLine.length() < codeStart + 3) {
throw new ProtocolException("Unexpected status line: " + statusLine);
}
int code;
try {
code = Integer.parseInt(statusLine.substring(codeStart, codeStart + 3));
} catch (NumberFormatException e) {
throw new ProtocolException("Unexpected status line: " + statusLine);
}
// Parse an optional response message like "OK" or "Not Modified". If it
// exists, it is separated from the response code by a space.
String message = "";
if (statusLine.length() > codeStart + 3) {
if (statusLine.charAt(codeStart + 3) != ' ') {
throw new ProtocolException("Unexpected status line: " + statusLine);
}
message = statusLine.substring(codeStart + 4);
}
return new StatusLine(protocol, code, message);
}
示例9: version
public static String version(Protocol protocol) {
return protocol == Protocol.HTTP_1_0 ? "HTTP/1.0" : "HTTP/1.1";
}