Add an onUploadHead hook so servers can attach headers to HEAD responses
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
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
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de tus/tus-node-server
-
bug
Dificultad 4/5 3-5 días Aptitud para principiantes 42/100
tus/tus-node-server#807 ·
Los mantenedores suelen responder en 1 día
-
Datastore dynamicAbierto
Dificultad 5/5 Más de una semana Aptitud para principiantes 25/100
tus/tus-node-server#737 · 3 comentarios · 1 reacción ·
Los mantenedores suelen responder en 1 día
-
bug
Dificultad 3/5 1-2 días Aptitud para principiantes 45/100
tus/tus-node-server#722 · 3 comentarios · 1 reacción ·
Los mantenedores suelen responder en 1 día
-
Dificultad 4/5 3-5 días Aptitud para principiantes 25/100
tus/tus-node-server#521 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
-
Dificultad 3/5 1-2 días Aptitud para principiantes 35/100
tus/tus-node-server#380 · 7 comentarios ·
Los mantenedores suelen responder en 1 día
Todos los issues de tus/tus-node-server
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
marmelab/react-admin#11431 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
db-ux-design-system/core-web#8655 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
Los mantenedores suelen responder en 1 día
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
stripe/react-stripe-js#728 ·
-
[Upload Grade C dataset] the pop-up changes it's size while uploading the document => Jumping effectAbiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 66/100
epam/statgpt-admin-frontend#305 ·
Los mantenedores suelen responder en 1 día