Skip to content

Commit e38cb91

Browse files
author
Ben Stahl
committed
Ensure all requests have exposed headers
1 parent 7c7c244 commit e38cb91

File tree

4 files changed

+6
-3
lines changed

4 files changed

+6
-3
lines changed

lib/Server.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const HeadHandler = require('./handlers/HeadHandler');
1616
const PatchHandler = require('./handlers/PatchHandler');
1717
const TUS_RESUMABLE = require('./constants').TUS_RESUMABLE;
1818
const RequestValidator = require('./validators/RequestValidator');
19+
const EXPOSED_HEADERS = require('./constants').EXPOSED_HEADERS;
1920

2021
class TusServer {
2122

@@ -99,6 +100,8 @@ class TusServer {
99100
res.setHeader('Access-Control-Allow-Origin', req.headers.origin);
100101
}
101102

103+
res.setHeader('Access-Control-Expose-Headers', EXPOSED_HEADERS);
104+
102105
// Handle POST, HEAD, PATCH, OPTIONS requests
103106
if (this.handlers[req.method]) {
104107
return this.handlers[req.method].send(req, res);

lib/constants.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ module.exports = {
6565
HEADERS_LOWERCASE,
6666
ALLOWED_METHODS: METHODS.join(', '),
6767
ALLOWED_HEADERS: HEADERS.join(', '),
68+
EXPOSED_HEADERS: HEADERS.join(', '),
6869
MAX_AGE: 86400,
6970
ERRORS,
7071
};

lib/handlers/BaseHandler.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
'use strict';
22

33
const DataStore = require('../stores/DataStore');
4-
const EXPOSED_HEADERS = 'Upload-Offset, Location, Upload-Length, Tus-Version, Tus-Resumable, Tus-Max-Size, Tus-Extension, Upload-Metadata';
54

65
class BaseHandler {
76
constructor(store) {
@@ -25,7 +24,6 @@ class BaseHandler {
2524
body = body ? body : '';
2625
headers = Object.assign(headers, {
2726
'Content-Length': body.length,
28-
'Access-Control-Expose-Headers': EXPOSED_HEADERS,
2927
});
3028

3129
res.writeHead(status, headers);

test/Test-OptionsHandler.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const DataStore = require('../lib/stores/DataStore');
88

99
const ALLOWED_METHODS = require('../lib/constants').ALLOWED_METHODS;
1010
const ALLOWED_HEADERS = require('../lib/constants').ALLOWED_HEADERS;
11+
const EXPOSED_HEADERS = require('../lib/constants').EXPOSED_HEADERS;
1112
const MAX_AGE = require('../lib/constants').MAX_AGE;
1213

1314
let hasHeader = (res, header) => {
@@ -31,7 +32,7 @@ describe('OptionsHandler', () => {
3132
let headers = {
3233
'Access-Control-Allow-Methods': ALLOWED_METHODS,
3334
'Access-Control-Allow-Headers': ALLOWED_HEADERS,
34-
'Access-Control-Expose-Headers': ALLOWED_HEADERS,
35+
'Access-Control-Expose-Headers': EXPOSED_HEADERS,
3536
'Access-Control-Max-Age': MAX_AGE,
3637
};
3738
handler.send(req, res);

0 commit comments

Comments
 (0)