/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* 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"
// from RFC2616 section 3.6.1, the chunked transfer coding is defined as: // // Chunked-Body = *chunk // last-chunk // trailer // CRLF // chunk = chunk-size [ chunk-extension ] CRLF // chunk-data CRLF // chunk-size = 1*HEX // last-chunk = 1*("0") [ chunk-extension ] CRLF // // chunk-extension = *( ";" chunk-ext-name [ "=" chunk-ext-val ] ) // chunk-ext-name = token // chunk-ext-val = token | quoted-string // chunk-data = chunk-size(OCTET) // trailer = *(entity-header CRLF) // // the chunk-size field is a string of hex digits indicating the size of the // chunk. the chunked encoding is ended by any chunk whose size is zero, // followed by the trailer, which is terminated by an empty line.
while (count) { if (mChunkRemaining) {
uint32_t amt = std::min(mChunkRemaining, count);
nsresult nsHttpChunkedDecoder::ParseChunkRemaining(char* buf, uint32_t count,
uint32_t* bytesConsumed) {
MOZ_ASSERT(mChunkRemaining == 0, "chunk remaining should be zero");
MOZ_ASSERT(count, "unexpected");
*bytesConsumed = 0;
char* p = static_cast<char*>(memchr(buf, '\n', count)); if (p) {
*p = 0;
count = p - buf; // new length
*bytesConsumed = count + 1; // length + newline if ((p > buf) && (*(p - 1) == '\r')) { // eliminate a preceding CR
*(p - 1) = 0;
count--;
}
// make buf point to the full line buffer to parse if (!mLineBuf.IsEmpty()) {
mLineBuf.Append(buf, count);
buf = (char*)mLineBuf.get();
count = mLineBuf.Length();
}
if (mWaitEOF) { if (*buf) {
LOG(("got trailer: %s\n", buf)); // allocate a header array for the trailers on demand if (!mTrailers) {
mTrailers = MakeUnique<nsHttpHeaderArray>();
}
nsHttpAtom hdr;
nsAutoCString headerNameOriginal;
nsAutoCString val; if (NS_SUCCEEDED(
mTrailers->ParseHeaderLine(nsDependentCSubstring(buf, count),
&hdr, &headerNameOriginal, &val))) { if (hdr == nsHttp::Server_Timing) {
Unused << mTrailers->SetHeaderFromNet(hdr, headerNameOriginal, val, true);
}
}
} else {
mWaitEOF = false;
mReachedEOF = true;
LOG(("reached end of chunked-body\n"));
}
} elseif (*buf) { char* endptr; unsignedlong parsedval; // could be 64 bit, could be 32
// ignore any chunk-extensions if ((p = strchr(buf, ';')) != nullptr) {
*p = 0;
}
// mChunkRemaining is an uint32_t!
parsedval = strtoul(buf, &endptr, 16);
mChunkRemaining = (uint32_t)parsedval;
// we've discovered the last chunk if (mChunkRemaining == 0) mWaitEOF = true;
}
// ensure that the line buffer is clear
mLineBuf.Truncate();
} else { // save the partial line; wait for more data
*bytesConsumed = count; // ignore a trailing CR if (buf[count - 1] == '\r') count--;
mLineBuf.Append(buf, count);
}
return NS_OK;
}
} // namespace net
} // namespace mozilla
¤ Dauer der Verarbeitung: 0.20 Sekunden
(vorverarbeitet)
¤
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 ist noch experimentell.