/** *becauseweusearingbuffertypeconstruct,anddon'tactuallyshuffleitemsinthearray,weneedtofigureout *therealindextouse. *<p/> *packageprivateforunittests * *@paramindexTheindexfromthehpack * *@returntherealindexintothearray
*/ int getRealIndex(int index) throws HpackException { // the index is one based, but our table is zero based, hence -1 // also because of our ring buffer setup the indexes are reversed // index = 1 is at position firstSlotPosition + filledSlots int realIndex = (firstSlotPosition + (filledTableSlots - index)) % headerTable.length; if (realIndex < 0) { thrownew HpackException(sm.getString("hpackdecoder.headerTableIndexInvalid", Integer.valueOf(index),
Integer.valueOf(Hpack.STATIC_TABLE_LENGTH), Integer.valueOf(filledTableSlots)));
} return realIndex;
}
privatevoid addStaticTableEntry(int index) throws HpackException { // adds an entry from the static table. if (log.isDebugEnabled()) {
log.debug(sm.getString("hpackdecoder.useStatic", Integer.valueOf(index)));
}
Hpack.HeaderField entry = Hpack.STATIC_TABLE[index];
emitHeader(entry.name, (entry.value == null) ? "" : entry.value);
}
privatevoid addEntryToHeaderTable(Hpack.HeaderField entry) { if (entry.size > maxMemorySizeSoft) { if (log.isDebugEnabled()) {
log.debug(sm.getString("hpackdecoder.clearDynamic"));
} // it is to big to fit, so we just completely clear the table. while (filledTableSlots > 0) {
headerTable[firstSlotPosition] = null;
firstSlotPosition++; if (firstSlotPosition == headerTable.length) {
firstSlotPosition = 0;
}
filledTableSlots--;
}
currentMemorySize = 0; return;
}
resizeIfRequired(); int newTableSlots = filledTableSlots + 1; int tableLength = headerTable.length; int index = (firstSlotPosition + filledTableSlots) % tableLength; if (log.isDebugEnabled()) {
log.debug(sm.getString("hpackdecoder.addDynamic", Integer.valueOf(index), entry.name, entry.value));
}
headerTable[index] = entry; int newSize = currentMemorySize + entry.size; while (newSize > maxMemorySizeSoft) { int clearIndex = firstSlotPosition;
firstSlotPosition++; if (firstSlotPosition == tableLength) {
firstSlotPosition = 0;
}
Hpack.HeaderField oldData = headerTable[clearIndex];
headerTable[clearIndex] = null;
newSize -= oldData.size;
newTableSlots--;
} this.filledTableSlots = newTableSlots;
currentMemorySize = newSize;
}
privatevoid resizeIfRequired() { if (filledTableSlots == headerTable.length) {
Hpack.HeaderField[] newArray = new Hpack.HeaderField[headerTable.length + 10]; // we only grow slowly for (int i = 0; i < headerTable.length; ++i) {
newArray[i] = headerTable[(firstSlotPosition + i) % headerTable.length];
}
firstSlotPosition = 0;
headerTable = newArray;
}
}
privatevoid emitHeader(String name, String value) throws HpackException { // Header names are forced to lower case if ("cookie".equals(name)) { // Only count the cookie header once since HTTP/2 splits it into // multiple headers to aid compression if (!countedCookie) {
headerCount++;
countedCookie = true;
}
} else {
headerCount++;
} // Overhead will vary. The main concern is that lots of small headers // trigger the limiting mechanism correctly. Therefore, use an overhead // estimate of 3 which is the worst case for small headers. int inc = 3 + name.length() + value.length();
headerSize += inc; if (!isHeaderCountExceeded() && !isHeaderSizeExceeded(0)) { if (log.isDebugEnabled()) {
log.debug(sm.getString("hpackdecoder.emitHeader", name, value));
}
headerEmitter.emitHeader(name, value);
}
}
boolean isHeaderSwallowSizeExceeded(int unreadSize) { if (maxHeaderSize < 0) { returnfalse;
} // Swallow the same again before closing the connection. return (headerSize + unreadSize) > (2 * maxHeaderSize);
}
// package private fields for unit tests
int getFirstSlotPosition() { return firstSlotPosition;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.