本文整理汇总了Java中com.squareup.okhttp.Protocol.SPDY_3属性的典型用法代码示例。如果您正苦于以下问题:Java Protocol.SPDY_3属性的具体用法?Java Protocol.SPDY_3怎么用?Java Protocol.SPDY_3使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类com.squareup.okhttp.Protocol
的用法示例。
在下文中一共展示了Protocol.SPDY_3属性的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: connectSocket
private void connectSocket(int connectTimeout, int readTimeout, int writeTimeout,
ConnectionSpecSelector connectionSpecSelector) throws IOException {
this.rawSocket.setSoTimeout(readTimeout);
try {
Platform.get().connectSocket(this.rawSocket, this.route.getSocketAddress(),
connectTimeout);
this.source = Okio.buffer(Okio.source(this.rawSocket));
this.sink = Okio.buffer(Okio.sink(this.rawSocket));
if (this.route.getAddress().getSslSocketFactory() != null) {
connectTls(readTimeout, writeTimeout, connectionSpecSelector);
} else {
this.protocol = Protocol.HTTP_1_1;
this.socket = this.rawSocket;
}
if (this.protocol == Protocol.SPDY_3 || this.protocol == Protocol.HTTP_2) {
this.socket.setSoTimeout(0);
FramedConnection framedConnection = new Builder(true).socket(this.socket, this
.route.getAddress().url().host(), this.source, this.sink).protocol(this
.protocol).build();
framedConnection.sendConnectionPreface();
this.framedConnection = framedConnection;
}
} catch (ConnectException e) {
throw new ConnectException("Failed to connect to " + this.route.getSocketAddress());
}
}
示例2: isProhibitedHeader
private static boolean isProhibitedHeader(Protocol paramProtocol, ByteString paramByteString)
{
if (paramProtocol == Protocol.SPDY_3) {
return SPDY_3_PROHIBITED_HEADERS.contains(paramByteString);
}
if (paramProtocol == Protocol.HTTP_2) {
return HTTP_2_PROHIBITED_HEADERS.contains(paramByteString);
}
throw new AssertionError(paramProtocol);
}
示例3: isProhibitedHeader
/** When true, this header should not be emitted or consumed. */
private static boolean isProhibitedHeader(Protocol protocol, ByteString name) {
if (protocol == Protocol.SPDY_3) {
return SPDY_3_PROHIBITED_HEADERS.contains(name);
} else if (protocol == Protocol.HTTP_2) {
return HTTP_2_PROHIBITED_HEADERS.contains(name);
} else {
throw new AssertionError(protocol);
}
}
示例4: SpdyConnection
private SpdyConnection(Builder builder) {
protocol = builder.protocol;
pushObserver = builder.pushObserver;
client = builder.client;
handler = builder.handler;
nextStreamId = builder.client ? 1 : 2;
nextPingId = builder.client ? 1 : 2;
// Flow control was designed more for servers, or proxies than edge clients.
// If we are a client, set the flow control window to 16MiB. This avoids
// thrashing window updates every 64KiB, yet small enough to avoid blowing
// up the heap.
if (builder.client) {
okHttpSettings.set(Settings.INITIAL_WINDOW_SIZE, 0, 16 * 1024 * 1024);
}
hostName = builder.hostName;
Variant variant;
if (protocol == Protocol.HTTP_2) {
variant = new Http20Draft09();
} else if (protocol == Protocol.SPDY_3) {
variant = new Spdy3();
} else {
throw new AssertionError(protocol);
}
bytesLeftInWriteWindow = peerSettings.getInitialWindowSize(DEFAULT_INITIAL_WINDOW_SIZE);
frameReader = variant.newReader(builder.source, client);
frameWriter = variant.newWriter(builder.sink, client);
maxFrameSize = variant.maxFrameSize();
readerRunnable = new Reader();
new Thread(readerRunnable).start(); // Not a daemon thread.
}
示例5: FramedConnection
private FramedConnection(Builder builder) throws IOException {
int i = 2;
this.streams = new HashMap();
this.idleStartTimeNs = System.nanoTime();
this.unacknowledgedBytesRead = 0;
this.okHttpSettings = new Settings();
this.peerSettings = new Settings();
this.receivedInitialPeerSettings = false;
this.currentPushRequests = new LinkedHashSet();
this.protocol = builder.protocol;
this.pushObserver = builder.pushObserver;
this.client = builder.client;
this.listener = builder.listener;
this.nextStreamId = builder.client ? 1 : 2;
if (builder.client && this.protocol == Protocol.HTTP_2) {
this.nextStreamId += 2;
}
if (builder.client) {
i = 1;
}
this.nextPingId = i;
if (builder.client) {
this.okHttpSettings.set(7, 0, 16777216);
}
this.hostName = builder.hostName;
if (this.protocol == Protocol.HTTP_2) {
this.variant = new Http2();
this.pushExecutor = new ThreadPoolExecutor(0, 1, 60, TimeUnit.SECONDS, new
LinkedBlockingQueue(), Util.threadFactory(String.format("OkHttp %s Push " +
"Observer", new Object[]{this.hostName}), true));
this.peerSettings.set(7, 0, 65535);
this.peerSettings.set(5, 0, 16384);
} else if (this.protocol == Protocol.SPDY_3) {
this.variant = new Spdy3();
this.pushExecutor = null;
} else {
throw new AssertionError(this.protocol);
}
this.bytesLeftInWriteWindow = (long) this.peerSettings.getInitialWindowSize(65536);
this.socket = builder.socket;
this.frameWriter = this.variant.newWriter(builder.sink, this.client);
this.readerRunnable = new Reader(this.variant.newReader(builder.source, this.client));
new Thread(this.readerRunnable).start();
}
示例6: getProtocol
public Protocol getProtocol() {
return Protocol.SPDY_3;
}
示例7: SpdyConnection
private SpdyConnection(Builder paramBuilder)
throws IOException
{
this.protocol = paramBuilder.protocol;
this.pushObserver = paramBuilder.pushObserver;
this.client = paramBuilder.client;
this.handler = paramBuilder.handler;
int j;
if (paramBuilder.client)
{
j = 1;
this.nextStreamId = j;
if ((paramBuilder.client) && (this.protocol == Protocol.HTTP_2)) {
this.nextStreamId = (2 + this.nextStreamId);
}
if (paramBuilder.client) {
i = 1;
}
this.nextPingId = i;
if (paramBuilder.client) {
this.okHttpSettings.set(7, 0, 16777216);
}
this.hostName = paramBuilder.hostName;
if (this.protocol != Protocol.HTTP_2) {
break label367;
}
this.variant = new Http20Draft16();
TimeUnit localTimeUnit = TimeUnit.SECONDS;
LinkedBlockingQueue localLinkedBlockingQueue = new LinkedBlockingQueue();
Object[] arrayOfObject = new Object[1];
arrayOfObject[0] = this.hostName;
this.pushExecutor = new ThreadPoolExecutor(0, 1, 60L, localTimeUnit, localLinkedBlockingQueue, Util.threadFactory$4b642d48(String.format("OkHttp %s Push Observer", arrayOfObject)));
this.peerSettings.set(7, 0, 65535);
this.peerSettings.set(5, 0, 16384);
}
for (;;)
{
this.bytesLeftInWriteWindow = this.peerSettings.getInitialWindowSize$134621();
this.socket = paramBuilder.socket;
this.frameWriter = this.variant.newWriter(Okio.buffer(Okio.sink(paramBuilder.socket)), this.client);
this.readerRunnable = new Reader((byte)0);
new Thread(this.readerRunnable).start();
return;
j = i;
break;
label367:
if (this.protocol != Protocol.SPDY_3) {
break label396;
}
this.variant = new Spdy3();
this.pushExecutor = null;
}
label396:
throw new AssertionError(this.protocol);
}
示例8: writeNameValueBlock
/**
* Returns a list of alternating names and values containing a SPDY request.
* Names are all lowercase. No names are repeated. If any name has multiple
* values, they are concatenated using "\0" as a delimiter.
*/
public static List<Header> writeNameValueBlock(Request request, Protocol protocol,
String version) {
Headers headers = request.headers();
List<Header> result = new ArrayList<>(headers.size() + 10);
result.add(new Header(TARGET_METHOD, request.method()));
result.add(new Header(TARGET_PATH, RequestLine.requestPath(request.url())));
String host = HttpEngine.hostHeader(request.url());
if (Protocol.SPDY_3 == protocol) {
result.add(new Header(VERSION, version));
result.add(new Header(TARGET_HOST, host));
} else if (Protocol.HTTP_2 == protocol) {
result.add(new Header(TARGET_AUTHORITY, host)); // Optional in HTTP/2
} else {
throw new AssertionError();
}
result.add(new Header(TARGET_SCHEME, request.url().getProtocol()));
Set<ByteString> names = new LinkedHashSet<ByteString>();
for (int i = 0; i < headers.size(); i++) {
// header names must be lowercase.
ByteString name = ByteString.encodeUtf8(headers.name(i).toLowerCase(Locale.US));
String value = headers.value(i);
// Drop headers that are forbidden when layering HTTP over SPDY.
if (isProhibitedHeader(protocol, name)) continue;
// They shouldn't be set, but if they are, drop them. We've already written them!
if (name.equals(TARGET_METHOD)
|| name.equals(TARGET_PATH)
|| name.equals(TARGET_SCHEME)
|| name.equals(TARGET_AUTHORITY)
|| name.equals(TARGET_HOST)
|| name.equals(VERSION)) {
continue;
}
// If we haven't seen this name before, add the pair to the end of the list...
if (names.add(name)) {
result.add(new Header(name, value));
continue;
}
// ...otherwise concatenate the existing values and this value.
for (int j = 0; j < result.size(); j++) {
if (result.get(j).name.equals(name)) {
String concatenated = joinOnNull(result.get(j).value.utf8(), value);
result.set(j, new Header(name, concatenated));
break;
}
}
}
return result;
}
示例9: getProtocol
@Override public Protocol getProtocol() {
return Protocol.SPDY_3;
}
示例10: SpdyConnection
private SpdyConnection(Builder builder) throws IOException {
protocol = builder.protocol;
pushObserver = builder.pushObserver;
client = builder.client;
handler = builder.handler;
// http://tools.ietf.org/html/draft-ietf-httpbis-http2-12#section-5.1.1
nextStreamId = builder.client ? 1 : 2;
if (builder.client && protocol == Protocol.HTTP_2) {
nextStreamId += 2; // In HTTP/2, 1 on client is reserved for Upgrade.
}
nextPingId = builder.client ? 1 : 2;
// Flow control was designed more for servers, or proxies than edge clients.
// If we are a client, set the flow control window to 16MiB. This avoids
// thrashing window updates every 64KiB, yet small enough to avoid blowing
// up the heap.
if (builder.client) {
okHttpSettings.set(Settings.INITIAL_WINDOW_SIZE, 0, OKHTTP_CLIENT_WINDOW_SIZE);
}
hostName = builder.hostName;
if (protocol == Protocol.HTTP_2) {
variant = new Http20Draft12();
// Like newSingleThreadExecutor, except lazy creates the thread.
pushExecutor = new ThreadPoolExecutor(0, 1,
0L, TimeUnit.MILLISECONDS,
new LinkedBlockingQueue<Runnable>(),
Util.threadFactory(String.format("OkHttp %s Push Observer", hostName), true));
} else if (protocol == Protocol.SPDY_3) {
variant = new Spdy3();
pushExecutor = null;
} else {
throw new AssertionError(protocol);
}
bytesLeftInWriteWindow = peerSettings.getInitialWindowSize(DEFAULT_INITIAL_WINDOW_SIZE);
socket = builder.socket;
frameWriter = variant.newWriter(Okio.buffer(Okio.sink(builder.socket)), client);
maxFrameSize = variant.maxFrameSize();
readerRunnable = new Reader();
new Thread(readerRunnable).start(); // Not a daemon thread.
}
示例11: writeNameValueBlock
/**
* Returns a list of alternating names and values containing a SPDY request.
* Names are all lowercase. No names are repeated. If any name has multiple
* values, they are concatenated using "\0" as a delimiter.
*/
public static List<Header> writeNameValueBlock(Request request, Protocol protocol,
String version) {
Headers headers = request.headers();
// TODO: make the known header names constants.
List<Header> result = new ArrayList<Header>(headers.size() + 10);
result.add(new Header(TARGET_METHOD, request.method()));
result.add(new Header(TARGET_PATH, RequestLine.requestPath(request.url())));
String host = HttpEngine.hostHeader(request.url());
if (Protocol.SPDY_3 == protocol) {
result.add(new Header(VERSION, version));
result.add(new Header(TARGET_HOST, host));
} else if (Protocol.HTTP_2 == protocol) {
result.add(new Header(TARGET_AUTHORITY, host));
} else {
throw new AssertionError();
}
result.add(new Header(TARGET_SCHEME, request.url().getProtocol()));
Set<ByteString> names = new LinkedHashSet<ByteString>();
for (int i = 0; i < headers.size(); i++) {
// header names must be lowercase.
ByteString name = ByteString.encodeUtf8(headers.name(i).toLowerCase(Locale.US));
String value = headers.value(i);
// Drop headers that are forbidden when layering HTTP over SPDY.
if (isProhibitedHeader(protocol, name)) continue;
// They shouldn't be set, but if they are, drop them. We've already written them!
if (name.equals(TARGET_METHOD)
|| name.equals(TARGET_PATH)
|| name.equals(TARGET_SCHEME)
|| name.equals(TARGET_AUTHORITY)
|| name.equals(TARGET_HOST)
|| name.equals(VERSION)) {
continue;
}
// If we haven't seen this name before, add the pair to the end of the list...
if (names.add(name)) {
result.add(new Header(name, value));
continue;
}
// ...otherwise concatenate the existing values and this value.
for (int j = 0; j < result.size(); j++) {
if (result.get(j).name.equals(name)) {
String concatenated = joinOnNull(result.get(j).value.utf8(), value);
result.set(j, new Header(name, concatenated));
break;
}
}
}
return result;
}
示例12: HttpOverSpdy3Test
public HttpOverSpdy3Test() {
super(Protocol.SPDY_3);
}