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

Refactor responseHeader to responseHeaders #3375

Merged
merged 1 commit into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
22 changes: 22 additions & 0 deletions test/types/dispatcher.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ expectAssignable<Dispatcher>(new Dispatcher())
expectAssignable<Error | null>(err)
expectAssignable<Dispatcher.ConnectData>(data)
}))
expectAssignable<Promise<Dispatcher.ConnectData>>(dispatcher.connect({ origin: '', path: '', responseHeaders: 'raw' }))
expectAssignable<Promise<Dispatcher.ConnectData>>(dispatcher.connect({ origin: '', path: '', responseHeaders: null }))

// request
expectAssignable<Promise<Dispatcher.ResponseData>>(dispatcher.request({ origin: '', path: '', method: 'GET', maxRedirections: 0 }))
Expand All @@ -62,6 +64,8 @@ expectAssignable<Dispatcher>(new Dispatcher())
expectAssignable<Error | null>(err)
expectAssignable<Dispatcher.ResponseData>(data)
}))
expectAssignable<Promise<Dispatcher.ResponseData>>(dispatcher.request({ origin: '', path: '', method: 'GET', responseHeaders: 'raw' }))
expectAssignable<Promise<Dispatcher.ResponseData>>(dispatcher.request({ origin: '', path: '', method: 'GET', responseHeaders: null }))

// pipeline
expectAssignable<Duplex>(dispatcher.pipeline({ origin: '', path: '', method: 'GET', maxRedirections: 0 }, data => {
Expand All @@ -72,6 +76,14 @@ expectAssignable<Dispatcher>(new Dispatcher())
expectAssignable<Dispatcher.PipelineHandlerData>(data)
return new Readable()
}))
expectAssignable<Duplex>(dispatcher.pipeline({ origin: '', path: '', method: 'GET', responseHeaders: 'raw' }, data => {
expectAssignable<Dispatcher.PipelineHandlerData>(data)
return new Readable()
}))
expectAssignable<Duplex>(dispatcher.pipeline({ origin: '', path: '', method: 'GET', responseHeaders: null }, data => {
expectAssignable<Dispatcher.PipelineHandlerData>(data)
return new Readable()
}))

// stream
expectAssignable<Promise<Dispatcher.StreamData>>(dispatcher.stream({ origin: '', path: '', method: 'GET', maxRedirections: 0 }, data => {
Expand Down Expand Up @@ -104,13 +116,23 @@ expectAssignable<Dispatcher>(new Dispatcher())
expectAssignable<Dispatcher.StreamData>(data)
}
))
expectAssignable<Promise<Dispatcher.StreamData>>(dispatcher.stream({ origin: '', path: '', method: 'GET', responseHeaders: 'raw' }, data => {
expectAssignable<Dispatcher.StreamFactoryData>(data)
return new Writable()
}))
expectAssignable<Promise<Dispatcher.StreamData>>(dispatcher.stream({ origin: '', path: '', method: 'GET', responseHeaders: null }, data => {
expectAssignable<Dispatcher.StreamFactoryData>(data)
return new Writable()
}))

// upgrade
expectAssignable<Promise<Dispatcher.UpgradeData>>(dispatcher.upgrade({ path: '', maxRedirections: 0 }))
expectAssignable<void>(dispatcher.upgrade({ path: '' }, (err, data) => {
expectAssignable<Error | null>(err)
expectAssignable<Dispatcher.UpgradeData>(data)
}))
expectAssignable<Promise<Dispatcher.UpgradeData>>(dispatcher.upgrade({ path: '', responseHeaders: 'raw' }))
expectAssignable<Promise<Dispatcher.UpgradeData>>(dispatcher.upgrade({ path: '', responseHeaders: null }))

// close
expectAssignable<Promise<void>>(dispatcher.close())
Expand Down
6 changes: 3 additions & 3 deletions types/dispatcher.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ declare namespace Dispatcher {
/** Default: false */
redirectionLimitReached?: boolean;
/** Default: `null` */
responseHeader?: 'raw' | null;
responseHeaders?: 'raw' | null;
}
export interface RequestOptions extends DispatchOptions {
/** Default: `null` */
Expand All @@ -153,7 +153,7 @@ declare namespace Dispatcher {
/** Default: `null` */
onInfo?: (info: { statusCode: number, headers: Record<string, string | string[]> }) => void;
/** Default: `null` */
responseHeader?: 'raw' | null;
responseHeaders?: 'raw' | null;
/** Default: `64 KiB` */
highWaterMark?: number;
}
Expand All @@ -176,7 +176,7 @@ declare namespace Dispatcher {
/** Default: false */
redirectionLimitReached?: boolean;
/** Default: `null` */
responseHeader?: 'raw' | null;
responseHeaders?: 'raw' | null;
}
export interface ConnectData {
statusCode: number;
Expand Down
Loading