]> git.ipfire.org Git - thirdparty/public-inbox.git/commit
http: response_write handles HEAD responses
authorEric Wong <e@80x24.org>
Sat, 14 Jun 2025 09:26:32 +0000 (09:26 +0000)
committerEric Wong <e@80x24.org>
Mon, 16 Jun 2025 20:10:31 +0000 (20:10 +0000)
commiteaf4c5d1e562df26be51449378f014eb4d1c1993
treef1ddafcdf658da4cef56203bbeaf47915118a0ab
parent8960831a4320d212795a2a0e67bdeae665fcd434
http: response_write handles HEAD responses

Since we special-case MSG_MORE for HEAD responses already,
our HTTP server code now strips response bodies from HEAD
requests unconditionally, allowing .psgi files to omit the
`enable "Head"' directive.

Proper placement of `Head' (Plack::Middleware::Head) in the
middleware stack can be confusing and tedious since it needs to
be after things like AccessLog::Timed which need to wrap the
response body with an object which responds to ->close.

Furthermore, removal of the response body in HEAD requests is
required in all relevant HTTP RFCs (2616, 7231 and 9110) and
doing HEAD response handling in the server itself avoids the
possibility of misconfiguration by the .psgi file maintainer.

The main reason in this rewrite was the desire to easily
configure per-map AccessLog::Timed destination log files.
Correct configuration without this patch would require putting
an `enable "Head"' directive inside every Plack::Builder::map
block after `enable "AccessLog::Timed"'.

In other words, the .psgi file having a single `enable "Head"'
encompassing everything:

builder {
enable 'Head';
map 'http://example.com/' => builder {
enable 'AccessLog::Timed', @a_params;
};
map 'http://example.net/' => builder {
enable 'AccessLog::Timed', @b_params;
};
};

...would not log HEAD requests properly, and the correct alternative:

builder {
map 'http://example.com/' => builder {
enable 'AccessLog::Timed', @a_params;
enable 'Head';
};
map 'http://example.net/' => {
enable 'AccessLog::Timed', @b_params;
enable 'Head';
};
};

...would be more tedious with many `map' directives.  With this
change, all `enable "Head"' directives can simply be omitted for
public-inbox-{netd,httpd} users.
lib/PublicInbox/HTTP.pm
lib/PublicInbox/HTTPD.pm