Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

Add an onUploadHead hook so servers can attach headers to HEAD responses

Abierto
#884 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
64/100
Tipo de issue
Nueva funcionalidad
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
node.js, typescript
Área
api, backend

Línea de trabajo

The hook option belongs next to onUploadFinish in the server options/types, and the call site is HeadHandler.send in the head handler, after the lock is released and the Upload is loaded. Mirror how PatchHandler and PostHandler merge headers returned by onUploadFinish, then add the returned headers to the HEAD response. Done is a test that sets onUploadHead, performs a HEAD request and asserts the custom header, plus a case where a thrown error reaches onResponseError.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

Initial checklist
  • I understand this is a feature request and questions should be posted in the Community Forum
  • I searched issues and couldn’t find anything (or linked relevant results below)
Problem

onUploadFinish lets a server attach headers to the final PATCH or creation-with-upload POST response. We use it to return the id of the database row created for a completed upload, so clients can reference the stored object without a follow-up list call.

That contract has a hole on resume. When tus-js-client is given an uploadUrl or resumes from a stored fingerprint, it sends HEAD first, and if Upload-Offset already equals Upload-Length it fires onSuccess with the HEAD response as lastResponse and never issues a PATCH.

Any header added in onUploadFinish is therefore missing in exactly the cases where the client lost the final PATCH response or picks the upload up in a later session, and the client can't recover it from the TUS response.

Solution

No existing hook can see the HEAD response: onIncomingRequest runs before the upload is loaded, onResponseError only sees failures, and HeadHandler is not exported.

I would like to propose a hook that mirrors onUploadFinish, limited to headers since a HEAD response carries no body:

onUploadHead?: (
  req: Request,
  upload: Upload
) => Promise<{ headers?: Record<string, string | number> } | void>

HeadHandler.send would call it after the lock is released and the Upload has been loaded, merge any returned headers into the response the same way PatchHandler and PostHandler merge onUploadFinish headers, and let thrown errors propagate to onResponseError.

Passing the Upload lets a server decide from upload.offset === upload.size and upload.id instead of parsing its own response headers. The cost is zero when the option is unset.

Alternatives

Wrapping server.handlers.HEAD.send on the instance or bypassing handle() with handleWeb() plus the srvx/node adapters but hook approach is cleaner.

Related to https://github.com/tus/tusd/issues/1336, which suggests persisting state and replaying. That works in principal but not complete. For example, hook can cover more cases where state changes after finish such as ETag, expiry, permissions, deletes, etc.

Related to https://github.com/tus/tus-node-server/issues/714

Lenguaje dominante
TypeScript
Estrellas
1.1k
Forks
228
Merge medio
4 d 3 h
PR fusionados (30 d)
14

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de tus/tus-node-server

Todos los issues de tus/tus-node-server

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.