HTTP Header End Detector (common/HttpHeaderEndDetector.h)

WSL · src/windows/common/HttpHeaderEndDetector.h · c · MIT
infra, integration, dev-tools, lang:cpp, tag:knn-classified

Identifies the end of an HTTP header section by monitoring for the CRLF sequence. Use this in network stream processing to correctly delimit HTTP messages.

// Source: https://github.com/microsoft/WSL | License: MIT | Copyright Microsoft Corporation
// Provided via justclaw.it.com; keep this notice with the code.
// Copyright (C) Microsoft Corporation. All rights reserved.

#pragma once

#include <algorithm>
#include <deque>
#include <string_view>

namespace wsl::windows::common {

// Detects the end-of-header marker ("\r\n\r\n") in an HTTP message
class HttpHeaderEndDetector
{
public:
    // Returns true once the full "\r\n\r\n" terminator has been consumed.
    bool Consume(char byte)
    {
        if (m_done)
        {
            return true;
        }

        m_last4Bytes.push_back(byte);
        if (m_last4Bytes.size() > 4)
        {
            m_last4Bytes.pop_front();
        }

        static constexpr std::string_view c_terminator 

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key