Skip to content
Open
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
6 changes: 6 additions & 0 deletions src/internal/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ const requestOptionProperties = [
'secureProtocol',
'servername',
'sessionIdContext',
'headers',
] as const

export interface RetryOptions {
Expand Down Expand Up @@ -481,6 +482,11 @@ export class TypedClient {
// If custom transportAgent was supplied earlier, we'll inject it here
agent: this.transportAgent,
}
if (this.reqOptions.headers) {
for (const [k, v] of Object.entries(this.reqOptions.headers)) {
reqOptions.headers[k.toLowerCase()] = v
}
}

// Verify if virtual host supported.
let virtualHostStyle
Expand Down
34 changes: 34 additions & 0 deletions tests/unit/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/

import http from 'node:http'
import * as Stream from 'node:stream'

import { assert, expect, use } from 'chai'
Expand Down Expand Up @@ -379,6 +380,39 @@ describe('Client', function () {
done()
}
})
it('should send custom headers with requests', async () => {
const headers = { 'X-Test-Header': 'test-value' }

const httpAgent = new http.Agent()

const client = new Minio.Client({
endPoint: 'localhost',
port: 9000,
accessKey: 'accesskey',
secretKey: 'secretkey',
useSSL: false,
transportAgent: httpAgent,
})
client.setRequestOptions({
headers,
})

const promiseConnection = new Promise((resolve, reject) => {
const timeout = setTimeout(() => {
reject(new Error('Timed out'))
}, 5000)
const originalCreateConnection = httpAgent.createConnection
httpAgent.createConnection = (options, callback) => {
clearTimeout(timeout)
resolve(options)
return originalCreateConnection(options, callback)
}
})

await client.listBuckets()
const connectionOptions = await promiseConnection
assert.propertyVal(connectionOptions.headers, 'x-test-header', headers['X-Test-Header'])
})
})
describe('Presigned URL', () => {
describe('presignedUrl', () => {
Expand Down
Loading