}
bool
-Http::One::Parser::findMimeBlock(const char *which, const size_t limit)
+Http::One::Parser::grabMimeBlock(const char *which, const size_t limit)
{
// MIME headers block exist in (only) HTTP/1.x and ICY
const bool expectMime = (msgProtocol_.protocol == AnyP::PROTO_HTTP && msgProtocol_.major == 1) ||
* So the rest of the code will need to deal with '0'-byte headers
* (ie, none, so don't try parsing em)
*/
- int64_t mimeHeaderBytes = 0;
// XXX: c_str() reallocates. performance regression.
- if ((mimeHeaderBytes = headersEnd(buf_.c_str(), buf_.length())) == 0) {
+ if (int64_t mimeHeaderBytes = headersEnd(buf_.c_str(), buf_.length())) {
+
+ // Squid could handle these headers, but admin does not want to
+ if (firstLineSize() + mimeHeaderBytes >= limit) {
+ debugs(33, 5, "Too large " << which);
+ parseStatusCode = Http::scHeaderTooLarge;
+ buf_.consume(mimeHeaderBytes);
+ parsingStage_ = HTTP_PARSE_DONE;
+ return false;
+ }
+
+ mimeHeaderBlock_ = buf_.consume(mimeHeaderBytes);
+ debugs(74, 5, "mime header (0-" << mimeHeaderBytes << ") {" << mimeHeaderBlock_ << "}");
+
+ } else { // headersEnd() == 0
if (buf_.length()+firstLineSize() >= limit) {
debugs(33, 5, "Too large " << which);
parseStatusCode = Http::scHeaderTooLarge;
return false;
}
- // Squid could handle these headers, but admin does not want to
- if (messageHeaderSize() >= limit) {
- debugs(33, 5, "Too large " << which);
- parseStatusCode = Http::scHeaderTooLarge;
- parsingStage_ = HTTP_PARSE_DONE;
- return false;
- }
-
- mimeHeaderBlock_ = buf_.consume(mimeHeaderBytes);
- debugs(74, 5, "mime header (0-" << mimeHeaderBytes << ") {" << mimeHeaderBlock_ << "}");
-
} else
debugs(33, 3, "Missing HTTP/1.x identifier");
bool skipLineTerminator(::Parser::Tokenizer &tok) const;
/**
- * Parse scan to find the mime headers block for current message.
+ * Scan to find the mime headers block for current message.
*
- * \retval true if mime block (or a blocks non-existence) has been
- * identified accurately within limit characters.
- * mimeHeaderBlock_ has been updated and buf_ consumed.
- * \retval false an error occured, or no MIME terminator found within limit.
+ * \retval true If mime block (or a blocks non-existence) has been
+ * identified accurately within limit characters.
+ * mimeHeaderBlock_ has been updated and buf_ consumed.
+ *
+ * \retval false An error occured, or no mime terminator found within limit.
*/
- bool findMimeBlock(const char *which, const size_t limit);
+ bool grabMimeBlock(const char *which, const size_t limit);
/// RFC 7230 section 2.6 - 7 magic octets
static const SBuf Http1magic;
// stage 3: locate the mime header block
if (parsingStage_ == HTTP_PARSE_MIME) {
// HTTP/1.x request-line is valid and parsing completed.
- if (!findMimeBlock("Request", Config.maxRequestHeaderSize)) {
+ if (!grabMimeBlock("Request", Config.maxRequestHeaderSize)) {
if (parseStatusCode == Http::scHeaderTooLarge)
parseStatusCode = Http::scRequestHeaderFieldsTooLarge;
return false;
if (parsingStage_ == HTTP_PARSE_FIRST) {
PROF_start(HttpParserParseReplyLine);
- int retcode = parseResponseFirstLine();
+ const int retcode = parseResponseFirstLine();
// first-line (or a look-alike) found successfully.
if (retcode > 0)
// stage 3: locate the mime header block
if (parsingStage_ == HTTP_PARSE_MIME) {
- if (!findMimeBlock("Response", Config.maxReplyHeaderSize))
+ if (!grabMimeBlock("Response", Config.maxReplyHeaderSize))
return false;
}