The http spec says about the HEAD request:
The HEAD method is identical to GET except that the server MUST NOT return a message-body in the response. The metainformation contained in the HTTP headers in response to a HEAD request SHOULD be identical to the information sent in response to a GET request.
And also:
The Content-Length entity-header field indicates the size of the entity-body, in decimal number of OCTETs, sent to the recipient or, in the case of the HEAD method, the size of the entity-body that would have been sent had the request been a GET.
So if the requested resource is dynamically generated, for the HEAD
request, will the resource ALSO be generated? Should there a Content-Length
header or Transfer-Encoding: chunked
header?
(I feel this is about how to implement the HTTP protocol.)
ADD 1
I don't see the spec mandates whether to
send Content-Length header or how to
send it for a dynamically generated resource. Such dynamic resource will be sent with chunked transfer encoding and there'll be no Content-Length
header if accessed with a GET
method. So, if HEAD response should mimic GET response, the Contnet-Length should not be sent either.
a) That's not the HTTP spec. It is the W3C copy of the now obsolete RFC 2616, dated 1999.
b) For the current spec, see https://greenbytes.de/tech/webdav/rfc7231.html#HEAD
To answer your question: if you don't know the payload size without actually generating it, not sending Content-Length in the HEAD response is ok.