Skip to content
HttpRespondWithHtml

HttpRespondWithHtml

Description

Populate response as an HTML reply. The body is a deep copy of html allocated through response->allocator.

Success

Returns response with status_code, content_type, and body updated.

Failure

Does not return - aborts on NULL arguments.

Usage example (Cross-references)

Usage examples (Cross-references)
    // ---------------------------------------------------------------------------
    
    HttpResponse *HttpRespondWithHtml(HttpResponse *response, HttpResponseCode status, const Str *html) {
        if (!response || !response->allocator || !html) {
            LOG_FATAL("invalid arguments");
    
        HttpResponse response = HttpResponseInit(adbg);
        HttpRespondWithHtml(&response, HTTP_RESPONSE_CODE_OK, &first);
    
        Str second = StrInit(adbg);
        StrAppendFmt(&second, "<h1>second-body-also-long-enough-to-heap</h1>");
        // Second call must free the first body before installing the second.
        HttpRespondWithHtml(&response, HTTP_RESPONSE_CODE_OK, &second);
    
        StrDeinit(&first);
        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);
        Str          body     = StrInit(alloc_base);
        StrAppendFmt(&body, "<h1>hi</h1>");
        HttpRespondWithHtml(&response, HTTP_RESPONSE_CODE_OK, &body);
        StrDeinit(&body);
Last updated on