Skip to content

HttpHeader

Description

A single Key: Value HTTP header. key and value are both Str objects that own their backing storage through their stored allocator. When kept inside a Vec(HttpHeader), the vec’s deep-copy callbacks (http_header_init_copy / http_header_deinit) handle duplication and cleanup automatically.

Usage example (Cross-references)

Usage examples (Cross-references)
                  (ZstrCompare(next, "body-bytes") == 0);
    
        HttpHeader *host = HttpHeadersFind(&req.headers, "Host");
        ok               = ok && host && ZstrCompare(host->value.data, "example.com") == 0;
    // ---------------------------------------------------------------------------
    
    void HttpHeaderDeinit(HttpHeader *header) {
        if (!header) {
            LOG_FATAL("invalid arguments");
            return;
        }
        HttpHeader *header = (HttpHeader *)header_ptr;
        StrDeinit(&header->key);
        StrDeinit(&header->value);
            LOG_FATAL("invalid arguments");
        }
        HttpHeader       *dst = (HttpHeader *)dst_ptr;
        const HttpHeader *src = (const HttpHeader *)src_ptr;
        }
        HttpHeader       *dst = (HttpHeader *)dst_ptr;
        const HttpHeader *src = (const HttpHeader *)src_ptr;
    
        dst->key   = StrInit((Allocator *)alloc);
    }
    
    HttpHeader *HttpHeadersFind(HttpHeaders *headers, const char *key) {
        if (!headers || !key) {
            LOG_ERROR("invalid arguments");
            }
    
            HttpHeader hh = HttpHeaderInit(alloc);
            StrReadFmt(cursor, "{}: {}\r\n", hh.key, hh.value);
            if (cursor == line_start) {
        Str key;
        Str value;
    } HttpHeader;
    
    ///
    #define HttpHeaderInit(...)         MISRA_OVERLOAD(HttpHeaderInit, __VA_ARGS__)
    #define HttpHeaderInit_0()          HttpHeaderInit_1(MisraScope)
    #define HttpHeaderInit_1(alloc_ptr) ((HttpHeader) {.key = StrInit_1(alloc_ptr), .value = StrInit_1(alloc_ptr)})
    
    typedef Vec(HttpHeader) HttpHeaders;
    #define HttpHeaderInit_1(alloc_ptr) ((HttpHeader) {.key = StrInit_1(alloc_ptr), .value = StrInit_1(alloc_ptr)})
    
    typedef Vec(HttpHeader) HttpHeaders;
    
    ///
    /// `header->key` and `header->value`, then zeros the struct.
    ///
    void HttpHeaderDeinit(HttpHeader *header);
    
    ///
    /// FAILURE : NULL if no header matches.
    ///
    HttpHeader *HttpHeadersFind(HttpHeaders *headers, const char *key);
    
    typedef enum HttpResponseCode {
Last updated on