Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
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
2 changes: 1 addition & 1 deletion lib/cache/memory-cache-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class MemoryCacheStore {
: {
statusMessage: entry.statusMessage,
statusCode: entry.statusCode,
rawHeaders: entry.rawHeaders,
headers: entry.headers,
body: entry.body,
etag: entry.etag,
cachedAt: entry.cachedAt,
Expand Down
18 changes: 9 additions & 9 deletions lib/cache/sqlite-cache-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ const { DatabaseSync } = require('node:sqlite')
const { Writable } = require('stream')
const { assertCacheKey, assertCacheValue } = require('../util/cache.js')

const VERSION = 1
const VERSION = 2

/**
* @typedef {import('../../types/cache-interceptor.d.ts').default.CacheStore} CacheStore
* @implements {CacheStore}
*
* @typedef {{
* id: Readonly<number>
* rawHeaders?: string
* headers?: Record<string, string | string[]>
* vary?: string | object
* body: string
* } & import('../../types/cache-interceptor.d.ts').default.CacheValue} SqliteStoreValue
Expand Down Expand Up @@ -107,7 +107,7 @@ class SqliteCacheStore {
deleteAt INTEGER NOT NULL,
statusCode INTEGER NOT NULL,
statusMessage TEXT NOT NULL,
rawHeaders TEXT NULL,
headers TEXT NULL,
etag TEXT NULL,
vary TEXT NULL,
cachedAt INTEGER NOT NULL,
Expand All @@ -126,7 +126,7 @@ class SqliteCacheStore {
deleteAt,
statusCode,
statusMessage,
rawHeaders,
headers,
etag,
vary,
cachedAt,
Expand All @@ -145,7 +145,7 @@ class SqliteCacheStore {
deleteAt = ?,
statusCode = ?,
statusMessage = ?,
rawHeaders = ?,
headers = ?,
etag = ?,
cachedAt = ?,
staleAt = ?,
Expand All @@ -162,7 +162,7 @@ class SqliteCacheStore {
deleteAt,
statusCode,
statusMessage,
rawHeaders,
headers,
etag,
vary,
cachedAt,
Expand Down Expand Up @@ -221,7 +221,7 @@ class SqliteCacheStore {
body: value.body ? parseBufferArray(JSON.parse(value.body)) : null,
statusCode: value.statusCode,
statusMessage: value.statusMessage,
rawHeaders: value.rawHeaders ? parseBufferArray(JSON.parse(value.rawHeaders)) : undefined,
headers: value.headers ? JSON.parse(value.headers) : undefined,
etag: value.etag ? value.etag : undefined,
cachedAt: value.cachedAt,
staleAt: value.staleAt,
Expand Down Expand Up @@ -275,7 +275,7 @@ class SqliteCacheStore {
value.deleteAt,
value.statusCode,
value.statusMessage,
value.rawHeaders ? JSON.stringify(stringifyBufferArray(value.rawHeaders)) : null,
value.headers ? JSON.stringify(value.headers) : null,
value.etag,
value.cachedAt,
value.staleAt,
Expand All @@ -291,7 +291,7 @@ class SqliteCacheStore {
value.deleteAt,
value.statusCode,
value.statusMessage,
value.rawHeaders ? JSON.stringify(stringifyBufferArray(value.rawHeaders)) : null,
value.headers ? JSON.stringify(value.headers) : null,
value.etag ? value.etag : null,
value.vary ? JSON.stringify(value.vary) : null,
value.cachedAt,
Expand Down
5 changes: 5 additions & 0 deletions lib/core/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,11 @@ function assertRequestHandler (handler, method, upgrade) {
throw new InvalidArgumentError('handler must be an object')
}

if (typeof handler.onRequestStart === 'function') {
// TODO (fix): More checks...
return
}

if (typeof handler.onConnect !== 'function') {
throw new InvalidArgumentError('invalid onConnect method')
}
Expand Down
3 changes: 2 additions & 1 deletion lib/dispatcher/dispatcher-base.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict'

const Dispatcher = require('./dispatcher')
const UnwrapHandler = require('../handler/unwrap-handler')
const {
ClientDestroyedError,
ClientClosedError,
Expand Down Expand Up @@ -142,7 +143,7 @@ class DispatcherBase extends Dispatcher {
throw new ClientClosedError()
}

return this[kDispatch](opts, handler)
return this[kDispatch](opts, UnwrapHandler.unwrap(handler))
} catch (err) {
if (typeof handler.onError !== 'function') {
throw new InvalidArgumentError('invalid onError method')
Expand Down
4 changes: 4 additions & 0 deletions lib/dispatcher/dispatcher.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
'use strict'
const EventEmitter = require('node:events')
const WrapHandler = require('../handler/wrap-handler')

const wrapInterceptor = (dispatch) => (opts, handler) => dispatch(opts, WrapHandler.wrap(handler))

class Dispatcher extends EventEmitter {
dispatch () {
Expand Down Expand Up @@ -29,6 +32,7 @@ class Dispatcher extends EventEmitter {
}

dispatch = interceptor(dispatch)
dispatch = wrapInterceptor(dispatch)

if (dispatch == null || typeof dispatch !== 'function' || dispatch.length !== 2) {
throw new TypeError('invalid interceptor')
Expand Down
Loading
Loading