Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
ronag committed Nov 6, 2024
1 parent 6f76cce commit 3eab995
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions lib/handler/cache-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ const {
parseVaryHeader
} = require('../util/cache')

function noop () {}

/**
* Writes a response to a CacheStore and then passes it on to the next handler
*/
Expand Down Expand Up @@ -77,15 +79,11 @@ class CacheHandler extends DecoratorHandler {
// Try/catch for if it's synchronous
try {
const result = this.#store.deleteByOrigin(this.#requestOptions.origin)
if (
result &&
typeof result.catch === 'function' &&
typeof this.#handler.onError === 'function'
) {
if (typeof result?.catch === 'function') {
// Fail silently
result.catch(_ => {})
result.catch(noop)
}
} catch (err) {
} catch {
// Fail silently
}

Expand Down Expand Up @@ -139,6 +137,7 @@ class CacheHandler extends DecoratorHandler {
if (this.#writeStream) {
this.#writeStream.on('drain', resume)
this.#writeStream.on('error', () => {
// TODO (fix): Make this error somehow observable?
this.#writeStream = undefined
resume()
})
Expand All @@ -148,6 +147,7 @@ class CacheHandler extends DecoratorHandler {
if (typeof this.#handler.onHeaders === 'function') {
return downstreamOnHeaders()
}

return false
}

Expand Down Expand Up @@ -178,10 +178,7 @@ class CacheHandler extends DecoratorHandler {
*/
onComplete (rawTrailers) {
if (this.#writeStream) {
if (rawTrailers) {
this.#writeStream.rawTrailers = rawTrailers
}

this.#writeStream.rawTrailers = rawTrailers ?? []
this.#writeStream.end()
}

Expand Down

0 comments on commit 3eab995

Please sign in to comment.