From 5d47b2d12caba33793a078d2eafae6ae3d2ad921 Mon Sep 17 00:00:00 2001 From: Xavier Del Campo Romero Date: Sun, 10 Nov 2024 23:56:57 +0100 Subject: Implement HTTP byte serving This commit allows the HTTP server to return partial content to clients, rather than returning the whole resource. This can be particularly useful for applications such as audio/video playback or showing large PDF files. Notes: - Applications must not care about partial contents i.e., if a valid user request was made, applications must still return HTTP status 200 ("OK"), as usual. The HTTP server will then translate the status code to 206 ("Partial Content") if required. --- include/libweb/http.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'include') diff --git a/include/libweb/http.h b/include/libweb/http.h index 4e80570..736a561 100644 --- a/include/libweb/http.h +++ b/include/libweb/http.h @@ -49,6 +49,21 @@ struct http_payload { const char *tmpname; } put; + + struct http_get + { + struct http_get_range + { + enum + { + HTTP_GET_RANGE_NONE, + HTTP_GET_RANGE_START = 1 << 0, + HTTP_GET_RANGE_END = 1 << 1 + } state; + + unsigned long long start, end; + } range; + } get; } u; const struct http_arg @@ -64,6 +79,7 @@ struct http_payload #define HTTP_STATUSES \ X(CONTINUE, "Continue", 100) \ X(OK, "OK", 200) \ + X(PARTIAL_CONTENT, "Partial Content", 206) \ X(SEE_OTHER, "See other", 303) \ X(BAD_REQUEST, "Bad Request", 400) \ X(UNAUTHORIZED, "Unauthorized", 401) \ -- cgit v1.2.3