Skip to content

Commit

Permalink
@tus/server: send Tus-Version in OPTIONS (#675)
Browse files Browse the repository at this point in the history
* @tus/server: send Tus-Version in OPTIONS

* Add changeset
  • Loading branch information
Murderlon authored Nov 19, 2024
1 parent 559ebea commit f465a0f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
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

0 comments on commit f465a0f

Please sign in to comment.