openlitespeed icon indicating copy to clipboard operation
openlitespeed copied to clipboard

HEAD response through reverse proxy is missing content-length header

Open jtmcdole opened this issue 6 months ago • 1 comments

Setup

  • Running a gitea server with docker container registry on ubuntu 24
  • Docker Desktop on Windows 11

Expected

Content-Length is passed through as Content-Length: 9757

Observed

Windows 11 + curl (through proxy): missing header

curl -v  -H "accept: application/json" -H "Authorization: Bearer <A TOKEN>" -I "https://a-server/v2/<a-user>/<a-container>/manifests/latest"

...

HTTP/2 200
content-type: application/vnd.docker.distribution.manifest.v2+json
docker-content-digest: sha256:eb4c6be0a6cf50c72a2375f53cd21411d728a925b0ea056f3798606b1297e12c
docker-distribution-api-version: registry/2.0
etag: "sha256:eb4c6be0a6cf50c72a2375f53cd21411d728a925b0ea056f3798606b1297e12c"
date: Thu, 05 Jun 2025 02:56:53 GMT
server: LiteSpeed

On server + curl directly to the gitea instance: header present

curl -v  -H "accept: application/json" -H "Authorization: Bearer <A TOKEN>" -I "localhost:3001/v2/<a-user>/<a-container>/manifests/latest"

...
HTTP/1.1 200 OK
Content-Length: 9757
Content-Type: application/vnd.docker.distribution.manifest.v2+json
Docker-Content-Digest: sha256:eb4c6be0a6cf50c72a2375f53cd21411d728a925b0ea056f3798606b1297e12c
Docker-Distribution-Api-Version: registry/2.0
Etag: "sha256:eb4c6be0a6cf50c72a2375f53cd21411d728a925b0ea056f3798606b1297e12c"
Date: Thu, 05 Jun 2025 02:56:32 GMT

jtmcdole avatar Jun 05 '25 03:06 jtmcdole

https://www.rfc-editor.org/rfc/rfc9110.html#name-content-length

A server MAY send a Content-Length header field in a response to a HEAD request (Section 9.3.2); a server MUST NOT send Content-Length in such a response unless its field value equals the decimal number of octets that would have been sent in the content of a response if the same request had used the GET method.

Digging:

proxconn.cpp: ProxyConn::processResp(),

                if (pReq->getMethod() == HttpMethod::HTTP_HEAD) {
                    HttpResp *pResp = pHEC->getHttpSession()->getResp();
                    pResp->appendContentLenHeader();
                }

Will send the headers. I'll put up a PR.

jtmcdole avatar Jun 06 '25 02:06 jtmcdole