2013-10-10 00:21:49 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set sw=2 ts=8 et tw=80 : */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
// HttpLog.h should generally be included first
|
|
|
|
#include "HttpLog.h"
|
|
|
|
|
2014-02-07 21:15:24 +00:00
|
|
|
// Log on level :5, instead of default :4.
|
|
|
|
#undef LOG
|
|
|
|
#define LOG(args) LOG5(args)
|
|
|
|
#undef LOG_ENABLED
|
|
|
|
#define LOG_ENABLED() LOG5_ENABLED()
|
|
|
|
|
2013-10-10 00:21:49 +00:00
|
|
|
#include "Http2Compression.h"
|
|
|
|
#include "Http2HuffmanIncoming.h"
|
|
|
|
#include "Http2HuffmanOutgoing.h"
|
|
|
|
|
|
|
|
extern PRThread *gSocketThread;
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace net {
|
|
|
|
|
|
|
|
static nsDeque *gStaticHeaders = nullptr;
|
|
|
|
|
|
|
|
void
|
|
|
|
Http2CompressionCleanup()
|
|
|
|
{
|
|
|
|
// this happens after the socket thread has been destroyed
|
|
|
|
delete gStaticHeaders;
|
|
|
|
gStaticHeaders = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
AddStaticElement(const nsCString &name, const nsCString &value)
|
|
|
|
{
|
|
|
|
nvPair *pair = new nvPair(name, value);
|
|
|
|
gStaticHeaders->Push(pair);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
AddStaticElement(const nsCString &name)
|
|
|
|
{
|
|
|
|
AddStaticElement(name, EmptyCString());
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
InitializeStaticHeaders()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(PR_GetCurrentThread() == gSocketThread);
|
|
|
|
if (!gStaticHeaders) {
|
|
|
|
gStaticHeaders = new nsDeque();
|
|
|
|
AddStaticElement(NS_LITERAL_CSTRING(":authority"));
|
|
|
|
AddStaticElement(NS_LITERAL_CSTRING(":method"), NS_LITERAL_CSTRING("GET"));
|
|
|
|
AddStaticElement(NS_LITERAL_CSTRING(":method"), NS_LITERAL_CSTRING("POST"));
|
|
|
|
AddStaticElement(NS_LITERAL_CSTRING(":path"), NS_LITERAL_CSTRING("/"));
|
|
|
|
AddStaticElement(NS_LITERAL_CSTRING(":path"), NS_LITERAL_CSTRING("/index.html"));
|
|
|
|
AddStaticElement(NS_LITERAL_CSTRING(":scheme"), NS_LITERAL_CSTRING("http"));
|
|
|
|
AddStaticElement(NS_LITERAL_CSTRING(":scheme"), NS_LITERAL_CSTRING("https"));
|
|
|
|
AddStaticElement(NS_LITERAL_CSTRING(":status"), NS_LITERAL_CSTRING("200"));
|
2014-04-30 01:45:59 +00:00
|
|
|
AddStaticElement(NS_LITERAL_CSTRING(":status"), NS_LITERAL_CSTRING("204"));
|
|
|
|
AddStaticElement(NS_LITERAL_CSTRING(":status"), NS_LITERAL_CSTRING("206"));
|
|
|
|
AddStaticElement(NS_LITERAL_CSTRING(":status"), NS_LITERAL_CSTRING("304"));
|
2013-10-10 00:21:49 +00:00
|
|
|
AddStaticElement(NS_LITERAL_CSTRING(":status"), NS_LITERAL_CSTRING("400"));
|
2014-04-30 01:45:59 +00:00
|
|
|
AddStaticElement(NS_LITERAL_CSTRING(":status"), NS_LITERAL_CSTRING("404"));
|
|
|
|
AddStaticElement(NS_LITERAL_CSTRING(":status"), NS_LITERAL_CSTRING("500"));
|
2013-10-10 00:21:49 +00:00
|
|
|
AddStaticElement(NS_LITERAL_CSTRING("accept-charset"));
|
2014-06-26 00:33:15 +00:00
|
|
|
AddStaticElement(NS_LITERAL_CSTRING("accept-encoding"), NS_LITERAL_CSTRING("gzip, deflate"));
|
2013-10-10 00:21:49 +00:00
|
|
|
AddStaticElement(NS_LITERAL_CSTRING("accept-language"));
|
|
|
|
AddStaticElement(NS_LITERAL_CSTRING("accept-ranges"));
|
|
|
|
AddStaticElement(NS_LITERAL_CSTRING("accept"));
|
|
|
|
AddStaticElement(NS_LITERAL_CSTRING("access-control-allow-origin"));
|
|
|
|
AddStaticElement(NS_LITERAL_CSTRING("age"));
|
|
|
|
AddStaticElement(NS_LITERAL_CSTRING("allow"));
|
|
|
|
AddStaticElement(NS_LITERAL_CSTRING("authorization"));
|
|
|
|
AddStaticElement(NS_LITERAL_CSTRING("cache-control"));
|
|
|
|
AddStaticElement(NS_LITERAL_CSTRING("content-disposition"));
|
|
|
|
AddStaticElement(NS_LITERAL_CSTRING("content-encoding"));
|
|
|
|
AddStaticElement(NS_LITERAL_CSTRING("content-language"));
|
|
|
|
AddStaticElement(NS_LITERAL_CSTRING("content-length"));
|
|
|
|
AddStaticElement(NS_LITERAL_CSTRING("content-location"));
|
|
|
|
AddStaticElement(NS_LITERAL_CSTRING("content-range"));
|
|
|
|
AddStaticElement(NS_LITERAL_CSTRING("content-type"));
|
|
|
|
AddStaticElement(NS_LITERAL_CSTRING("cookie"));
|
|
|
|
AddStaticElement(NS_LITERAL_CSTRING("date"));
|
|
|
|
AddStaticElement(NS_LITERAL_CSTRING("etag"));
|
|
|
|
AddStaticElement(NS_LITERAL_CSTRING("expect"));
|
|
|
|
AddStaticElement(NS_LITERAL_CSTRING("expires"));
|
|
|
|
AddStaticElement(NS_LITERAL_CSTRING("from"));
|
2014-01-14 01:16:26 +00:00
|
|
|
AddStaticElement(NS_LITERAL_CSTRING("host"));
|
2013-10-10 00:21:49 +00:00
|
|
|
AddStaticElement(NS_LITERAL_CSTRING("if-match"));
|
|
|
|
AddStaticElement(NS_LITERAL_CSTRING("if-modified-since"));
|
|
|
|
AddStaticElement(NS_LITERAL_CSTRING("if-none-match"));
|
|
|
|
AddStaticElement(NS_LITERAL_CSTRING("if-range"));
|
|
|
|
AddStaticElement(NS_LITERAL_CSTRING("if-unmodified-since"));
|
|
|
|
AddStaticElement(NS_LITERAL_CSTRING("last-modified"));
|
|
|
|
AddStaticElement(NS_LITERAL_CSTRING("link"));
|
|
|
|
AddStaticElement(NS_LITERAL_CSTRING("location"));
|
|
|
|
AddStaticElement(NS_LITERAL_CSTRING("max-forwards"));
|
|
|
|
AddStaticElement(NS_LITERAL_CSTRING("proxy-authenticate"));
|
|
|
|
AddStaticElement(NS_LITERAL_CSTRING("proxy-authorization"));
|
|
|
|
AddStaticElement(NS_LITERAL_CSTRING("range"));
|
|
|
|
AddStaticElement(NS_LITERAL_CSTRING("referer"));
|
|
|
|
AddStaticElement(NS_LITERAL_CSTRING("refresh"));
|
|
|
|
AddStaticElement(NS_LITERAL_CSTRING("retry-after"));
|
|
|
|
AddStaticElement(NS_LITERAL_CSTRING("server"));
|
|
|
|
AddStaticElement(NS_LITERAL_CSTRING("set-cookie"));
|
|
|
|
AddStaticElement(NS_LITERAL_CSTRING("strict-transport-security"));
|
|
|
|
AddStaticElement(NS_LITERAL_CSTRING("transfer-encoding"));
|
|
|
|
AddStaticElement(NS_LITERAL_CSTRING("user-agent"));
|
|
|
|
AddStaticElement(NS_LITERAL_CSTRING("vary"));
|
|
|
|
AddStaticElement(NS_LITERAL_CSTRING("via"));
|
|
|
|
AddStaticElement(NS_LITERAL_CSTRING("www-authenticate"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nvFIFO::nvFIFO()
|
|
|
|
: mByteCount(0)
|
|
|
|
, mTable()
|
|
|
|
{
|
|
|
|
InitializeStaticHeaders();
|
|
|
|
}
|
|
|
|
|
|
|
|
nvFIFO::~nvFIFO()
|
|
|
|
{
|
|
|
|
Clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nvFIFO::AddElement(const nsCString &name, const nsCString &value)
|
|
|
|
{
|
|
|
|
mByteCount += name.Length() + value.Length() + 32;
|
|
|
|
nvPair *pair = new nvPair(name, value);
|
|
|
|
mTable.PushFront(pair);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nvFIFO::AddElement(const nsCString &name)
|
|
|
|
{
|
|
|
|
AddElement(name, EmptyCString());
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nvFIFO::RemoveElement()
|
|
|
|
{
|
|
|
|
nvPair *pair = static_cast<nvPair *>(mTable.Pop());
|
|
|
|
if (pair) {
|
|
|
|
mByteCount -= pair->Size();
|
|
|
|
delete pair;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
nvFIFO::ByteCount() const
|
|
|
|
{
|
|
|
|
return mByteCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
nvFIFO::Length() const
|
|
|
|
{
|
|
|
|
return mTable.GetSize() + gStaticHeaders->GetSize();
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
nvFIFO::VariableLength() const
|
|
|
|
{
|
|
|
|
return mTable.GetSize();
|
|
|
|
}
|
|
|
|
|
2014-08-05 15:41:09 +00:00
|
|
|
uint32_t
|
|
|
|
nvFIFO::StaticLength() const
|
|
|
|
{
|
|
|
|
return gStaticHeaders->GetSize();
|
|
|
|
}
|
|
|
|
|
2013-10-10 00:21:49 +00:00
|
|
|
void
|
|
|
|
nvFIFO::Clear()
|
|
|
|
{
|
|
|
|
mByteCount = 0;
|
|
|
|
while (mTable.GetSize())
|
|
|
|
delete static_cast<nvPair *>(mTable.Pop());
|
|
|
|
}
|
|
|
|
|
|
|
|
const nvPair *
|
|
|
|
nvFIFO::operator[] (int32_t index) const
|
|
|
|
{
|
2014-08-05 15:41:09 +00:00
|
|
|
// NWGH - ensure index > 0
|
|
|
|
// NWGH - subtract 1 from index here
|
2013-10-10 00:21:49 +00:00
|
|
|
if (index >= (mTable.GetSize() + gStaticHeaders->GetSize())) {
|
|
|
|
MOZ_ASSERT(false);
|
|
|
|
NS_WARNING("nvFIFO Table Out of Range");
|
|
|
|
return nullptr;
|
|
|
|
}
|
2014-08-05 15:41:09 +00:00
|
|
|
if (index >= gStaticHeaders->GetSize()) {
|
|
|
|
return static_cast<nvPair *>(mTable.ObjectAt(index - gStaticHeaders->GetSize()));
|
2013-10-10 00:21:49 +00:00
|
|
|
}
|
2014-08-05 15:41:09 +00:00
|
|
|
return static_cast<nvPair *>(gStaticHeaders->ObjectAt(index));
|
2013-10-10 00:21:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Http2BaseCompressor::Http2BaseCompressor()
|
|
|
|
: mOutput(nullptr)
|
|
|
|
, mMaxBuffer(kDefaultMaxBuffer)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Http2BaseCompressor::ClearHeaderTable()
|
|
|
|
{
|
|
|
|
mHeaderTable.Clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-08-05 15:41:09 +00:00
|
|
|
Http2BaseCompressor::MakeRoom(uint32_t amount, const char *direction)
|
2013-10-10 00:21:49 +00:00
|
|
|
{
|
2014-08-05 15:41:09 +00:00
|
|
|
// make room in the header table
|
|
|
|
while (mHeaderTable.VariableLength() && ((mHeaderTable.ByteCount() + amount) > mMaxBuffer)) {
|
|
|
|
// NWGH - remove the "- 1" here
|
|
|
|
uint32_t index = mHeaderTable.Length() - 1;
|
|
|
|
LOG(("HTTP %s header table index %u %s %s removed for size.\n",
|
|
|
|
direction, index, mHeaderTable[index]->mName.get(),
|
|
|
|
mHeaderTable[index]->mValue.get()));
|
|
|
|
mHeaderTable.RemoveElement();
|
2013-10-10 00:21:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-30 23:16:23 +00:00
|
|
|
void
|
|
|
|
Http2BaseCompressor::DumpState()
|
|
|
|
{
|
|
|
|
LOG(("Header Table"));
|
2014-08-05 15:41:09 +00:00
|
|
|
uint32_t i;
|
|
|
|
uint32_t length = mHeaderTable.Length();
|
|
|
|
uint32_t staticLength = mHeaderTable.StaticLength();
|
|
|
|
// NWGH - make i = 1; i <= length; ++i
|
2014-05-30 23:16:23 +00:00
|
|
|
for (i = 0; i < length; ++i) {
|
|
|
|
const nvPair *pair = mHeaderTable[i];
|
2014-08-05 15:41:09 +00:00
|
|
|
// NWGH - make this <= staticLength
|
|
|
|
LOG(("%sindex %u: %s %s", i < staticLength ? "static " : "", i,
|
2014-07-11 16:48:32 +00:00
|
|
|
pair->mName.get(), pair->mValue.get()));
|
2014-05-30 23:16:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-10 00:21:49 +00:00
|
|
|
nsresult
|
|
|
|
Http2Decompressor::DecodeHeaderBlock(const uint8_t *data, uint32_t datalen,
|
2014-08-18 21:59:32 +00:00
|
|
|
nsACString &output, bool isPush)
|
2013-10-10 00:21:49 +00:00
|
|
|
{
|
|
|
|
mOffset = 0;
|
|
|
|
mData = data;
|
|
|
|
mDataLen = datalen;
|
|
|
|
mOutput = &output;
|
|
|
|
mOutput->Truncate();
|
|
|
|
mHeaderStatus.Truncate();
|
|
|
|
mHeaderHost.Truncate();
|
|
|
|
mHeaderScheme.Truncate();
|
|
|
|
mHeaderPath.Truncate();
|
|
|
|
mHeaderMethod.Truncate();
|
2014-08-05 15:41:09 +00:00
|
|
|
mSeenNonColonHeader = false;
|
2014-08-18 21:59:32 +00:00
|
|
|
mIsPush = isPush;
|
2013-10-10 00:21:49 +00:00
|
|
|
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
while (NS_SUCCEEDED(rv) && (mOffset < datalen)) {
|
|
|
|
if (mData[mOffset] & 0x80) {
|
|
|
|
rv = DoIndexed();
|
2014-05-30 23:16:23 +00:00
|
|
|
LOG(("Decompressor state after indexed"));
|
2013-10-10 00:21:49 +00:00
|
|
|
} else if (mData[mOffset] & 0x40) {
|
|
|
|
rv = DoLiteralWithIncremental();
|
2014-05-30 23:16:23 +00:00
|
|
|
LOG(("Decompressor state after literal with incremental"));
|
2014-04-30 01:45:59 +00:00
|
|
|
} else if (mData[mOffset] & 0x20) {
|
|
|
|
rv = DoContextUpdate();
|
2014-05-30 23:16:23 +00:00
|
|
|
LOG(("Decompressor state after context update"));
|
2014-04-30 01:45:59 +00:00
|
|
|
} else if (mData[mOffset] & 0x10) {
|
|
|
|
rv = DoLiteralNeverIndexed();
|
2014-05-30 23:16:23 +00:00
|
|
|
LOG(("Decompressor state after literal never index"));
|
2014-04-30 01:45:59 +00:00
|
|
|
} else {
|
|
|
|
rv = DoLiteralWithoutIndex();
|
2014-05-30 23:16:23 +00:00
|
|
|
LOG(("Decompressor state after literal without index"));
|
2013-10-10 00:21:49 +00:00
|
|
|
}
|
2014-05-30 23:16:23 +00:00
|
|
|
DumpState();
|
2013-10-10 00:21:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
Http2Decompressor::DecodeInteger(uint32_t prefixLen, uint32_t &accum)
|
|
|
|
{
|
|
|
|
accum = 0;
|
|
|
|
|
|
|
|
if (prefixLen) {
|
|
|
|
uint32_t mask = (1 << prefixLen) - 1;
|
|
|
|
|
|
|
|
accum = mData[mOffset] & mask;
|
|
|
|
++mOffset;
|
|
|
|
|
|
|
|
if (accum != mask) {
|
|
|
|
// the simple case for small values
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t factor = 1; // 128 ^ 0
|
|
|
|
|
|
|
|
// we need a series of bytes. The high bit signifies if we need another one.
|
|
|
|
// The first one is a a factor of 128 ^ 0, the next 128 ^1, the next 128 ^2, ..
|
|
|
|
|
|
|
|
if (mOffset >= mDataLen) {
|
|
|
|
NS_WARNING("Ran out of data to decode integer");
|
|
|
|
return NS_ERROR_ILLEGAL_VALUE;
|
|
|
|
}
|
|
|
|
bool chainBit = mData[mOffset] & 0x80;
|
|
|
|
accum += (mData[mOffset] & 0x7f) * factor;
|
|
|
|
|
|
|
|
++mOffset;
|
|
|
|
factor = factor * 128;
|
|
|
|
|
|
|
|
while (chainBit) {
|
|
|
|
// really big offsets are just trawling for overflows
|
|
|
|
if (accum >= 0x800000) {
|
|
|
|
NS_WARNING("Decoding integer >= 0x800000");
|
|
|
|
return NS_ERROR_ILLEGAL_VALUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mOffset >= mDataLen) {
|
|
|
|
NS_WARNING("Ran out of data to decode integer");
|
|
|
|
return NS_ERROR_ILLEGAL_VALUE;
|
|
|
|
}
|
|
|
|
chainBit = mData[mOffset] & 0x80;
|
|
|
|
accum += (mData[mOffset] & 0x7f) * factor;
|
|
|
|
++mOffset;
|
|
|
|
factor = factor * 128;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
Http2Decompressor::OutputHeader(const nsACString &name, const nsACString &value)
|
|
|
|
{
|
|
|
|
// exclusions
|
2014-08-18 21:59:32 +00:00
|
|
|
if (!mIsPush &&
|
|
|
|
(name.EqualsLiteral("connection") ||
|
|
|
|
name.EqualsLiteral("host") ||
|
|
|
|
name.EqualsLiteral("keep-alive") ||
|
|
|
|
name.EqualsLiteral("proxy-connection") ||
|
|
|
|
name.EqualsLiteral("te") ||
|
|
|
|
name.EqualsLiteral("transfer-encoding") ||
|
|
|
|
name.EqualsLiteral("upgrade") ||
|
|
|
|
name.Equals(("accept-encoding")))) {
|
2013-10-10 00:21:49 +00:00
|
|
|
nsCString toLog(name);
|
2014-08-18 21:59:32 +00:00
|
|
|
LOG(("HTTP Decompressor illegal response header found, not gatewaying: %s",
|
2014-05-30 23:16:23 +00:00
|
|
|
toLog.get()));
|
2014-08-18 21:59:32 +00:00
|
|
|
return NS_OK;
|
2013-10-10 00:21:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Look for upper case characters in the name.
|
|
|
|
for (const char *cPtr = name.BeginReading();
|
|
|
|
cPtr && cPtr < name.EndReading();
|
|
|
|
++cPtr) {
|
|
|
|
if (*cPtr <= 'Z' && *cPtr >= 'A') {
|
|
|
|
nsCString toLog(name);
|
2014-05-30 23:16:23 +00:00
|
|
|
LOG(("HTTP Decompressor upper case response header found. [%s]\n",
|
|
|
|
toLog.get()));
|
2013-10-10 00:21:49 +00:00
|
|
|
return NS_ERROR_ILLEGAL_VALUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Look for CR OR LF in value - could be smuggling Sec 10.3
|
|
|
|
// can map to space safely
|
|
|
|
for (const char *cPtr = value.BeginReading();
|
|
|
|
cPtr && cPtr < value.EndReading();
|
|
|
|
++cPtr) {
|
|
|
|
if (*cPtr == '\r' || *cPtr== '\n') {
|
|
|
|
char *wPtr = const_cast<char *>(cPtr);
|
|
|
|
*wPtr = ' ';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Status comes first
|
2014-05-22 03:48:51 +00:00
|
|
|
if (name.EqualsLiteral(":status")) {
|
2014-01-29 21:42:19 +00:00
|
|
|
nsAutoCString status(NS_LITERAL_CSTRING("HTTP/2.0 "));
|
2013-10-10 00:21:49 +00:00
|
|
|
status.Append(value);
|
2014-05-22 03:48:50 +00:00
|
|
|
status.AppendLiteral("\r\n");
|
2013-10-10 00:21:49 +00:00
|
|
|
mOutput->Insert(status, 0);
|
|
|
|
mHeaderStatus = value;
|
2014-05-22 03:48:51 +00:00
|
|
|
} else if (name.EqualsLiteral(":authority")) {
|
2013-10-10 00:21:49 +00:00
|
|
|
mHeaderHost = value;
|
2014-05-22 03:48:51 +00:00
|
|
|
} else if (name.EqualsLiteral(":scheme")) {
|
2013-10-10 00:21:49 +00:00
|
|
|
mHeaderScheme = value;
|
2014-05-22 03:48:51 +00:00
|
|
|
} else if (name.EqualsLiteral(":path")) {
|
2013-10-10 00:21:49 +00:00
|
|
|
mHeaderPath = value;
|
2014-05-22 03:48:51 +00:00
|
|
|
} else if (name.EqualsLiteral(":method")) {
|
2013-10-10 00:21:49 +00:00
|
|
|
mHeaderMethod = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
// http/2 transport level headers shouldn't be gatewayed into http/1
|
2014-08-05 15:41:09 +00:00
|
|
|
bool isColonHeader = false;
|
|
|
|
for (const char *cPtr = name.BeginReading();
|
|
|
|
cPtr && cPtr < name.EndReading();
|
|
|
|
++cPtr) {
|
|
|
|
if (*cPtr == ':') {
|
|
|
|
isColonHeader = true;
|
|
|
|
break;
|
|
|
|
} else if (*cPtr != ' ' && *cPtr != '\t') {
|
|
|
|
isColonHeader = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(isColonHeader) {
|
|
|
|
if (mSeenNonColonHeader) {
|
|
|
|
LOG(("HTTP Decompressor found illegal : header %s", name.BeginReading()));
|
|
|
|
return NS_ERROR_ILLEGAL_VALUE;
|
|
|
|
}
|
2014-05-30 23:16:23 +00:00
|
|
|
LOG(("HTTP Decompressor not gatewaying %s into http/1",
|
|
|
|
name.BeginReading()));
|
2013-10-10 00:21:49 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-08-05 15:41:09 +00:00
|
|
|
LOG(("Http2Decompressor::OutputHeader %s %s", name.BeginReading(),
|
|
|
|
value.BeginReading()));
|
|
|
|
mSeenNonColonHeader = true;
|
2013-10-10 00:21:49 +00:00
|
|
|
mOutput->Append(name);
|
2014-05-22 03:48:50 +00:00
|
|
|
mOutput->AppendLiteral(": ");
|
2014-08-05 15:41:09 +00:00
|
|
|
mOutput->Append(value);
|
2014-05-22 03:48:50 +00:00
|
|
|
mOutput->AppendLiteral("\r\n");
|
2013-10-10 00:21:49 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
Http2Decompressor::OutputHeader(uint32_t index)
|
|
|
|
{
|
2014-08-05 15:41:09 +00:00
|
|
|
// NWGH - make this < index
|
2013-10-10 00:21:49 +00:00
|
|
|
// bounds check
|
2014-07-11 16:48:32 +00:00
|
|
|
if (mHeaderTable.Length() <= index) {
|
|
|
|
LOG(("Http2Decompressor::OutputHeader index too large %u", index));
|
2013-10-10 00:21:49 +00:00
|
|
|
return NS_ERROR_ILLEGAL_VALUE;
|
2014-07-11 16:48:32 +00:00
|
|
|
}
|
2013-10-10 00:21:49 +00:00
|
|
|
|
|
|
|
return OutputHeader(mHeaderTable[index]->mName,
|
|
|
|
mHeaderTable[index]->mValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
Http2Decompressor::CopyHeaderString(uint32_t index, nsACString &name)
|
|
|
|
{
|
2014-08-05 15:41:09 +00:00
|
|
|
// NWGH - make this < index
|
2013-10-10 00:21:49 +00:00
|
|
|
// bounds check
|
|
|
|
if (mHeaderTable.Length() <= index)
|
|
|
|
return NS_ERROR_ILLEGAL_VALUE;
|
|
|
|
|
|
|
|
name = mHeaderTable[index]->mName;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
Http2Decompressor::CopyStringFromInput(uint32_t bytes, nsACString &val)
|
|
|
|
{
|
|
|
|
if (mOffset + bytes > mDataLen)
|
|
|
|
return NS_ERROR_ILLEGAL_VALUE;
|
|
|
|
|
|
|
|
val.Assign(reinterpret_cast<const char *>(mData) + mOffset, bytes);
|
|
|
|
mOffset += bytes;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
Http2Decompressor::DecodeFinalHuffmanCharacter(HuffmanIncomingTable *table,
|
|
|
|
uint8_t &c, uint8_t &bitsLeft)
|
|
|
|
{
|
|
|
|
uint8_t mask = (1 << bitsLeft) - 1;
|
|
|
|
uint8_t idx = mData[mOffset - 1] & mask;
|
2014-03-26 17:58:09 +00:00
|
|
|
idx <<= (8 - bitsLeft);
|
2013-10-10 00:21:49 +00:00
|
|
|
// Don't update bitsLeft yet, because we need to check that value against the
|
|
|
|
// number of bits used by our encoding later on. We'll update when we are sure
|
|
|
|
// how many bits we've actually used.
|
|
|
|
|
2014-03-26 17:58:09 +00:00
|
|
|
HuffmanIncomingEntry *entry = &(table->mEntries[idx]);
|
|
|
|
|
|
|
|
if (entry->mPtr) {
|
2013-10-10 00:21:49 +00:00
|
|
|
// Can't chain to another table when we're all out of bits in the encoding
|
2014-05-30 23:16:23 +00:00
|
|
|
LOG(("DecodeFinalHuffmanCharacter trying to chain when we're out of bits"));
|
2013-10-10 00:21:49 +00:00
|
|
|
return NS_ERROR_ILLEGAL_VALUE;
|
|
|
|
}
|
|
|
|
|
2014-03-26 17:58:09 +00:00
|
|
|
if (bitsLeft < entry->mPrefixLen) {
|
2013-10-10 00:21:49 +00:00
|
|
|
// We don't have enough bits to actually make a match, this is some sort of
|
|
|
|
// invalid coding
|
2014-05-30 23:16:23 +00:00
|
|
|
LOG(("DecodeFinalHuffmanCharacter does't have enough bits to match"));
|
2013-10-10 00:21:49 +00:00
|
|
|
return NS_ERROR_ILLEGAL_VALUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This is a character!
|
2014-03-26 17:58:09 +00:00
|
|
|
if (entry->mValue == 256) {
|
2013-10-10 00:21:49 +00:00
|
|
|
// EOS
|
2014-05-30 23:16:23 +00:00
|
|
|
LOG(("DecodeFinalHuffmanCharacter actually decoded an EOS"));
|
2013-10-10 00:21:49 +00:00
|
|
|
return NS_ERROR_ILLEGAL_VALUE;
|
|
|
|
}
|
2014-03-26 17:58:09 +00:00
|
|
|
c = static_cast<uint8_t>(entry->mValue & 0xFF);
|
|
|
|
bitsLeft -= entry->mPrefixLen;
|
2013-10-10 00:21:49 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-03-26 17:58:09 +00:00
|
|
|
uint8_t
|
|
|
|
Http2Decompressor::ExtractByte(uint8_t bitsLeft, uint32_t &bytesConsumed)
|
|
|
|
{
|
|
|
|
uint8_t rv;
|
|
|
|
|
|
|
|
if (bitsLeft) {
|
|
|
|
// Need to extract bitsLeft bits from the previous byte, and 8 - bitsLeft
|
|
|
|
// bits from the current byte
|
|
|
|
uint8_t mask = (1 << bitsLeft) - 1;
|
|
|
|
rv = (mData[mOffset - 1] & mask) << (8 - bitsLeft);
|
|
|
|
rv |= (mData[mOffset] & ~mask) >> bitsLeft;
|
|
|
|
} else {
|
|
|
|
rv = mData[mOffset];
|
|
|
|
}
|
|
|
|
|
|
|
|
// We always update these here, under the assumption that all 8 bits we got
|
|
|
|
// here will be used. These may be re-adjusted later in the case that we don't
|
|
|
|
// use up all 8 bits of the byte.
|
|
|
|
++mOffset;
|
|
|
|
++bytesConsumed;
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2013-10-10 00:21:49 +00:00
|
|
|
nsresult
|
|
|
|
Http2Decompressor::DecodeHuffmanCharacter(HuffmanIncomingTable *table,
|
|
|
|
uint8_t &c, uint32_t &bytesConsumed,
|
|
|
|
uint8_t &bitsLeft)
|
|
|
|
{
|
2014-03-26 17:58:09 +00:00
|
|
|
uint8_t idx = ExtractByte(bitsLeft, bytesConsumed);
|
|
|
|
HuffmanIncomingEntry *entry = &(table->mEntries[idx]);
|
2013-10-10 00:21:49 +00:00
|
|
|
|
2014-03-26 17:58:09 +00:00
|
|
|
if (entry->mPtr) {
|
2013-10-10 00:21:49 +00:00
|
|
|
if (bytesConsumed >= mDataLen) {
|
|
|
|
if (!bitsLeft || (bytesConsumed > mDataLen)) {
|
2014-03-26 17:58:09 +00:00
|
|
|
// TODO - does this get me into trouble in the new world?
|
2013-10-10 00:21:49 +00:00
|
|
|
// No info left in input to try to consume, we're done
|
2014-05-30 23:16:23 +00:00
|
|
|
LOG(("DecodeHuffmanCharacter all out of bits to consume, can't chain"));
|
2013-10-10 00:21:49 +00:00
|
|
|
return NS_ERROR_ILLEGAL_VALUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We might get lucky here!
|
2014-03-26 17:58:09 +00:00
|
|
|
return DecodeFinalHuffmanCharacter(entry->mPtr, c, bitsLeft);
|
2013-10-10 00:21:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// We're sorry, Mario, but your princess is in another castle
|
2014-03-26 17:58:09 +00:00
|
|
|
return DecodeHuffmanCharacter(entry->mPtr, c, bytesConsumed, bitsLeft);
|
2013-10-10 00:21:49 +00:00
|
|
|
}
|
|
|
|
|
2014-03-26 17:58:09 +00:00
|
|
|
if (entry->mValue == 256) {
|
2014-05-30 23:16:23 +00:00
|
|
|
LOG(("DecodeHuffmanCharacter found an actual EOS"));
|
2013-10-10 00:21:49 +00:00
|
|
|
return NS_ERROR_ILLEGAL_VALUE;
|
|
|
|
}
|
2014-03-26 17:58:09 +00:00
|
|
|
c = static_cast<uint8_t>(entry->mValue & 0xFF);
|
2013-10-10 00:21:49 +00:00
|
|
|
|
|
|
|
// Need to adjust bitsLeft (and possibly other values) because we may not have
|
2014-03-26 17:58:09 +00:00
|
|
|
// consumed all of the bits of the byte we extracted.
|
|
|
|
if (entry->mPrefixLen <= bitsLeft) {
|
|
|
|
bitsLeft -= entry->mPrefixLen;
|
|
|
|
--mOffset;
|
|
|
|
--bytesConsumed;
|
|
|
|
} else {
|
|
|
|
bitsLeft = 8 - (entry->mPrefixLen - bitsLeft);
|
2013-10-10 00:21:49 +00:00
|
|
|
}
|
|
|
|
MOZ_ASSERT(bitsLeft < 8);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
Http2Decompressor::CopyHuffmanStringFromInput(uint32_t bytes, nsACString &val)
|
|
|
|
{
|
|
|
|
if (mOffset + bytes > mDataLen) {
|
2014-05-30 23:16:23 +00:00
|
|
|
LOG(("CopyHuffmanStringFromInput not enough data"));
|
2013-10-10 00:21:49 +00:00
|
|
|
return NS_ERROR_ILLEGAL_VALUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t bytesRead = 0;
|
|
|
|
uint8_t bitsLeft = 0;
|
|
|
|
nsAutoCString buf;
|
|
|
|
nsresult rv;
|
|
|
|
uint8_t c;
|
|
|
|
|
|
|
|
while (bytesRead < bytes) {
|
|
|
|
uint32_t bytesConsumed = 0;
|
|
|
|
rv = DecodeHuffmanCharacter(&HuffmanIncomingRoot, c, bytesConsumed,
|
|
|
|
bitsLeft);
|
|
|
|
if (NS_FAILED(rv)) {
|
2014-05-30 23:16:23 +00:00
|
|
|
LOG(("CopyHuffmanStringFromInput failed to decode a character"));
|
2013-10-10 00:21:49 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
bytesRead += bytesConsumed;
|
|
|
|
buf.Append(c);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bytesRead > bytes) {
|
2014-05-30 23:16:23 +00:00
|
|
|
LOG(("CopyHuffmanStringFromInput read more bytes than was allowed!"));
|
2013-10-10 00:21:49 +00:00
|
|
|
return NS_ERROR_ILLEGAL_VALUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bitsLeft) {
|
|
|
|
// The shortest valid code is 4 bits, so we know there can be at most one
|
|
|
|
// character left that our loop didn't decode. Check to see if that's the
|
|
|
|
// case, and if so, add it to our output.
|
|
|
|
rv = DecodeFinalHuffmanCharacter(&HuffmanIncomingRoot, c, bitsLeft);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
buf.Append(c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-30 01:45:59 +00:00
|
|
|
if (bitsLeft > 7) {
|
2014-05-30 23:16:23 +00:00
|
|
|
LOG(("CopyHuffmanStringFromInput more than 7 bits of padding"));
|
2014-04-30 01:45:59 +00:00
|
|
|
return NS_ERROR_ILLEGAL_VALUE;
|
|
|
|
}
|
|
|
|
|
2013-10-10 00:21:49 +00:00
|
|
|
if (bitsLeft) {
|
|
|
|
// Any bits left at this point must belong to the EOS symbol, so make sure
|
|
|
|
// they make sense (ie, are all ones)
|
|
|
|
uint8_t mask = (1 << bitsLeft) - 1;
|
|
|
|
uint8_t bits = mData[mOffset - 1] & mask;
|
|
|
|
if (bits != mask) {
|
2014-05-30 23:16:23 +00:00
|
|
|
LOG(("CopyHuffmanStringFromInput ran out of data but found possible "
|
|
|
|
"non-EOS symbol"));
|
2013-10-10 00:21:49 +00:00
|
|
|
return NS_ERROR_ILLEGAL_VALUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
val = buf;
|
2014-05-30 23:16:23 +00:00
|
|
|
LOG(("CopyHuffmanStringFromInput decoded a full string!"));
|
2013-10-10 00:21:49 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
Http2Decompressor::DoIndexed()
|
|
|
|
{
|
|
|
|
// this starts with a 1 bit pattern
|
|
|
|
MOZ_ASSERT(mData[mOffset] & 0x80);
|
|
|
|
|
|
|
|
// This is a 7 bit prefix
|
|
|
|
|
|
|
|
uint32_t index;
|
|
|
|
nsresult rv = DecodeInteger(7, index);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2014-05-30 23:16:23 +00:00
|
|
|
LOG(("HTTP decompressor indexed entry %u\n", index));
|
2013-10-10 00:21:49 +00:00
|
|
|
|
2014-01-14 01:16:26 +00:00
|
|
|
if (index == 0) {
|
2014-04-30 01:45:59 +00:00
|
|
|
return NS_ERROR_ILLEGAL_VALUE;
|
2014-01-14 01:16:26 +00:00
|
|
|
}
|
2014-08-05 15:41:09 +00:00
|
|
|
// NWGH - remove this line, since we'll keep everything 1-indexed
|
2014-01-14 01:16:26 +00:00
|
|
|
index--; // Internally, we 0-index everything, since this is, y'know, C++
|
|
|
|
|
2014-08-05 15:41:09 +00:00
|
|
|
return OutputHeader(index);
|
2013-10-10 00:21:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2014-04-30 01:45:59 +00:00
|
|
|
Http2Decompressor::DoLiteralInternal(nsACString &name, nsACString &value,
|
|
|
|
uint32_t namePrefixLen)
|
2013-10-10 00:21:49 +00:00
|
|
|
{
|
|
|
|
// guts of doliteralwithoutindex and doliteralwithincremental
|
2014-04-30 01:45:59 +00:00
|
|
|
MOZ_ASSERT(((mData[mOffset] & 0xF0) == 0x00) || // withoutindex
|
|
|
|
((mData[mOffset] & 0xF0) == 0x10) || // neverindexed
|
|
|
|
((mData[mOffset] & 0xC0) == 0x40)); // withincremental
|
2013-10-10 00:21:49 +00:00
|
|
|
|
|
|
|
// first let's get the name
|
|
|
|
uint32_t index;
|
2014-04-30 01:45:59 +00:00
|
|
|
nsresult rv = DecodeInteger(namePrefixLen, index);
|
2013-10-10 00:21:49 +00:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
bool isHuffmanEncoded;
|
|
|
|
|
|
|
|
if (!index) {
|
|
|
|
// name is embedded as a literal
|
|
|
|
uint32_t nameLen;
|
|
|
|
isHuffmanEncoded = mData[mOffset] & (1 << 7);
|
|
|
|
rv = DecodeInteger(7, nameLen);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
if (isHuffmanEncoded) {
|
|
|
|
rv = CopyHuffmanStringFromInput(nameLen, name);
|
|
|
|
} else {
|
|
|
|
rv = CopyStringFromInput(nameLen, name);
|
|
|
|
}
|
|
|
|
}
|
2014-07-11 16:48:32 +00:00
|
|
|
LOG(("Http2Decompressor::DoLiteralInternal literal name %s",
|
|
|
|
name.BeginReading()));
|
2013-10-10 00:21:49 +00:00
|
|
|
} else {
|
2014-08-05 15:41:09 +00:00
|
|
|
// NWGH - make this index, not index - 1
|
2013-10-10 00:21:49 +00:00
|
|
|
// name is from headertable
|
|
|
|
rv = CopyHeaderString(index - 1, name);
|
2014-07-11 16:48:32 +00:00
|
|
|
LOG(("Http2Decompressor::DoLiteralInternal indexed name %d %s",
|
|
|
|
index, name.BeginReading()));
|
2013-10-10 00:21:49 +00:00
|
|
|
}
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
// now the value
|
|
|
|
uint32_t valueLen;
|
|
|
|
isHuffmanEncoded = mData[mOffset] & (1 << 7);
|
|
|
|
rv = DecodeInteger(7, valueLen);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
if (isHuffmanEncoded) {
|
|
|
|
rv = CopyHuffmanStringFromInput(valueLen, value);
|
|
|
|
} else {
|
|
|
|
rv = CopyStringFromInput(valueLen, value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2014-07-11 16:48:32 +00:00
|
|
|
LOG(("Http2Decompressor::DoLiteralInternal value %s", value.BeginReading()));
|
2013-10-10 00:21:49 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
Http2Decompressor::DoLiteralWithoutIndex()
|
|
|
|
{
|
2014-04-30 01:45:59 +00:00
|
|
|
// this starts with 0000 bit pattern
|
|
|
|
MOZ_ASSERT((mData[mOffset] & 0xF0) == 0x00);
|
2013-10-10 00:21:49 +00:00
|
|
|
|
|
|
|
nsAutoCString name, value;
|
2014-04-30 01:45:59 +00:00
|
|
|
nsresult rv = DoLiteralInternal(name, value, 4);
|
2013-10-10 00:21:49 +00:00
|
|
|
|
2014-05-30 23:16:23 +00:00
|
|
|
LOG(("HTTP decompressor literal without index %s %s\n",
|
|
|
|
name.get(), value.get()));
|
2013-10-10 00:21:49 +00:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
rv = OutputHeader(name, value);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
Http2Decompressor::DoLiteralWithIncremental()
|
|
|
|
{
|
2014-04-30 01:45:59 +00:00
|
|
|
// this starts with 01 bit pattern
|
|
|
|
MOZ_ASSERT((mData[mOffset] & 0xC0) == 0x40);
|
2013-10-10 00:21:49 +00:00
|
|
|
|
|
|
|
nsAutoCString name, value;
|
2014-04-30 01:45:59 +00:00
|
|
|
nsresult rv = DoLiteralInternal(name, value, 6);
|
2013-10-10 00:21:49 +00:00
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
rv = OutputHeader(name, value);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
uint32_t room = nvPair(name, value).Size();
|
|
|
|
if (room > mMaxBuffer) {
|
|
|
|
ClearHeaderTable();
|
2014-08-05 15:41:09 +00:00
|
|
|
LOG(("HTTP decompressor literal with index not inserted due to size %u %s %s\n",
|
2014-05-30 23:16:23 +00:00
|
|
|
room, name.get(), value.get()));
|
|
|
|
LOG(("Decompressor state after ClearHeaderTable"));
|
|
|
|
DumpState();
|
2013-10-10 00:21:49 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-08-05 15:41:09 +00:00
|
|
|
MakeRoom(room, "decompressor");
|
2013-10-10 00:21:49 +00:00
|
|
|
|
|
|
|
// Incremental Indexing implicitly adds a row to the header table.
|
|
|
|
mHeaderTable.AddElement(name, value);
|
|
|
|
|
2014-05-30 23:16:23 +00:00
|
|
|
LOG(("HTTP decompressor literal with index 0 %s %s\n",
|
|
|
|
name.get(), value.get()));
|
2013-10-10 00:21:49 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-04-30 01:45:59 +00:00
|
|
|
nsresult
|
|
|
|
Http2Decompressor::DoLiteralNeverIndexed()
|
|
|
|
{
|
|
|
|
// This starts with 0001 bit pattern
|
|
|
|
MOZ_ASSERT((mData[mOffset] & 0xF0) == 0x10);
|
|
|
|
|
|
|
|
nsAutoCString name, value;
|
|
|
|
nsresult rv = DoLiteralInternal(name, value, 4);
|
|
|
|
|
2014-05-30 23:16:23 +00:00
|
|
|
LOG(("HTTP decompressor literal never indexed %s %s\n",
|
|
|
|
name.get(), value.get()));
|
2014-04-30 01:45:59 +00:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
rv = OutputHeader(name, value);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
Http2Decompressor::DoContextUpdate()
|
|
|
|
{
|
|
|
|
// This starts with 001 bit pattern
|
|
|
|
MOZ_ASSERT((mData[mOffset] & 0xE0) == 0x20);
|
|
|
|
|
|
|
|
// Getting here means we have to adjust the max table size
|
|
|
|
uint32_t newMaxSize;
|
2014-08-05 15:41:09 +00:00
|
|
|
nsresult rv = DecodeInteger(5, newMaxSize);
|
2014-05-30 23:16:23 +00:00
|
|
|
LOG(("Http2Decompressor::DoContextUpdate new maximum size %u", newMaxSize));
|
2014-04-30 01:45:59 +00:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
return mCompressor->SetMaxBufferSizeInternal(newMaxSize);
|
|
|
|
}
|
|
|
|
|
2013-10-10 00:21:49 +00:00
|
|
|
/////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
Http2Compressor::EncodeHeaderBlock(const nsCString &nvInput,
|
|
|
|
const nsACString &method, const nsACString &path,
|
|
|
|
const nsACString &host, const nsACString &scheme,
|
2014-05-16 15:46:13 +00:00
|
|
|
bool connectForm, nsACString &output)
|
2013-10-10 00:21:49 +00:00
|
|
|
{
|
|
|
|
mOutput = &output;
|
|
|
|
output.SetCapacity(1024);
|
|
|
|
output.Truncate();
|
|
|
|
mParsedContentLength = -1;
|
|
|
|
|
2014-04-30 01:46:07 +00:00
|
|
|
// first thing's first - context size updates (if necessary)
|
|
|
|
if (mBufferSizeChangeWaiting) {
|
|
|
|
if (mLowestBufferSizeWaiting < mMaxBufferSetting) {
|
|
|
|
EncodeTableSizeChange(mLowestBufferSizeWaiting);
|
|
|
|
}
|
|
|
|
EncodeTableSizeChange(mMaxBufferSetting);
|
|
|
|
mBufferSizeChangeWaiting = false;
|
|
|
|
}
|
|
|
|
|
2013-10-10 00:21:49 +00:00
|
|
|
// colon headers first
|
2014-05-16 15:46:13 +00:00
|
|
|
if (!connectForm) {
|
2014-06-13 22:02:05 +00:00
|
|
|
ProcessHeader(nvPair(NS_LITERAL_CSTRING(":method"), method), false, false);
|
|
|
|
ProcessHeader(nvPair(NS_LITERAL_CSTRING(":path"), path), true, false);
|
|
|
|
ProcessHeader(nvPair(NS_LITERAL_CSTRING(":authority"), host), false, false);
|
|
|
|
ProcessHeader(nvPair(NS_LITERAL_CSTRING(":scheme"), scheme), false, false);
|
2014-05-16 15:46:13 +00:00
|
|
|
} else {
|
2014-06-13 22:02:05 +00:00
|
|
|
ProcessHeader(nvPair(NS_LITERAL_CSTRING(":method"), method), false, false);
|
|
|
|
ProcessHeader(nvPair(NS_LITERAL_CSTRING(":authority"), host), false, false);
|
2014-05-16 15:46:13 +00:00
|
|
|
}
|
2013-10-10 00:21:49 +00:00
|
|
|
|
|
|
|
// now the non colon headers
|
|
|
|
const char *beginBuffer = nvInput.BeginReading();
|
|
|
|
|
2014-04-30 01:45:59 +00:00
|
|
|
// This strips off the HTTP/1 method+path+version
|
2013-10-10 00:21:49 +00:00
|
|
|
int32_t crlfIndex = nvInput.Find("\r\n");
|
|
|
|
while (true) {
|
|
|
|
int32_t startIndex = crlfIndex + 2;
|
|
|
|
|
|
|
|
crlfIndex = nvInput.Find("\r\n", false, startIndex);
|
|
|
|
if (crlfIndex == -1)
|
|
|
|
break;
|
|
|
|
|
|
|
|
int32_t colonIndex = nvInput.Find(":", false, startIndex,
|
|
|
|
crlfIndex - startIndex);
|
|
|
|
if (colonIndex == -1)
|
|
|
|
break;
|
|
|
|
|
|
|
|
nsDependentCSubstring name = Substring(beginBuffer + startIndex,
|
|
|
|
beginBuffer + colonIndex);
|
|
|
|
// all header names are lower case in http/2
|
|
|
|
ToLowerCase(name);
|
|
|
|
|
|
|
|
// exclusions
|
2014-05-22 03:48:51 +00:00
|
|
|
if (name.EqualsLiteral("connection") ||
|
|
|
|
name.EqualsLiteral("host") ||
|
|
|
|
name.EqualsLiteral("keep-alive") ||
|
|
|
|
name.EqualsLiteral("proxy-connection") ||
|
|
|
|
name.EqualsLiteral("te") ||
|
|
|
|
name.EqualsLiteral("transfer-encoding") ||
|
2014-06-06 23:18:00 +00:00
|
|
|
name.EqualsLiteral("upgrade")) {
|
2013-10-10 00:21:49 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// colon headers are for http/2 and this is http/1 input, so that
|
|
|
|
// is probably a smuggling attack of some kind
|
2014-08-05 15:41:09 +00:00
|
|
|
bool isColonHeader = false;
|
|
|
|
for (const char *cPtr = name.BeginReading();
|
|
|
|
cPtr && cPtr < name.EndReading();
|
|
|
|
++cPtr) {
|
|
|
|
if (*cPtr == ':') {
|
|
|
|
isColonHeader = true;
|
|
|
|
break;
|
|
|
|
} else if (*cPtr != ' ' && *cPtr != '\t') {
|
|
|
|
isColonHeader = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(isColonHeader) {
|
2013-10-10 00:21:49 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t valueIndex = colonIndex + 1;
|
|
|
|
|
|
|
|
while (valueIndex < crlfIndex && beginBuffer[valueIndex] == ' ')
|
|
|
|
++valueIndex;
|
|
|
|
|
|
|
|
nsDependentCSubstring value = Substring(beginBuffer + valueIndex,
|
|
|
|
beginBuffer + crlfIndex);
|
|
|
|
|
2014-05-22 03:48:51 +00:00
|
|
|
if (name.EqualsLiteral("content-length")) {
|
2013-10-10 00:21:49 +00:00
|
|
|
int64_t len;
|
|
|
|
nsCString tmp(value);
|
|
|
|
if (nsHttp::ParseInt64(tmp.get(), nullptr, &len))
|
|
|
|
mParsedContentLength = len;
|
|
|
|
}
|
|
|
|
|
2014-05-22 03:48:51 +00:00
|
|
|
if (name.EqualsLiteral("cookie")) {
|
2014-01-14 01:16:26 +00:00
|
|
|
// cookie crumbling
|
|
|
|
bool haveMoreCookies = true;
|
|
|
|
int32_t nextCookie = valueIndex;
|
|
|
|
while (haveMoreCookies) {
|
|
|
|
int32_t semiSpaceIndex = nvInput.Find("; ", false, nextCookie,
|
|
|
|
crlfIndex - nextCookie);
|
|
|
|
if (semiSpaceIndex == -1) {
|
|
|
|
haveMoreCookies = false;
|
|
|
|
semiSpaceIndex = crlfIndex;
|
|
|
|
}
|
|
|
|
nsDependentCSubstring cookie = Substring(beginBuffer + nextCookie,
|
|
|
|
beginBuffer + semiSpaceIndex);
|
2014-06-07 15:54:38 +00:00
|
|
|
// cookies less than 20 bytes are not indexed
|
2014-06-13 22:02:05 +00:00
|
|
|
ProcessHeader(nvPair(name, cookie), false, name.Length() < 20);
|
2014-01-14 01:16:26 +00:00
|
|
|
nextCookie = semiSpaceIndex + 2;
|
|
|
|
}
|
|
|
|
} else {
|
2014-06-07 15:54:38 +00:00
|
|
|
// allow indexing of every non-cookie except authorization
|
2014-06-13 22:02:05 +00:00
|
|
|
ProcessHeader(nvPair(name, value), false,
|
|
|
|
name.EqualsLiteral("authorization"));
|
2014-01-14 01:16:26 +00:00
|
|
|
}
|
2013-10-10 00:21:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
mOutput = nullptr;
|
2014-05-30 23:16:23 +00:00
|
|
|
LOG(("Compressor state after EncodeHeaderBlock"));
|
|
|
|
DumpState();
|
2013-10-10 00:21:49 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Http2Compressor::DoOutput(Http2Compressor::outputCode code,
|
|
|
|
const class nvPair *pair, uint32_t index)
|
|
|
|
{
|
|
|
|
// start Byte needs to be calculated from the offset after
|
|
|
|
// the opcode has been written out in case the output stream
|
|
|
|
// buffer gets resized/relocated
|
|
|
|
uint32_t offset = mOutput->Length();
|
|
|
|
uint8_t *startByte;
|
|
|
|
|
|
|
|
switch (code) {
|
2014-04-30 01:45:59 +00:00
|
|
|
case kNeverIndexedLiteral:
|
2014-05-30 23:16:23 +00:00
|
|
|
LOG(("HTTP compressor %p neverindex literal with name reference %u %s %s\n",
|
|
|
|
this, index, pair->mName.get(), pair->mValue.get()));
|
2014-04-30 01:45:59 +00:00
|
|
|
|
|
|
|
// In this case, the index will have already been adjusted to be 1-based
|
|
|
|
// instead of 0-based.
|
|
|
|
EncodeInteger(4, index); // 0001 4 bit prefix
|
|
|
|
startByte = reinterpret_cast<unsigned char *>(mOutput->BeginWriting()) + offset;
|
|
|
|
*startByte = (*startByte & 0x0f) | 0x10;
|
|
|
|
|
|
|
|
if (!index) {
|
|
|
|
HuffmanAppend(pair->mName);
|
|
|
|
}
|
|
|
|
|
|
|
|
HuffmanAppend(pair->mValue);
|
|
|
|
break;
|
|
|
|
|
2013-10-10 00:21:49 +00:00
|
|
|
case kPlainLiteral:
|
2014-05-30 23:16:23 +00:00
|
|
|
LOG(("HTTP compressor %p noindex literal with name reference %u %s %s\n",
|
|
|
|
this, index, pair->mName.get(), pair->mValue.get()));
|
2013-10-10 00:21:49 +00:00
|
|
|
|
2014-01-14 01:16:26 +00:00
|
|
|
// In this case, the index will have already been adjusted to be 1-based
|
|
|
|
// instead of 0-based.
|
2014-04-30 01:45:59 +00:00
|
|
|
EncodeInteger(4, index); // 0000 4 bit prefix
|
2013-10-10 00:21:49 +00:00
|
|
|
startByte = reinterpret_cast<unsigned char *>(mOutput->BeginWriting()) + offset;
|
2014-04-30 01:45:59 +00:00
|
|
|
*startByte = *startByte & 0x0f;
|
2013-10-10 00:21:49 +00:00
|
|
|
|
|
|
|
if (!index) {
|
|
|
|
HuffmanAppend(pair->mName);
|
|
|
|
}
|
|
|
|
|
|
|
|
HuffmanAppend(pair->mValue);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case kIndexedLiteral:
|
2014-05-30 23:16:23 +00:00
|
|
|
LOG(("HTTP compressor %p literal with name reference %u %s %s\n",
|
|
|
|
this, index, pair->mName.get(), pair->mValue.get()));
|
2013-10-10 00:21:49 +00:00
|
|
|
|
2014-01-14 01:16:26 +00:00
|
|
|
// In this case, the index will have already been adjusted to be 1-based
|
|
|
|
// instead of 0-based.
|
2014-04-30 01:45:59 +00:00
|
|
|
EncodeInteger(6, index); // 01 2 bit prefix
|
2013-10-10 00:21:49 +00:00
|
|
|
startByte = reinterpret_cast<unsigned char *>(mOutput->BeginWriting()) + offset;
|
2014-04-30 01:45:59 +00:00
|
|
|
*startByte = (*startByte & 0x3f) | 0x40;
|
2013-10-10 00:21:49 +00:00
|
|
|
|
|
|
|
if (!index) {
|
|
|
|
HuffmanAppend(pair->mName);
|
|
|
|
}
|
|
|
|
|
|
|
|
HuffmanAppend(pair->mValue);
|
|
|
|
break;
|
|
|
|
|
2014-08-05 15:41:09 +00:00
|
|
|
case kIndex:
|
|
|
|
LOG(("HTTP compressor %p index %u %s %s\n",
|
|
|
|
this, index, pair->mName.get(), pair->mValue.get()));
|
|
|
|
// NWGH - make this plain old index instead of index + 1
|
2014-01-14 01:16:26 +00:00
|
|
|
// In this case, we are passed the raw 0-based C index, and need to
|
|
|
|
// increment to make it 1-based and comply with the spec
|
|
|
|
EncodeInteger(7, index + 1);
|
2013-10-10 00:21:49 +00:00
|
|
|
startByte = reinterpret_cast<unsigned char *>(mOutput->BeginWriting()) + offset;
|
|
|
|
*startByte = *startByte | 0x80; // 1 1 bit prefix
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// writes the encoded integer onto the output
|
|
|
|
void
|
|
|
|
Http2Compressor::EncodeInteger(uint32_t prefixLen, uint32_t val)
|
|
|
|
{
|
|
|
|
uint32_t mask = (1 << prefixLen) - 1;
|
|
|
|
uint8_t tmp;
|
|
|
|
|
|
|
|
if (val < mask) {
|
|
|
|
// 1 byte encoding!
|
|
|
|
tmp = val;
|
|
|
|
mOutput->Append(reinterpret_cast<char *>(&tmp), 1);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mask) {
|
|
|
|
val -= mask;
|
|
|
|
tmp = mask;
|
|
|
|
mOutput->Append(reinterpret_cast<char *>(&tmp), 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t q, r;
|
|
|
|
do {
|
|
|
|
q = val / 128;
|
|
|
|
r = val % 128;
|
|
|
|
tmp = r;
|
|
|
|
if (q)
|
|
|
|
tmp |= 0x80; // chain bit
|
|
|
|
val = q;
|
|
|
|
mOutput->Append(reinterpret_cast<char *>(&tmp), 1);
|
|
|
|
} while (q);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Http2Compressor::HuffmanAppend(const nsCString &value)
|
|
|
|
{
|
|
|
|
nsAutoCString buf;
|
|
|
|
uint8_t bitsLeft = 8;
|
|
|
|
uint32_t length = value.Length();
|
|
|
|
uint32_t offset;
|
|
|
|
uint8_t *startByte;
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < length; ++i) {
|
|
|
|
uint8_t idx = static_cast<uint8_t>(value[i]);
|
|
|
|
uint8_t huffLength = HuffmanOutgoing[idx].mLength;
|
|
|
|
uint32_t huffValue = HuffmanOutgoing[idx].mValue;
|
|
|
|
|
|
|
|
if (bitsLeft < 8) {
|
|
|
|
// Fill in the least significant <bitsLeft> bits of the previous byte
|
|
|
|
// first
|
|
|
|
uint32_t val;
|
|
|
|
if (huffLength >= bitsLeft) {
|
|
|
|
val = huffValue & ~((1 << (huffLength - bitsLeft)) - 1);
|
|
|
|
val >>= (huffLength - bitsLeft);
|
|
|
|
} else {
|
|
|
|
val = huffValue << (bitsLeft - huffLength);
|
|
|
|
}
|
|
|
|
val &= ((1 << bitsLeft) - 1);
|
|
|
|
offset = buf.Length() - 1;
|
|
|
|
startByte = reinterpret_cast<unsigned char *>(buf.BeginWriting()) + offset;
|
|
|
|
*startByte = *startByte | static_cast<uint8_t>(val & 0xFF);
|
|
|
|
if (huffLength >= bitsLeft) {
|
|
|
|
huffLength -= bitsLeft;
|
|
|
|
bitsLeft = 8;
|
|
|
|
} else {
|
|
|
|
bitsLeft -= huffLength;
|
|
|
|
huffLength = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-30 01:45:59 +00:00
|
|
|
while (huffLength >= 8) {
|
2013-10-10 00:21:49 +00:00
|
|
|
uint32_t mask = ~((1 << (huffLength - 8)) - 1);
|
|
|
|
uint8_t val = ((huffValue & mask) >> (huffLength - 8)) & 0xFF;
|
|
|
|
buf.Append(reinterpret_cast<char *>(&val), 1);
|
|
|
|
huffLength -= 8;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (huffLength) {
|
|
|
|
// Fill in the most significant <huffLength> bits of the next byte
|
|
|
|
bitsLeft = 8 - huffLength;
|
|
|
|
uint8_t val = (huffValue & ((1 << huffLength) - 1)) << bitsLeft;
|
|
|
|
buf.Append(reinterpret_cast<char *>(&val), 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bitsLeft != 8) {
|
|
|
|
// Pad the last <bitsLeft> bits with ones, which corresponds to the EOS
|
|
|
|
// encoding
|
|
|
|
uint8_t val = (1 << bitsLeft) - 1;
|
|
|
|
offset = buf.Length() - 1;
|
|
|
|
startByte = reinterpret_cast<unsigned char *>(buf.BeginWriting()) + offset;
|
|
|
|
*startByte = *startByte | val;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now we know how long our encoded string is, we can fill in our length
|
|
|
|
uint32_t bufLength = buf.Length();
|
|
|
|
offset = mOutput->Length();
|
|
|
|
EncodeInteger(7, bufLength);
|
|
|
|
startByte = reinterpret_cast<unsigned char *>(mOutput->BeginWriting()) + offset;
|
|
|
|
*startByte = *startByte | 0x80;
|
|
|
|
|
|
|
|
// Finally, we can add our REAL data!
|
|
|
|
mOutput->Append(buf);
|
2014-05-30 23:16:23 +00:00
|
|
|
LOG(("Http2Compressor::HuffmanAppend %p encoded %d byte original on %d "
|
|
|
|
"bytes.\n", this, length, bufLength));
|
|
|
|
}
|
|
|
|
|
2013-10-10 00:21:49 +00:00
|
|
|
void
|
2014-06-13 22:02:05 +00:00
|
|
|
Http2Compressor::ProcessHeader(const nvPair inputPair, bool noLocalIndex,
|
|
|
|
bool neverIndex)
|
2013-10-10 00:21:49 +00:00
|
|
|
{
|
|
|
|
uint32_t newSize = inputPair.Size();
|
|
|
|
uint32_t headerTableSize = mHeaderTable.Length();
|
|
|
|
uint32_t matchedIndex;
|
|
|
|
uint32_t nameReference = 0;
|
|
|
|
bool match = false;
|
|
|
|
|
2014-05-30 23:16:23 +00:00
|
|
|
LOG(("Http2Compressor::ProcessHeader %s %s", inputPair.mName.get(),
|
|
|
|
inputPair.mValue.get()));
|
|
|
|
|
2014-08-05 15:41:09 +00:00
|
|
|
// NWGH - make this index = 1; index <= headerTableSize; ++index
|
2013-10-10 00:21:49 +00:00
|
|
|
for (uint32_t index = 0; index < headerTableSize; ++index) {
|
|
|
|
if (mHeaderTable[index]->mName.Equals(inputPair.mName)) {
|
2014-08-05 15:41:09 +00:00
|
|
|
// NWGH - make this nameReference = index
|
2013-10-10 00:21:49 +00:00
|
|
|
nameReference = index + 1;
|
|
|
|
if (mHeaderTable[index]->mValue.Equals(inputPair.mValue)) {
|
|
|
|
match = true;
|
|
|
|
matchedIndex = index;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// We need to emit a new literal
|
2014-06-13 22:02:05 +00:00
|
|
|
if (!match || noLocalIndex || neverIndex) {
|
2014-04-30 01:45:59 +00:00
|
|
|
if (neverIndex) {
|
|
|
|
DoOutput(kNeverIndexedLiteral, &inputPair, nameReference);
|
2014-05-30 23:16:23 +00:00
|
|
|
LOG(("Compressor state after literal never index"));
|
|
|
|
DumpState();
|
2014-04-30 01:45:59 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-06-13 22:02:05 +00:00
|
|
|
if (noLocalIndex || (newSize > (mMaxBuffer / 2)) || (mMaxBuffer < 128)) {
|
2013-10-10 00:21:49 +00:00
|
|
|
DoOutput(kPlainLiteral, &inputPair, nameReference);
|
2014-05-30 23:16:23 +00:00
|
|
|
LOG(("Compressor state after literal without index"));
|
|
|
|
DumpState();
|
2013-10-10 00:21:49 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// make sure to makeroom() first so that any implied items
|
|
|
|
// get preserved.
|
2014-08-05 15:41:09 +00:00
|
|
|
MakeRoom(newSize, "compressor");
|
2013-10-10 00:21:49 +00:00
|
|
|
DoOutput(kIndexedLiteral, &inputPair, nameReference);
|
|
|
|
|
|
|
|
mHeaderTable.AddElement(inputPair.mName, inputPair.mValue);
|
2014-05-30 23:16:23 +00:00
|
|
|
LOG(("HTTP compressor %p new literal placed at index 0\n",
|
|
|
|
this));
|
|
|
|
LOG(("Compressor state after literal with index"));
|
|
|
|
DumpState();
|
2013-10-10 00:21:49 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-08-05 15:41:09 +00:00
|
|
|
// emit an index
|
|
|
|
DoOutput(kIndex, &inputPair, matchedIndex);
|
2014-06-03 20:09:08 +00:00
|
|
|
|
2014-05-30 23:16:23 +00:00
|
|
|
LOG(("Compressor state after index"));
|
|
|
|
DumpState();
|
2013-10-10 00:21:49 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-04-30 01:46:07 +00:00
|
|
|
void
|
|
|
|
Http2Compressor::EncodeTableSizeChange(uint32_t newMaxSize)
|
|
|
|
{
|
|
|
|
uint32_t offset = mOutput->Length();
|
2014-08-12 00:31:26 +00:00
|
|
|
EncodeInteger(5, newMaxSize);
|
2014-04-30 01:46:07 +00:00
|
|
|
uint8_t *startByte = reinterpret_cast<uint8_t *>(mOutput->BeginWriting()) + offset;
|
|
|
|
*startByte = *startByte | 0x20;
|
|
|
|
}
|
|
|
|
|
2013-10-10 00:21:49 +00:00
|
|
|
void
|
|
|
|
Http2Compressor::SetMaxBufferSize(uint32_t maxBufferSize)
|
|
|
|
{
|
2014-03-26 17:58:09 +00:00
|
|
|
mMaxBufferSetting = maxBufferSize;
|
|
|
|
SetMaxBufferSizeInternal(maxBufferSize);
|
2014-04-30 01:46:07 +00:00
|
|
|
if (!mBufferSizeChangeWaiting) {
|
|
|
|
mBufferSizeChangeWaiting = true;
|
|
|
|
mLowestBufferSizeWaiting = maxBufferSize;
|
|
|
|
} else if (maxBufferSize < mLowestBufferSizeWaiting) {
|
|
|
|
mLowestBufferSizeWaiting = maxBufferSize;
|
|
|
|
}
|
2014-03-26 17:58:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
Http2Compressor::SetMaxBufferSizeInternal(uint32_t maxBufferSize)
|
|
|
|
{
|
|
|
|
if (maxBufferSize > mMaxBufferSetting) {
|
|
|
|
return NS_ERROR_ILLEGAL_VALUE;
|
|
|
|
}
|
|
|
|
|
2013-10-10 00:21:49 +00:00
|
|
|
uint32_t removedCount = 0;
|
|
|
|
|
2014-05-30 23:16:23 +00:00
|
|
|
LOG(("Http2Compressor::SetMaxBufferSizeInternal %u called", maxBufferSize));
|
2013-10-10 00:21:49 +00:00
|
|
|
|
|
|
|
while (mHeaderTable.VariableLength() && (mHeaderTable.ByteCount() > maxBufferSize)) {
|
|
|
|
mHeaderTable.RemoveElement();
|
|
|
|
++removedCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
mMaxBuffer = maxBufferSize;
|
2014-03-26 17:58:09 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
2013-10-10 00:21:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace mozilla::net
|
|
|
|
} // namespace mozilla
|