-
-
Notifications
You must be signed in to change notification settings - Fork 174
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
358 additions
and
286 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import type { RequestListener } from 'http'; | ||
|
||
declare namespace cluster { | ||
export interface ClusterController { | ||
listen(port: number): void; | ||
} | ||
} | ||
|
||
declare function cluster( | ||
app: RequestListener | { | ||
listen: Function | ||
} | ||
): cluster.ClusterController; | ||
|
||
export = cluster; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,7 @@ | ||
import type { RequestListener } from 'http'; | ||
|
||
declare namespace cluster { | ||
export interface ClusterController { | ||
listen(port: number): void; | ||
} | ||
export interface ClusterController { | ||
listen(port: number): void; | ||
} | ||
|
||
declare function cluster( | ||
app: RequestListener | { | ||
listen: Function | ||
} | ||
): cluster.ClusterController; | ||
|
||
export = cluster; | ||
export default function (app: RequestListener | { listen: Function }): ClusterController; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import type { IncomingMessage, ServerResponse } from 'node:http'; | ||
|
||
declare namespace compression { | ||
export type Options = { | ||
/** | ||
* Don't compress responses below this size (in bytes). | ||
* @default 1024 | ||
*/ | ||
threshold?: number; | ||
/** | ||
* Gzip/Brotli compression effort (1-11, or -1 for default) | ||
* @default -1 | ||
*/ | ||
level?: number; | ||
/** | ||
* Generate and serve Brotli-compressed responses. | ||
* @default false | ||
*/ | ||
brotli?: boolean; | ||
/** | ||
* Generate and serve Gzip-compressed responses. | ||
* @default true | ||
*/ | ||
gzip?: boolean; | ||
/** | ||
* Regular expression of response MIME types to compress. | ||
* @default /text|javascript|\/json|xml/i | ||
*/ | ||
mimes?: RegExp; | ||
}; | ||
|
||
export type Middleware = ( | ||
request: Pick<IncomingMessage, 'method' | 'headers'>, | ||
response: ServerResponse, | ||
next?: (error?: Error | string) => any, | ||
) => void; | ||
} | ||
|
||
declare function compression(options?: compression.Options): compression.Middleware; | ||
|
||
export = compression; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,37 @@ | ||
import type { IncomingMessage, ServerResponse } from 'node:http'; | ||
|
||
declare namespace compression { | ||
export type Options = { | ||
/** | ||
* Don't compress responses below this size (in bytes). | ||
* @default 1024 | ||
*/ | ||
threshold?: number; | ||
/** | ||
* Gzip/Brotli compression effort (1-11, or -1 for default) | ||
* @default -1 | ||
*/ | ||
level?: number; | ||
/** | ||
* Generate and serve Brotli-compressed responses. | ||
* @default false | ||
*/ | ||
brotli?: boolean; | ||
/** | ||
* Generate and serve Gzip-compressed responses. | ||
* @default true | ||
*/ | ||
gzip?: boolean; | ||
/** | ||
* Regular expression of response MIME types to compress. | ||
* @default /text|javascript|\/json|xml/i | ||
*/ | ||
mimes?: RegExp; | ||
}; | ||
export type Options = { | ||
/** | ||
* Don't compress responses below this size (in bytes). | ||
* @default 1024 | ||
*/ | ||
threshold?: number; | ||
/** | ||
* Gzip/Brotli compression effort (1-11, or -1 for default) | ||
* @default -1 | ||
*/ | ||
level?: number; | ||
/** | ||
* Generate and serve Brotli-compressed responses. | ||
* @default false | ||
*/ | ||
brotli?: boolean; | ||
/** | ||
* Generate and serve Gzip-compressed responses. | ||
* @default true | ||
*/ | ||
gzip?: boolean; | ||
/** | ||
* Regular expression of response MIME types to compress. | ||
* @default /text|javascript|\/json|xml/i | ||
*/ | ||
mimes?: RegExp; | ||
}; | ||
|
||
export type Middleware = ( | ||
request: Pick<IncomingMessage, 'method' | 'headers'>, | ||
response: ServerResponse, | ||
next?: (error?: Error | string) => any, | ||
) => void; | ||
} | ||
export type Middleware = ( | ||
request: Pick<IncomingMessage, 'method' | 'headers'>, | ||
response: ServerResponse, | ||
next?: (error?: Error | string) => any, | ||
) => void; | ||
|
||
declare function compression(options?: compression.Options): compression.Middleware; | ||
|
||
export = compression; | ||
export default function (options?: Options): Middleware; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { IncomingMessage, ServerResponse } from 'http'; | ||
|
||
// IncomingMessage | ||
class Request { | ||
constructor(method = 'GET', headers = {}) { | ||
this.method = method.toUpperCase(); | ||
this.headers = {}; | ||
for (let i in headers) { | ||
this.headers[i.toLowerCase()] = headers[i]; | ||
} | ||
} | ||
} | ||
|
||
class Response extends ServerResponse { | ||
constructor(req) { | ||
super(req); | ||
this._chunks = []; | ||
this.done = new Promise(r => this._done = r); | ||
} | ||
write(chunk, enc, cb) { | ||
if (!Buffer.isBuffer(chunk)) chunk = Buffer.from(chunk, enc); | ||
this._chunks.push(chunk); | ||
if (cb) cb(null); | ||
return true; | ||
} | ||
end(chunk, enc, cb) { | ||
if (chunk) this.write(chunk, enc); | ||
if (cb) cb(); | ||
this._done(Buffer.concat(this._chunks)); | ||
return this; | ||
} | ||
getResponseData() { | ||
return this.done; | ||
} | ||
async getResponseText() { | ||
return (await this.done).toString(); | ||
} | ||
} | ||
|
||
/** | ||
* @param {string} method | ||
* @param {string} encoding | ||
* @returns {{ req: IncomingMessage, res: Response }} | ||
*/ | ||
export function prepare(method, encoding) { | ||
let req = new Request(method, { | ||
'Accept-Encoding': encoding, | ||
}); | ||
let res = new Response(req); | ||
// @ts-expect-error | ||
return { req, res }; | ||
} | ||
|
||
export function toAscii(thing) { | ||
return JSON.stringify( | ||
Buffer.from(thing).toString('ascii') | ||
).replace(/(^"|"$)/g,''); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.