public HeadersEncoder(int maxHeaderTableSize) { encoder = new Encoder(maxHeaderTableSize); }
public void encode(HttpMessage message, OutputStream out) throws IOException { String value = getMethod(message); if (value != null) { encoder.encodeHeader(out, Http2Header.METHOD.getName().getBytes(US_ASCII_CHARSET), value.getBytes(US_ASCII_CHARSET), encoder.encodeHeader(out, Http2Header.PATH.getName().getBytes(US_ASCII_CHARSET), value.getBytes(US_ASCII_CHARSET), encoder.encodeHeader(out, Http2Header.STATUS.getName().getBytes(US_ASCII_CHARSET), Integer.toString(((HttpResponse)message).getStatus().code()).getBytes(US_ASCII_CHARSET), encoder.encodeHeader(out, name.getBytes(US_ASCII_CHARSET), message.getHeaders().get(name).getBytes(US_ASCII_CHARSET),
private void indexHeader(int index, HeaderListener headerListener) throws IOException { if (index <= StaticTable.length) { HeaderField headerField = StaticTable.getEntry(index); addHeader(headerListener, headerField.name, headerField.value, false); } else if (index - StaticTable.length <= dynamicTable.length()) { HeaderField headerField = dynamicTable.getEntry(index - StaticTable.length); addHeader(headerListener, headerField.name, headerField.value, false); } else { throw ILLEGAL_INDEX_VALUE; } }
private void readName(int index) throws IOException { if (index <= StaticTable.length) { HeaderField headerField = StaticTable.getEntry(index); name = headerField.name; } else if (index - StaticTable.length <= dynamicTable.length()) { HeaderField headerField = dynamicTable.getEntry(index - StaticTable.length); name = headerField.name; } else { throw ILLEGAL_INDEX_VALUE; } }
private void insertHeader(HeaderListener headerListener, byte[] name, byte[] value, IndexType indexType) { addHeader(headerListener, name, value, indexType == IndexType.NEVER); switch (indexType) { case NONE: case NEVER: break; case INCREMENTAL: dynamicTable.add(new HeaderField(name, value)); break; default: throw new IllegalStateException("should not reach here"); } }
/** * Creates a new decoder. */ public Decoder(int maxHeaderSize, int maxHeaderTableSize) { dynamicTable = new DynamicTable(maxHeaderTableSize); this.maxHeaderSize = maxHeaderSize; maxDynamicTableSize = maxHeaderTableSize; encoderMaxDynamicTableSize = maxHeaderTableSize; maxDynamicTableSizeChangeRequired = false; reset(); }
/** * Return the size of the dynamic table. * Exposed for testing. */ int size() { return dynamicTable.size(); }
/** * End the current header block. Returns if the header field has been truncated. * This must be called after the header block has been completely decoded. */ public boolean endHeaderBlock() { boolean truncated = headerSize > maxHeaderSize; reset(); return truncated; }
/** * Return the maximum table size. * This is the maximum size allowed by both the encoder and the decoder. */ public int getMaxHeaderTableSize() { return dynamicTable.capacity(); }
/** * Creates a new dynamic table with the specified initial capacity. */ DynamicTable(int initialCapacity) { setCapacity(initialCapacity); }
/** * Set the maximum header table size allowed by the decoder. * This is the value of SETTINGS_HEADER_TABLE_SIZE sent to the peer. * * @param maxHeaderTableSize the maximum header table size allowed by the decoder */ public void setMaxHeaderTableSize(int maxHeaderTableSize) { decoder.setMaxHeaderTableSize(maxHeaderTableSize); }
/** * Compresses the input string literal using the Huffman coding. * @param out the output stream for the compressed data * @param data the string literal to be Huffman encoded * @throws IOException if an I/O error occurs. * @see com.twitter.hpack.HuffmanEncoder#encode(OutputStream, byte[], int, int) */ public void encode(OutputStream out, byte[] data) throws IOException { encode(out, data, 0, data.length); }
private void indexHeader(int index, HeaderListener headerListener) throws IOException { if (index <= StaticTable.length) { HeaderField headerField = StaticTable.getEntry(index); addHeader(headerListener, headerField.name, headerField.value, false); } else if (index - StaticTable.length <= dynamicTable.length()) { HeaderField headerField = dynamicTable.getEntry(index - StaticTable.length); addHeader(headerListener, headerField.name, headerField.value, false); } else { throw ILLEGAL_INDEX_VALUE; } }
private void readName(int index) throws IOException { if (index <= StaticTable.length) { HeaderField headerField = StaticTable.getEntry(index); name = headerField.name; } else if (index - StaticTable.length <= dynamicTable.length()) { HeaderField headerField = dynamicTable.getEntry(index - StaticTable.length); name = headerField.name; } else { throw ILLEGAL_INDEX_VALUE; } }
/** * Creates a new decoder. */ public Decoder(int maxHeaderSize, int maxHeaderTableSize) { dynamicTable = new DynamicTable(maxHeaderTableSize); this.maxHeaderSize = maxHeaderSize; maxDynamicTableSize = maxHeaderTableSize; encoderMaxDynamicTableSize = maxHeaderTableSize; maxDynamicTableSizeChangeRequired = false; reset(); }