Add an onUploadHead hook so servers can attach headers to HEAD responses
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 64/100
- Tipo di issue
- Funzionalità
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Attiva
- Stack tecnologico
- node.js, typescript
Direzione di ricerca
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.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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
- Lingua principale
- TypeScript
- Stelle
- 1.1k
- Fork
- 228
- Merge medio
- 4g 3h
- PR unite (30g)
- 14
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di tus/tus-node-server
-
bug
Difficoltà 4/5 3-5 giorni Idoneità per principianti 42/100
tus/tus-node-server#807 ·
I maintainer di solito rispondono entro 1 giorno
-
Datastore dynamicAperta
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
tus/tus-node-server#737 · 3 commenti · 1 reazione ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 3/5 1-2 giorni Idoneità per principianti 45/100
tus/tus-node-server#722 · 3 commenti · 1 reazione ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 25/100
tus/tus-node-server#521 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 35/100
tus/tus-node-server#380 · 7 commenti ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di tus/tus-node-server
Issue simili
-
area: triage theme: undefined
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
jhipster/generator-jhipster#35895 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
paperclipai/paperclip#18396 ·
I maintainer di solito rispondono entro 1 giorno
-
community first-timers-only good first issue hacktoberfest help wanted low hanging fruit up-for-grabs
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 82/100
lingdojo/kana-dojo#33380 · 1 commento · 5 reazioni ·
I maintainer di solito rispondono entro 1 giorno
-
chore other
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
alastair-smith/card-games#342 ·
I maintainer di solito rispondono entro 1 giorno