@nxtedition/nxt-undici 6.0.23 → 6.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js CHANGED
@@ -59,6 +59,7 @@ function wrapDispatch(dispatcher) {
59
59
  if (wrappedDispatcher == null) {
60
60
  wrappedDispatcher = compose(
61
61
  dispatcher,
62
+ interceptors.log({ bindings: { intercept: 'upstream' } }),
62
63
  interceptors.responseError(),
63
64
  interceptors.requestBodyFactory(),
64
65
  interceptors.dns(),
@@ -69,7 +70,7 @@ function wrapDispatch(dispatcher) {
69
70
  interceptors.proxy(),
70
71
  interceptors.cache(),
71
72
  interceptors.redirect(),
72
- interceptors.log(),
73
+ interceptors.log({ bindings: { intercept: 'downstream' } }),
73
74
  (dispatch) => (opts, handler) => {
74
75
  const headers = parseHeaders(opts.headers)
75
76
 
@@ -55,11 +55,17 @@ class CacheHandler extends DecoratorHandler {
55
55
  return super.onHeaders(statusCode, headers, resume)
56
56
  }
57
57
 
58
+ if (cacheControlDirectives['must-understand']) {
59
+ // Do nothing. We only cache responses that we understand...
60
+ }
61
+
62
+ if (cacheControlDirectives['no-transform']) {
63
+ // Do nothing. We don't transform responses...
64
+ }
65
+
58
66
  if (
59
- cacheControlDirectives['no-transform'] ||
60
67
  cacheControlDirectives['must-revalidate'] ||
61
68
  cacheControlDirectives['proxy-revalidate'] ||
62
- cacheControlDirectives['must-understand'] ||
63
69
  cacheControlDirectives['stale-while-revalidate'] ||
64
70
  cacheControlDirectives['stale-if-error'] ||
65
71
  cacheControlDirectives['no-cache']
@@ -142,12 +148,15 @@ export default () => (dispatch) => (opts, handler) => {
142
148
 
143
149
  const cacheControlDirectives = parseCacheControl(opts?.headers['cache-control']) ?? {}
144
150
 
151
+ if (cacheControlDirectives['no-transform']) {
152
+ // Do nothing. We don't transform requests...
153
+ }
154
+
145
155
  if (
146
156
  cacheControlDirectives['max-age'] ||
147
157
  cacheControlDirectives['max-stale'] ||
148
158
  cacheControlDirectives['min-fresh'] ||
149
159
  cacheControlDirectives['no-cache'] ||
150
- cacheControlDirectives['no-transform'] ||
151
160
  cacheControlDirectives['stale-if-error']
152
161
  ) {
153
162
  // TODO (fix): Support all cache control directives...
@@ -19,12 +19,16 @@ class Handler extends DecoratorHandler {
19
19
  #statusCode
20
20
  #headers
21
21
 
22
- constructor(opts, { handler }) {
22
+ constructor(logOpts, opts, { handler }) {
23
23
  super(handler)
24
24
 
25
25
  this.#opts = opts
26
26
  this.#logger = opts.logger.child({ ureq: opts })
27
27
 
28
+ if (logOpts?.bindings) {
29
+ this.#logger = this.#logger.child(logOpts?.bindings)
30
+ }
31
+
28
32
  this.#created = performance.now()
29
33
  }
30
34
 
@@ -128,5 +132,5 @@ class Handler extends DecoratorHandler {
128
132
  }
129
133
  }
130
134
 
131
- export default () => (dispatch) => (opts, handler) =>
132
- opts.logger ? dispatch(opts, new Handler(opts, { handler })) : dispatch(opts, handler)
135
+ export default (logOpts) => (dispatch) => (opts, handler) =>
136
+ opts.logger ? dispatch(opts, new Handler(logOpts, opts, { handler })) : dispatch(opts, handler)
@@ -178,7 +178,7 @@ class Handler extends DecoratorHandler {
178
178
  this.#onError(this.#error)
179
179
  } else if (!this.#headersSent) {
180
180
  this.#retryCount++
181
- this.#opts.logger?.debug({ retryCount: this.#retryCount }, 'retry response headers')
181
+ this.#opts.logger?.debug({ err, retryCount: this.#retryCount }, 'retry response headers')
182
182
  this.#dispatch(this.#opts, this)
183
183
  } else {
184
184
  assert(Number.isFinite(this.#pos))
@@ -196,7 +196,7 @@ class Handler extends DecoratorHandler {
196
196
  }
197
197
 
198
198
  this.#retryCount++
199
- this.#opts.logger?.debug({ retryCount: this.#retryCount }, 'retry response body')
199
+ this.#opts.logger?.debug({ err, retryCount: this.#retryCount }, 'retry response body')
200
200
  this.#dispatch(this.#opts, this)
201
201
  }
202
202
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/nxt-undici",
3
- "version": "6.0.23",
3
+ "version": "6.1.0",
4
4
  "license": "MIT",
5
5
  "author": "Robert Nagy <robert.nagy@boffins.se>",
6
6
  "main": "lib/index.js",