当前位置: 首页>>代码示例>>Java>>正文


Java Protocol.HTTP_2属性代码示例

本文整理汇总了Java中com.squareup.okhttp.Protocol.HTTP_2属性的典型用法代码示例。如果您正苦于以下问题:Java Protocol.HTTP_2属性的具体用法?Java Protocol.HTTP_2怎么用?Java Protocol.HTTP_2使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在com.squareup.okhttp.Protocol的用法示例。


在下文中一共展示了Protocol.HTTP_2属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: writeRequestHeaders

public void writeRequestHeaders(Request request) throws IOException {
    if (this.stream == null) {
        List<Header> requestHeaders;
        this.httpEngine.writingRequestHeaders();
        boolean permitsRequestBody = this.httpEngine.permitsRequestBody(request);
        if (this.framedConnection.getProtocol() == Protocol.HTTP_2) {
            requestHeaders = http2HeadersList(request);
        } else {
            requestHeaders = spdy3HeadersList(request);
        }
        this.stream = this.framedConnection.newStream(requestHeaders, permitsRequestBody, true);
        this.stream.readTimeout().timeout((long) this.httpEngine.client.getReadTimeout(),
                TimeUnit.MILLISECONDS);
        this.stream.writeTimeout().timeout((long) this.httpEngine.client.getWriteTimeout(),
                TimeUnit.MILLISECONDS);
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:17,代码来源:Http2xStream.java

示例2: 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());
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:26,代码来源:RealConnection.java

示例3: pushStream

public FramedStream pushStream(int associatedStreamId, List<Header> requestHeaders, boolean
        out) throws IOException {
    if (this.client) {
        throw new IllegalStateException("Client cannot push requests.");
    } else if (this.protocol == Protocol.HTTP_2) {
        return newStream(associatedStreamId, requestHeaders, out, false);
    } else {
        throw new IllegalStateException("protocol != HTTP_2");
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:10,代码来源:FramedConnection.java

示例4: 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);
}
 
开发者ID:ChiangC,项目名称:FMTech,代码行数:10,代码来源:SpdyTransport.java

示例5: 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);
  }
}
 
开发者ID:NannanZ,项目名称:spdymcsclient,代码行数:10,代码来源:SpdyTransport.java

示例6: settings

@Override public void settings(boolean clearPrevious, Settings newSettings) {
  long delta = 0;
  SpdyStream[] streamsToNotify = null;
  synchronized (SpdyConnection.this) {
    int priorWriteWindowSize = peerSettings.getInitialWindowSize(DEFAULT_INITIAL_WINDOW_SIZE);
    if (clearPrevious) peerSettings.clear();
    peerSettings.merge(newSettings);
    if (getProtocol() == Protocol.HTTP_2) {
      ackSettingsLater();
    }
    int peerInitialWindowSize = peerSettings.getInitialWindowSize(DEFAULT_INITIAL_WINDOW_SIZE);
    if (peerInitialWindowSize != -1 && peerInitialWindowSize != priorWriteWindowSize) {
      delta = peerInitialWindowSize - priorWriteWindowSize;
      if (!receivedInitialPeerSettings) {
        addBytesToWriteWindow(delta);
        receivedInitialPeerSettings = true;
      }
      if (!streams.isEmpty()) {
        streamsToNotify = streams.values().toArray(new SpdyStream[streams.size()]);
      }
    }
  }
  if (streamsToNotify != null && delta != 0) {
    for (SpdyStream stream : streams.values()) {
      synchronized (stream) {
        stream.addBytesToWriteWindow(delta);
      }
    }
  }
}
 
开发者ID:NannanZ,项目名称:spdymcsclient,代码行数:30,代码来源:SpdyConnection.java

示例7: 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.
}
 
开发者ID:xin3liang,项目名称:platform_external_okhttp,代码行数:34,代码来源:SpdyConnection.java

示例8: readResponseHeaders

public Response$Builder readResponseHeaders() throws IOException {
    if (this.framedConnection.getProtocol() == Protocol.HTTP_2) {
        return readHttp2HeadersList(this.stream.getResponseHeaders());
    }
    return readSpdy3HeadersList(this.stream.getResponseHeaders());
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:6,代码来源:Http2xStream.java

示例9: settings

public void settings(boolean clearPrevious, Settings newSettings) {
    long delta = 0;
    FramedStream[] streamsToNotify = null;
    synchronized (FramedConnection.this) {
        int priorWriteWindowSize = FramedConnection.this.peerSettings
                .getInitialWindowSize(65536);
        if (clearPrevious) {
            FramedConnection.this.peerSettings.clear();
        }
        FramedConnection.this.peerSettings.merge(newSettings);
        if (FramedConnection.this.getProtocol() == Protocol.HTTP_2) {
            ackSettingsLater(newSettings);
        }
        int peerInitialWindowSize = FramedConnection.this.peerSettings
                .getInitialWindowSize(65536);
        if (!(peerInitialWindowSize == -1 || peerInitialWindowSize ==
                priorWriteWindowSize)) {
            delta = (long) (peerInitialWindowSize - priorWriteWindowSize);
            if (!FramedConnection.this.receivedInitialPeerSettings) {
                FramedConnection.this.addBytesToWriteWindow(delta);
                FramedConnection.this.receivedInitialPeerSettings = true;
            }
            if (!FramedConnection.this.streams.isEmpty()) {
                streamsToNotify = (FramedStream[]) FramedConnection.this.streams.values()
                        .toArray(new FramedStream[FramedConnection.this.streams.size()]);
            }
        }
        FramedConnection.executor.execute(new NamedRunnable("OkHttp %s settings",
                FramedConnection.this.hostName) {
            public void execute() {
                FramedConnection.this.listener.onSettings(FramedConnection.this);
            }
        });
    }
    if (streamsToNotify != null && delta != 0) {
        for (FramedStream stream : streamsToNotify) {
            synchronized (stream) {
                stream.addBytesToWriteWindow(delta);
            }
        }
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:42,代码来源:FramedConnection.java

示例10: 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();
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:44,代码来源:FramedConnection.java

示例11: pushedStream

private boolean pushedStream(int streamId) {
    return this.protocol == Protocol.HTTP_2 && streamId != 0 && (streamId & 1) == 0;
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:3,代码来源:FramedConnection.java

示例12: getProtocol

public Protocol getProtocol() {
    return Protocol.HTTP_2;
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:3,代码来源:Http2.java

示例13: 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);
}
 
开发者ID:ChiangC,项目名称:FMTech,代码行数:55,代码来源:SpdyConnection.java

示例14: 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;
}
 
开发者ID:NannanZ,项目名称:spdymcsclient,代码行数:58,代码来源:SpdyTransport.java

示例15: 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.
}
 
开发者ID:NannanZ,项目名称:spdymcsclient,代码行数:44,代码来源:SpdyConnection.java


注:本文中的com.squareup.okhttp.Protocol.HTTP_2属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。