Skip to content

Commit

Permalink
Refactor responseHeader to responseHeaders
Browse files Browse the repository at this point in the history
  • Loading branch information
DarkGL committed Jun 25, 2024
1 parent dd98299 commit a6eb304
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
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

0 comments on commit a6eb304

Please sign in to comment.