Skip to content
HttpResponseInit

HttpResponseInit

Description

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

Success

Returns an HttpResponse with content_type and status_code set to their invalid sentinels, an empty headers Vec that takes ownership of inserted headers by move (freed per-element by HttpResponseDeinit), and an empty body.

Failure

Macro cannot fail (pure literal expansion).

Usage example (Cross-references)

Usage examples (Cross-references)
        Allocator       *alloc_base = ALLOCATOR_OF(&alloc);
    
        HttpResponse response = HttpResponseInit(alloc_base);
        Str          body     = StrInit(alloc_base);
        StrAppendFmt(&body, "<h1>hi</h1>");
        FileClose(&f);
    
        HttpResponse  response = HttpResponseInit(alloc_base);
        HttpResponse *res =
            HttpRespondWithFile(&response, HTTP_RESPONSE_CODE_OK, HTTP_CONTENT_TYPE_TEXT_PLAIN, StrBegin(&path));
        FileClose(&f); // leave it empty
    
        HttpResponse  response = HttpResponseInit(alloc_base);
        HttpResponse *res =
            HttpRespondWithFile(&response, HTTP_RESPONSE_CODE_OK, HTTP_CONTENT_TYPE_TEXT_PLAIN, StrBegin(&path));
        Allocator       *alloc_base = ALLOCATOR_OF(&alloc);
    
        HttpResponse  response = HttpResponseInit(alloc_base);
        HttpResponse *res      = HttpRespondWithFile(
            &response,
        StrAppendFmt(&first, "<h1>first-body-long-enough-to-heap-allocate</h1>");
    
        HttpResponse response = HttpResponseInit(adbg);
        HttpRespondWithHtml(&response, HTTP_RESPONSE_CODE_OK, &first);
        Str first = StrInit(adbg);
        StrAppendFmt(&first, "<h1>old-body-long-enough-to-force-heap-here</h1>");
        HttpResponse response = HttpResponseInit(adbg);
        HttpRespondWithHtml(&response, HTTP_RESPONSE_CODE_OK, &first);
        StrDeinit(&first);
Last updated on