Skip to content

Commit f465a0f

Browse files
authored
@tus/server: send Tus-Version in OPTIONS (#675)
* @tus/server: send Tus-Version in OPTIONS * Add changeset
1 parent 559ebea commit f465a0f

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

.changeset/brave-doors-ring.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@tus/server": patch
3+
---
4+
5+
Send Tus-Version header in OPTIONS

packages/server/src/handlers/OptionsHandler.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,18 @@ export class OptionsHandler extends BaseHandler {
99
async send(req: http.IncomingMessage, res: http.ServerResponse) {
1010
const maxSize = await this.getConfiguredMaxSize(req, null)
1111

12+
res.setHeader('Tus-Version', '1.0.0')
13+
if (this.store.extensions.length > 0) {
14+
res.setHeader('Tus-Extension', this.store.extensions.join(','))
15+
}
1216
if (maxSize) {
1317
res.setHeader('Tus-Max-Size', maxSize)
1418
}
1519

1620
const allowedHeaders = [...HEADERS, ...(this.options.allowedHeaders ?? [])]
17-
1821
res.setHeader('Access-Control-Allow-Methods', ALLOWED_METHODS)
1922
res.setHeader('Access-Control-Allow-Headers', allowedHeaders.join(', '))
2023
res.setHeader('Access-Control-Max-Age', MAX_AGE)
21-
if (this.store.extensions.length > 0) {
22-
res.setHeader('Tus-Extension', this.store.extensions.join(','))
23-
}
2424

2525
return this.write(res, 204)
2626
}

packages/server/test/OptionsHandler.test.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,14 @@ import httpMocks from 'node-mocks-http'
77

88
import {OptionsHandler} from '../src/handlers/OptionsHandler'
99
import {DataStore, ALLOWED_METHODS, ALLOWED_HEADERS, MAX_AGE} from '@tus/utils'
10-
import {MemoryLocker} from '../src'
10+
import {MemoryLocker, type ServerOptions} from '../src'
1111

1212
describe('OptionsHandler', () => {
13-
const options = {path: '/test/output', locker: new MemoryLocker()}
13+
const options: ServerOptions = {
14+
path: '/test/output',
15+
locker: new MemoryLocker(),
16+
maxSize: 1024,
17+
}
1418
const store = new DataStore()
1519
const handler = new OptionsHandler(store, options)
1620

@@ -27,6 +31,8 @@ describe('OptionsHandler', () => {
2731
'Access-Control-Allow-Methods': ALLOWED_METHODS,
2832
'Access-Control-Allow-Headers': ALLOWED_HEADERS,
2933
'Access-Control-Max-Age': MAX_AGE,
34+
'Tus-Version': '1.0.0',
35+
'Tus-Max-Size': 1024,
3036
}
3137
await handler.send(req, res)
3238
// eslint-disable-next-line guard-for-in

0 commit comments

Comments
 (0)