feat(registry,daemon): answer HEAD without a body; mark editor generations stale
This commit is contained in:
1 parent
2c4eeba945
commit
3fa7ab086f
8 files changed
+190
-2
No files matched your search
@@ -219,8 +219,17 @@ Void::Result::Result<void, Void::Result::Error> HttpServer::start(const HttpServ
|
||||
}
|
||||
bridged.body = request.body;
|
||||
|
||||
// HEAD is routed exactly like GET; the body is dropped but Content-Length is preserved.
|
||||
const bool head_only = request.method == Void::Net::Method::Head;
|
||||
if (head_only) {
|
||||
bridged.method = "GET";
|
||||
}
|
||||
HttpResponse response = handler(bridged);
|
||||
apply_default_security_headers(response);
|
||||
if (head_only) {
|
||||
response.headers["Content-Length"] = std::to_string(response.body.size());
|
||||
response.body.clear();
|
||||
}
|
||||
Void::Net::ServerResponse net_response;
|
||||
net_response.status = response.status;
|
||||
for (const auto &[name, value] : response.headers) {
|
||||
@@ -333,11 +342,13 @@ void HttpServer::handle_client(int client_fd) {
|
||||
(void)::setsockopt(client_fd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv));
|
||||
(void)::setsockopt(client_fd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv));
|
||||
|
||||
bool suppress_body = false;
|
||||
auto write_response = [&](HttpResponse resp) {
|
||||
if (resp.reason.empty()) {
|
||||
resp.reason = default_reason(resp.status);
|
||||
}
|
||||
apply_default_security_headers(resp);
|
||||
// HEAD keeps the headers of the equivalent GET (including Content-Length) but no body.
|
||||
resp.headers["Content-Length"] = std::to_string(resp.body.size());
|
||||
resp.headers["Connection"] = "close";
|
||||
|
||||
@@ -349,7 +360,9 @@ void HttpServer::handle_client(int client_fd) {
|
||||
wire += "Set-Cookie: " + cookie + "\r\n";
|
||||
}
|
||||
wire += "\r\n";
|
||||
wire += resp.body;
|
||||
if (!suppress_body) {
|
||||
wire += resp.body;
|
||||
}
|
||||
(void)send_all(client_fd, wire);
|
||||
};
|
||||
|
||||
@@ -446,6 +459,12 @@ void HttpServer::handle_client(int client_fd) {
|
||||
req.body.resize(content_length);
|
||||
}
|
||||
|
||||
// HEAD is routed exactly like GET; only the body is suppressed when writing.
|
||||
if (req.method == "HEAD") {
|
||||
suppress_body = true;
|
||||
req.method = "GET";
|
||||
}
|
||||
|
||||
try {
|
||||
write_response(handler_(req));
|
||||
} catch (const std::exception &ex) {
|
||||
|
||||
Reference in new issue
Block a user