/** * Add the header field to the dynamic table. * Entries are evicted from the dynamic table until the size of the table * and the new header field is less than the table's capacity. * If the size of the new entry is larger than the table's capacity, * the dynamic table will be cleared. */ private void add(byte[] name, byte[] value) { int headerSize = HeaderField.sizeOf(name, value); // Clear the table if the header field size is larger than the capacity. if (headerSize > capacity) { clear(); return; } // Evict oldest entries until we have enough capacity. while (size + headerSize > capacity) { remove(); } // Copy name and value that modifications of original do not affect the dynamic table. name = Arrays.copyOf(name, name.length); value = Arrays.copyOf(value, value.length); int h = hash(name); int i = index(h); HeaderEntry old = headerFields[i]; HeaderEntry e = new HeaderEntry(h, name, value, head.before.index - 1, old); headerFields[i] = e; e.addBefore(head); size += headerSize; }
/** * Add the header field to the dynamic table. * Entries are evicted from the dynamic table until the size of the table * and the new header field is less than the table's capacity. * If the size of the new entry is larger than the table's capacity, * the dynamic table will be cleared. */ private void add(byte[] name, byte[] value) { int headerSize = HeaderField.sizeOf(name, value); // Clear the table if the header field size is larger than the capacity. if (headerSize > capacity) { clear(); return; } // Evict oldest entries until we have enough capacity. while (size + headerSize > capacity) { remove(); } // Copy name and value that modifications of original do not affect the dynamic table. name = Arrays.copyOf(name, name.length); value = Arrays.copyOf(value, value.length); int h = hash(name); int i = index(h); HeaderEntry old = headerFields[i]; HeaderEntry e = new HeaderEntry(h, name, value, head.before.index - 1, old); headerFields[i] = e; e.addBefore(head); size += headerSize; }
/** * Returns the lowest index value for the header field name in the dynamic table. * Returns -1 if the header field name is not in the dynamic table. */ private int getIndex(byte[] name) { if (length() == 0 || name == null) { return -1; } int h = hash(name); int i = index(h); int index = -1; for (HeaderEntry e = headerFields[i]; e != null; e = e.next) { if (e.hash == h && HpackUtil.equals(name, e.name)) { index = e.index; break; } } return getIndex(index); }
/** * Returns the header entry with the lowest index value for the header field. * Returns null if header field is not in the dynamic table. */ private HeaderEntry getEntry(byte[] name, byte[] value) { if (length() == 0 || name == null || value == null) { return null; } int h = hash(name); int i = index(h); for (HeaderEntry e = headerFields[i]; e != null; e = e.next) { if (e.hash == h && HpackUtil.equals(name, e.name) && HpackUtil.equals(value, e.value)) { return e; } } return null; }
/** * Returns the header entry with the lowest index value for the header field. * Returns null if header field is not in the dynamic table. */ private HeaderEntry getEntry(byte[] name, byte[] value) { if (length() == 0 || name == null || value == null) { return null; } int h = hash(name); int i = index(h); for (HeaderEntry e = headerFields[i]; e != null; e = e.next) { if (e.hash == h && HpackUtil.equals(name, e.name) && HpackUtil.equals(value, e.value)) { return e; } } return null; }
/** * Returns the lowest index value for the header field name in the dynamic table. * Returns -1 if the header field name is not in the dynamic table. */ private int getIndex(byte[] name) { if (length() == 0 || name == null) { return -1; } int h = hash(name); int i = index(h); int index = -1; for (HeaderEntry e = headerFields[i]; e != null; e = e.next) { if (e.hash == h && HpackUtil.equals(name, e.name)) { index = e.index; break; } } return getIndex(index); }