Skip to content

Commit

Permalink
Merge branch 'main' into flakey5/20241018/now-absolute
Browse files Browse the repository at this point in the history
  • Loading branch information
metcoder95 authored Oct 24, 2024
2 parents de258ea + 7bb663e commit 152c924
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 252 deletions.
2 changes: 1 addition & 1 deletion build/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:22-alpine3.19@sha256:83b4d7bcfc3d4a40faac3e73a59bc3b0f4b3cc72b9a19e036d340746ebfeaecb
FROM node:22-alpine3.19@sha256:f1b43157ce277feaed97088f4d1bbf6b209148d49d98cea592e0af6637657baf

ARG UID=1000
ARG GID=1000
Expand Down
2 changes: 1 addition & 1 deletion lib/api/api-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class RequestHandler extends AsyncResource {
this.removeAbortListener = util.addAbortListener(signal, () => {
this.reason = signal.reason ?? new RequestAbortedError()
if (this.res) {
util.destroy(this.res, this.reason)
util.destroy(this.res.on('error', noop), this.reason)
} else if (this.abort) {
this.abort(this.reason)
}
Expand Down
10 changes: 2 additions & 8 deletions lib/handler/cache-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@ class CacheHandler extends DecoratorHandler {
*/
#store

/**
* @type {import('../../types/cache-interceptor.d.ts').default.CacheMethods}
*/
#methods

/**
* @type {import('../../types/dispatcher.d.ts').default.RequestOptions}
*/
Expand All @@ -43,14 +38,13 @@ class CacheHandler extends DecoratorHandler {
* @param {import('../../types/dispatcher.d.ts').default.DispatchHandlers} handler
*/
constructor (opts, requestOptions, handler) {
const { store, methods } = opts
const { store } = opts

super(handler)

this.#store = store
this.#requestOptions = requestOptions
this.#handler = handler
this.#methods = methods
}

/**
Expand All @@ -76,7 +70,7 @@ class CacheHandler extends DecoratorHandler {
)

if (
!this.#methods.includes(this.#requestOptions.method) &&
!util.safeHTTPMethods.includes(this.#requestOptions.method) &&
statusCode >= 200 &&
statusCode <= 399
) {
Expand Down
4 changes: 3 additions & 1 deletion lib/interceptor/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ module.exports = (opts = {}) => {
methods
}

const safeMethodsToNotCache = util.safeHTTPMethods.filter(method => methods.includes(method) === false)

return dispatch => {
return (opts, handler) => {
if (!opts.origin || !methods.includes(opts.method)) {
if (!opts.origin || safeMethodsToNotCache.includes(opts.method)) {
// Not a method we want to cache or we don't have the origin, skip
return dispatch(opts, handler)
}
Expand Down
240 changes: 0 additions & 240 deletions test/cache-interceptor/interceptor.js

This file was deleted.

36 changes: 36 additions & 0 deletions test/client-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -1337,3 +1337,39 @@ test('request multibyte text with setEncoding', async (t) => {

await t.completed
})

test('#3736 - Aborted Response (without consuming body)', async (t) => {
const plan = tspl(t, { plan: 1 })

const controller = new AbortController()
const server = createServer((req, res) => {
setTimeout(() => {
res.writeHead(200, 'ok', {
'content-type': 'text/plain'
})
res.write('hello from server')
res.end()
}, 100)
})

server.listen(0)

await EE.once(server, 'listening')
const client = new Client(`http://localhost:${server.address().port}`)

after(server.close.bind(server))
after(client.destroy.bind(client))

const { signal } = controller
const promise = client.request({
path: '/',
method: 'GET',
signal
})

controller.abort()

await plan.rejects(promise, { message: 'This operation was aborted' })

await plan.completed
})
Loading

0 comments on commit 152c924

Please sign in to comment.