Skip to content

HttpRequest

Description

Parsed HTTP request. Carries the allocator that owns url and headers; all sub-allocations route through the same handle.

Usage example (Cross-references)

Usage examples (Cross-references)
        Str               url;
        HttpHeaders       headers;
    } HttpRequest;
    
    ///
    #define HttpRequestInit_0()  HttpRequestInit_1(MisraScope)
    #define HttpRequestInit_1(alloc_ptr)                                                                                   \
        ((HttpRequest) {.allocator = ALLOCATOR_OF(alloc_ptr),                                                              \
                        .method    = HTTP_REQUEST_METHOD_UNKNOWN,                                                          \
                        .url       = StrInit_1(alloc_ptr),                                                                 \
    /// TAGS: Http, Request, Deinit, Init
    ///
    void HttpRequestDeinit(HttpRequest *req);
    
    ///
    }
    
    Zstr http_request_parse_zstr(HttpRequest *req, Zstr in) {
        if (!req || !req->allocator || !in) {
            LOG_FATAL("invalid arguments");
    }
    
    Zstr http_request_parse_str(HttpRequest *req, const Str *in) {
        if (!req || !in) {
            LOG_FATAL("invalid arguments");
    }
    
    void HttpRequestDeinit(HttpRequest *req) {
        if (!req) {
            LOG_FATAL("invalid arguments");
            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