HttpResponseSerialize
Description
Serialize response to its on-wire HTTP/1.1 form. Caller owns the returned Str and must deinit it. The result is exactly the bytes that should land on the transport (sockets / files / etc.) — no transport call is made.
Success
Returns a populated Str.
Failure
Returns an empty Str and logs the failing condition (unknown response code, unknown content type, etc.).
Usage example (Cross-references)
Usage examples (Cross-references)
- In
Http.c:44:
StrDeinit(&body);
Str wire = HttpResponseSerialize(&response, alloc_base);
// Spot-check the wire format:
- In
Http.c:421:
#endif
Str HttpResponseSerialize(const HttpResponse *response, Allocator *alloc) {
Str out = StrInit(alloc);- In
Http.c:425:
if (!response) {
LOG_ERROR("HttpResponseSerialize: response is NULL");
return out;
}- In
Http.c:431:
const char *response_code = HttpResponseCodeToZstr(response->status_code);
if (!response_code) {
LOG_ERROR("HttpResponseSerialize: invalid/unknown response code {}", (u32)response->status_code);
return out;
}- In
Http.c:436:
const char *content_type = HttpContentTypeToZstr(response->content_type);
if (!content_type) {
LOG_ERROR("HttpResponseSerialize: invalid/unknown content type {}", (u32)response->content_type);
return out;
}- In
Http.c:459:
u64 head = out.length;
if (!StrReserve(&out, head + response->body.length + 1)) {
LOG_ERROR("HttpResponseSerialize: failed to reserve buffer");
StrDeinit(&out);
return StrInit(alloc);
Last updated on