Skip to content

Commit 37401c8

Browse files
committed
fix: id fallback from headers
1 parent 3359aad commit 37401c8

File tree

3 files changed

+6
-11
lines changed

3 files changed

+6
-11
lines changed

lib/index.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,12 @@ function wrapDispatch(dispatcher) {
6969
(dispatch) => (opts, handler) => {
7070
const headers = parseHeaders(opts.headers)
7171

72-
const userAgent = opts.userAgent ?? globalThis.userAgent
73-
if (userAgent && headers?.['user-agent'] !== userAgent) {
74-
headers['user-agent'] = userAgent
75-
}
72+
// TODO (fix): Move to interceptor?
73+
headers['user-agent'] ??= opts.userAgent ?? globalThis.userAgent
7674

7775
return dispatch(
7876
{
79-
id: opts.id,
77+
id: opts.id ?? headers['request-id'],
8078
origin: opts.origin,
8179
path: opts.path,
8280
method: opts.method ?? (opts.body ? 'POST' : 'GET'),

lib/interceptor/response-verify.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ import crypto from 'node:crypto'
22
import assert from 'node:assert'
33
import { DecoratorHandler, parseHeaders } from '../utils.js'
44

5-
const DEFAULT_OPTS = { hash: null }
6-
75
class Handler extends DecoratorHandler {
86
#verifyOpts
97
#contentMD5
@@ -14,8 +12,7 @@ class Handler extends DecoratorHandler {
1412
constructor(opts, { handler }) {
1513
super(handler)
1614

17-
this.#verifyOpts =
18-
opts.verify === true ? { hash: true, size: true } : (opts.verify ?? DEFAULT_OPTS)
15+
this.#verifyOpts = opts.verify === true ? { hash: true, size: true } : opts.verify
1916
}
2017

2118
onConnect(abort) {
@@ -31,7 +28,7 @@ class Handler extends DecoratorHandler {
3128

3229
onHeaders(statusCode, rawHeaders, resume, statusMessage, headers = parseHeaders(rawHeaders)) {
3330
this.#contentMD5 = this.#verifyOpts.hash ? headers['content-md5'] : null
34-
this.#contentLength = this.#verifyOpts.hash ? headers['content-length'] : null
31+
this.#contentLength = this.#verifyOpts.size ? headers['content-length'] : null
3532
this.#hasher = this.#contentMD5 != null ? crypto.createHash('md5') : null
3633

3734
return super.onHeaders(statusCode, null, resume, null, headers)

test/response-content.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ test('put & get', (t) => {
8383
verify: true,
8484
method: 'PUT',
8585
body: async function () {
86-
const { body } = await request(`http://0.0.0.0:${port}`)
86+
const { body } = await request(`http://0.0.0.0:${port}`, { verify: true })
8787
return body
8888
},
8989
})

0 commit comments

Comments
 (0)