Skip to content
HttpRequestInit

HttpRequestInit

Description

Initialize an empty HttpRequest. Inside a Scope the allocator argument may be omitted (uses MisraScope).

Success

Returns an HttpRequest with method set to HTTP_REQUEST_METHOD_UNKNOWN, empty url, and an empty headers Vec that takes ownership of inserted headers by move (freed per-element by HttpRequestDeinit).

Failure

Macro cannot fail (pure literal expansion).

Usage example (Cross-references)

Usage examples (Cross-references)
            StrPushBackMany(&raw, prefix_bytes);
    
            HttpRequest req = HttpRequestInit(scope);
            Zstr        end = HttpRequestParse(&req, (Zstr)StrBegin(&raw));
            if (end == StrBegin(&raw)) {
            "\r\n";
    
        HttpRequest req  = HttpRequestInit(adbg);
        Zstr        next = HttpRequestParse(&req, raw);
        bool        ok   = (next != raw) && (StrLen(&req.url) > 0);
            "body-bytes";
    
        HttpRequest req  = HttpRequestInit(alloc_base);
        Zstr        next = HttpRequestParse(&req, raw);
        bool ok = true;
        for (u64 i = 0; i < sizeof(cases) / sizeof(cases[0]); i++) {
            HttpRequest req  = HttpRequestInit(alloc_base);
            Zstr        next = HttpRequestParse(&req, cases[i].raw);
            ok               = ok && (next != cases[i].raw) && (req.method == cases[i].method);
        bool ok = true;
        for (u64 i = 0; i < sizeof(cases) / sizeof(cases[0]); i++) {
            HttpRequest req  = HttpRequestInit(alloc_base);
            Zstr        next = HttpRequestParse(&req, cases[i]);
            ok               = ok && (next == cases[i]) && (req.method == HTTP_REQUEST_METHOD_UNKNOWN);
        bool ok = true;
        for (u64 i = 0; i < sizeof(cases) / sizeof(cases[0]); i++) {
            HttpRequest req  = HttpRequestInit(alloc_base);
            Zstr        next = HttpRequestParse(&req, cases[i]);
            ok               = ok && (next == cases[i]) && (req.method == HTTP_REQUEST_METHOD_UNKNOWN);
        StrAppendFmt(&raw, "\r\n");
    
        HttpRequest req  = HttpRequestInit(alloc_base);
        Zstr        in   = StrBegin(&raw);
        Zstr        next = HttpRequestParse(&req, in);
        StrAppendFmt(&raw, "\r\n");
    
        HttpRequest req  = HttpRequestInit(alloc_base);
        Zstr        in   = StrBegin(&raw);
        Zstr        next = HttpRequestParse(&req, in);
Last updated on