Responding to HEAD Requests

The docs contains different ways to write custom HTTP Headers in a Service, e.g. you could also write custom HTTP Headers using a Request Filter.

I’ve tracked down the issue to a HttpResult with null response which is resolved in this commit. This fix is available from v5.0.0 that’s now available on MyGet. Please note v5 changes before upgrading.

The way I’d handle a HEAD request is to use a separate method for the Service and write the HTTP Headers directly to the response. You’ll need to use the custom SetContentLength() API to set the Content-Length, e.g:

public void Head(LegacyContentFileRequest request)
{
    Response.AddHeader("Last-Modified", file.LastWriteTimeUtc.ToString("r"));
    Response.ContentType = "video/mp4";
    Response.SetContentLength(file.Length);
    Response.EndRequest();
}
1 Like