Skip to content

Commit

Permalink
fix(typings): accept an HTTP2 server in the constructor
Browse files Browse the repository at this point in the history
Related:

- #4434
- #4494
  • Loading branch information
darrachequesne committed Oct 14, 2022
1 parent 19b225b commit d3d0a2d
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import http = require("http");
import type { Server as HTTPSServer } from "https";
import type { Http2SecureServer } from "http2";
import { createReadStream } from "fs";
import { createDeflate, createGzip, createBrotliCompress } from "zlib";
import accepts = require("accepts");
Expand Down Expand Up @@ -155,7 +156,7 @@ export class Server<
* @private
*/
_connectTimeout: number;
private httpServer: http.Server | HTTPSServer;
private httpServer: http.Server | HTTPSServer | Http2SecureServer;

/**
* Server constructor.
Expand All @@ -165,7 +166,7 @@ export class Server<
*/
constructor(opts?: Partial<ServerOptions>);
constructor(
srv?: http.Server | HTTPSServer | number,
srv?: http.Server | HTTPSServer | Http2SecureServer | number,
opts?: Partial<ServerOptions>
);
constructor(
Expand All @@ -174,6 +175,7 @@ export class Server<
| Partial<ServerOptions>
| http.Server
| HTTPSServer
| Http2SecureServer
| number,
opts?: Partial<ServerOptions>
);
Expand All @@ -183,6 +185,7 @@ export class Server<
| Partial<ServerOptions>
| http.Server
| HTTPSServer
| Http2SecureServer
| number,
opts: Partial<ServerOptions> = {}
) {
Expand All @@ -204,7 +207,9 @@ export class Server<
this.sockets = this.of("/");
this.opts = opts;
if (srv || typeof srv == "number")
this.attach(srv as http.Server | HTTPSServer | number);
this.attach(
srv as http.Server | HTTPSServer | Http2SecureServer | number
);
}

/**
Expand Down Expand Up @@ -332,7 +337,7 @@ export class Server<
* @return self
*/
public listen(
srv: http.Server | HTTPSServer | number,
srv: http.Server | HTTPSServer | Http2SecureServer | number,
opts: Partial<ServerOptions> = {}
): this {
return this.attach(srv, opts);
Expand All @@ -346,7 +351,7 @@ export class Server<
* @return self
*/
public attach(
srv: http.Server | HTTPSServer | number,
srv: http.Server | HTTPSServer | Http2SecureServer | number,
opts: Partial<ServerOptions> = {}
): this {
if ("function" == typeof srv) {
Expand Down Expand Up @@ -452,7 +457,7 @@ export class Server<
* @private
*/
private initEngine(
srv: http.Server | HTTPSServer,
srv: http.Server | HTTPSServer | Http2SecureServer,
opts: EngineOptions & AttachOptions
): void {
// initialize engine
Expand All @@ -475,7 +480,9 @@ export class Server<
* @param srv http server
* @private
*/
private attachServe(srv: http.Server | HTTPSServer): void {
private attachServe(
srv: http.Server | HTTPSServer | Http2SecureServer
): void {
debug("attaching client serving req handler");

const evs = srv.listeners("request").slice(0);
Expand Down

0 comments on commit d3d0a2d

Please sign in to comment.