Skip to content
HttpRespondWithFile

HttpRespondWithFile

Description

Populate response from a file on disk. The file’s bytes are read through response->allocator. Only available when the file feature is enabled.

Success

Returns response with body filled.

Failure

Returns NULL on I/O or allocation failure.

Usage example (Cross-references)

Usage examples (Cross-references)
        // Serving the file must free the old (HTML) body before installing the new.
        HttpResponse *res =
            HttpRespondWithFile(&response, HTTP_RESPONSE_CODE_OK, HTTP_CONTENT_TYPE_TEXT_PLAIN, StrBegin(&path));
        ok = ok && (res != NULL);
        HttpResponse  response = HttpResponseInit(alloc_base);
        HttpResponse *res =
            HttpRespondWithFile(&response, HTTP_RESPONSE_CODE_OK, HTTP_CONTENT_TYPE_TEXT_PLAIN, StrBegin(&path));
    
        ok = ok && (res != NULL) && (response.status_code == HTTP_RESPONSE_CODE_OK) &&
        HttpResponse  response = HttpResponseInit(alloc_base);
        HttpResponse *res =
            HttpRespondWithFile(&response, HTTP_RESPONSE_CODE_OK, HTTP_CONTENT_TYPE_TEXT_PLAIN, StrBegin(&path));
    
        ok = ok && (res != NULL) && (response.status_code == HTTP_RESPONSE_CODE_OK) && (StrLen(&response.body) == 0);
    
        HttpResponse  response = HttpResponseInit(alloc_base);
        HttpResponse *res      = HttpRespondWithFile(
            &response,
            HTTP_RESPONSE_CODE_OK,
Last updated on