Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: cache #3804

Merged
merged 17 commits into from
Nov 6, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
WIP
  • Loading branch information
ronag committed Nov 6, 2024
commit 3eab9955173786c8bb732c8cb096cf0395d700d0
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
Loading