Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

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

Aperta
#884 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

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
Ambito
api, backend

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

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di tus/tus-node-server

Tutte le issue di tus/tus-node-server

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.