Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/completed-upload-expiration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@tus/server": patch
---

Allow HEAD requests for completed uploads after their original expiration deadline. Unfinished uploads continue to return 410 Gone after expiration.
1 change: 1 addition & 0 deletions packages/server/src/handlers/HeadHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export class HeadHandler extends BaseHandler {
// be used if the Server is keeping track of expired uploads.
const now = new Date()
if (
file.offset !== file.size &&
Comment thread
devin-ai-integration[bot] marked this conversation as resolved.
Resolved
Comment thread
devin-ai-integration[bot] marked this conversation as resolved.
Resolved
this.store.hasExtension('expiration') &&
this.store.getExpiration() > 0 &&
file.creation_date &&
Expand Down
27 changes: 27 additions & 0 deletions packages/server/src/test/HeadHandler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,31 @@ describe('HeadHandler', () => {
const res = await handler.send(req, context)
assert.equal(res.headers.has('Upload-Metadata'), false)
})

describe('expiration', () => {
const creation_date = new Date(Date.now() - 120_000).toISOString()

before(() => {
fake_store.hasExtension.withArgs('expiration').returns(true)
fake_store.getExpiration.returns(60_000)
})

it('should resolve completed uploads after expiration', async () => {
fake_store.getUpload.resolves(
new Upload({id: '1234', offset: 4, size: 4, creation_date})
)
const res = await handler.send(req, context)
assert.equal(res.status, 200)
assert.equal(res.headers.get('Upload-Offset'), '4')
})

for (const size of [4, undefined]) {
it(`should 410 unfinished uploads after expiration (size: ${size})`, () => {
fake_store.getUpload.resolves(
new Upload({id: '1234', offset: 0, size, creation_date})
)
return assert.rejects(() => handler.send(req, context), {status_code: 410})
})
}
})
})