Ejemplo n.º 1
0
    void headers(boolean outFinished, int streamId, List<Header> headerBlock) throws IOException {
      if (closed) throw new IOException("closed");
      if (hpackBuffer.size() != 0) throw new IllegalStateException();
      hpackWriter.writeHeaders(headerBlock);

      long byteCount = hpackBuffer.size();
      int length = (int) Math.min(maxFrameSize, byteCount);
      byte type = TYPE_HEADERS;
      byte flags = byteCount == length ? FLAG_END_HEADERS : 0;
      if (outFinished) flags |= FLAG_END_STREAM;
      frameHeader(streamId, length, type, flags);
      sink.write(hpackBuffer, length);

      if (byteCount > length) writeContinuationFrames(streamId, byteCount - length);
    }
Ejemplo n.º 2
0
 private void headers(
     boolean outFinished, int streamId, int priority, List<String> nameValueBlock)
     throws IOException {
   hpackBuffer.reset();
   hpackWriter.writeHeaders(nameValueBlock);
   int type = TYPE_HEADERS;
   // TODO: implement CONTINUATION
   int length = hpackBuffer.size();
   int flags = FLAG_END_HEADERS;
   if (outFinished) flags |= FLAG_END_STREAM;
   if (priority != -1) flags |= FLAG_PRIORITY;
   out.writeInt((length & 0xffff) << 16 | (type & 0xff) << 8 | (flags & 0xff));
   out.writeInt(streamId & 0x7fffffff);
   if (priority != -1) out.writeInt(priority & 0x7fffffff);
   hpackBuffer.writeTo(out);
 }
Ejemplo n.º 3
0
    @Override
    public synchronized void pushPromise(
        int streamId, int promisedStreamId, List<Header> requestHeaders) throws IOException {
      if (closed) throw new IOException("closed");
      if (hpackBuffer.size() != 0) throw new IllegalStateException();
      hpackWriter.writeHeaders(requestHeaders);

      long byteCount = hpackBuffer.size();
      int length = (int) Math.min(maxFrameSize - 4, byteCount);
      byte type = TYPE_PUSH_PROMISE;
      byte flags = byteCount == length ? FLAG_END_HEADERS : 0;
      frameHeader(streamId, length + 4, type, flags);
      sink.writeInt(promisedStreamId & 0x7fffffff);
      sink.write(hpackBuffer, length);

      if (byteCount > length) writeContinuationFrames(streamId, byteCount - length);
    }