Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

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

Đang mở
#884 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
64/100
Loại issue
Tính năng
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
node.js, typescript
Lĩnh vực
api, backend

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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

Ngôn ngữ chính
TypeScript
Star
1.1k
Fork
228
Merge trung bình
4 ngày 3 giờ
Pull request đã merge (30 ngày)
14

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của tus/tus-node-server

Tất cả issue của tus/tus-node-server

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.