diff --git a/lib/upload.js b/lib/upload.js index 5023fb8d..edc9a82b 100644 --- a/lib/upload.js +++ b/lib/upload.js @@ -155,23 +155,6 @@ class BaseUpload { }) } - static convertToStringHeaderValue(val) { - if (val === null || val === undefined) { - return '' - } else if (Array.isArray(val)) { - return val.join(',') - } else if ( - typeof val === 'string' || - typeof val === 'number' || - typeof val === 'boolean' || - typeof val === 'symbol' - ) { - return val.toString() - } else if (typeof val === 'object') { - return Object.values(val).join(',') - } - } - findPreviousUploads() { return this.options .fingerprint(this.file, this.options) @@ -395,7 +378,7 @@ class BaseUpload { // Add metadata if values have been added const metadata = encodeMetadata(this.options.metadata) if (metadata !== '') { - req.setHeader('Upload-Metadata', BaseUpload.convertToStringHeaderValue(metadata)) + req.setHeader('Upload-Metadata', metadata) } return this._sendRequest(req, null) @@ -598,13 +581,13 @@ class BaseUpload { if (this.options.uploadLengthDeferred) { req.setHeader('Upload-Defer-Length', '1') } else { - req.setHeader('Upload-Length', BaseUpload.convertToStringHeaderValue(this._size)) + req.setHeader('Upload-Length',`${this._size}`)) } // Add metadata if values have been added const metadata = encodeMetadata(this.options.metadata) if (metadata !== '') { - req.setHeader('Upload-Metadata', BaseUpload.convertToStringHeaderValue(metadata)) + req.setHeader('Upload-Metadata', metadata) } let promise @@ -771,7 +754,7 @@ class BaseUpload { req = this._openRequest('PATCH', this.url) } - req.setHeader('Upload-Offset', BaseUpload.convertToStringHeaderValue(this._offset)) + req.setHeader('Upload-Offset', `${this._offset}`) const promise = this._addChunkToRequest(req) promise @@ -827,7 +810,7 @@ class BaseUpload { // upload size and can tell the tus server. if (this.options.uploadLengthDeferred && done) { this._size = this._offset + valueSize - req.setHeader('Upload-Length', BaseUpload.convertToStringHeaderValue(this._size)) + req.setHeader('Upload-Length', `${this._size}`) } // The specified uploadSize might not match the actual amount of data that a source @@ -990,7 +973,7 @@ function openRequest(method, url, options) { const headers = options.headers || {} for (const [name, value] of Object.entries(headers)) { - req.setHeader(name, BaseUpload.convertToStringHeaderValue(value)) + req.setHeader(name, value) } if (options.addRequestId) {