Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@tus/server: send Tus-Version in OPTIONS #675

Merged
merged 2 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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/brave-doors-ring.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@tus/server": patch
---

Send Tus-Version header in OPTIONS
8 changes: 4 additions & 4 deletions packages/server/src/handlers/OptionsHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ export class OptionsHandler extends BaseHandler {
async send(req: http.IncomingMessage, res: http.ServerResponse) {
const maxSize = await this.getConfiguredMaxSize(req, null)

res.setHeader('Tus-Version', '1.0.0')
if (this.store.extensions.length > 0) {
res.setHeader('Tus-Extension', this.store.extensions.join(','))
}
if (maxSize) {
res.setHeader('Tus-Max-Size', maxSize)
}

const allowedHeaders = [...HEADERS, ...(this.options.allowedHeaders ?? [])]

res.setHeader('Access-Control-Allow-Methods', ALLOWED_METHODS)
res.setHeader('Access-Control-Allow-Headers', allowedHeaders.join(', '))
res.setHeader('Access-Control-Max-Age', MAX_AGE)
if (this.store.extensions.length > 0) {
res.setHeader('Tus-Extension', this.store.extensions.join(','))
}

return this.write(res, 204)
}
Expand Down
10 changes: 8 additions & 2 deletions packages/server/test/OptionsHandler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@ import httpMocks from 'node-mocks-http'

import {OptionsHandler} from '../src/handlers/OptionsHandler'
import {DataStore, ALLOWED_METHODS, ALLOWED_HEADERS, MAX_AGE} from '@tus/utils'
import {MemoryLocker} from '../src'
import {MemoryLocker, type ServerOptions} from '../src'

describe('OptionsHandler', () => {
const options = {path: '/test/output', locker: new MemoryLocker()}
const options: ServerOptions = {
path: '/test/output',
locker: new MemoryLocker(),
maxSize: 1024,
}
const store = new DataStore()
const handler = new OptionsHandler(store, options)

Expand All @@ -27,6 +31,8 @@ describe('OptionsHandler', () => {
'Access-Control-Allow-Methods': ALLOWED_METHODS,
'Access-Control-Allow-Headers': ALLOWED_HEADERS,
'Access-Control-Max-Age': MAX_AGE,
'Tus-Version': '1.0.0',
'Tus-Max-Size': 1024,
}
await handler.send(req, res)
// eslint-disable-next-line guard-for-in
Expand Down
Loading