From c3421f12a80881669f1ab1e52566f7f193fce6e8 Mon Sep 17 00:00:00 2001 From: Kei Ito Date: Fri, 15 Feb 2019 12:13:45 +0900 Subject: [PATCH 1/3] feat: add ClientRequest.prototype.path --- types/node/http.d.ts | 1 + types/node/test/http.ts | 4 ++++ types/node/v0/index.d.ts | 1 + types/node/v10/http.d.ts | 1 + types/node/v4/index.d.ts | 1 + types/node/v6/index.d.ts | 1 + types/node/v7/index.d.ts | 1 + types/node/v8/index.d.ts | 1 + types/node/v9/index.d.ts | 1 + 9 files changed, 12 insertions(+) diff --git a/types/node/http.d.ts b/types/node/http.d.ts index b2557963a0..7c790c3d41 100644 --- a/types/node/http.d.ts +++ b/types/node/http.d.ts @@ -159,6 +159,7 @@ declare module "http" { constructor(url: string | URL | ClientRequestArgs, cb?: (res: IncomingMessage) => void); + path: string; abort(): void; onSocket(socket: net.Socket): void; setTimeout(timeout: number, callback?: () => void): this; diff --git a/types/node/test/http.ts b/types/node/test/http.ts index 6e4db63a2c..20a07f0048 100644 --- a/types/node/test/http.ts +++ b/types/node/test/http.ts @@ -1,6 +1,7 @@ import * as http from 'http'; import * as url from 'url'; import * as net from 'net'; +import * as assert from 'assert'; // http Server { @@ -112,6 +113,9 @@ import * as net from 'net'; // event req.on('data', () => { }); + + // path + assert.equal(req.path.charAt(0), '/'); } { diff --git a/types/node/v0/index.d.ts b/types/node/v0/index.d.ts index 1f29bbcc10..6991514b3b 100644 --- a/types/node/v0/index.d.ts +++ b/types/node/v0/index.d.ts @@ -531,6 +531,7 @@ declare module "http" { write(str: string, encoding?: string, cb?: Function): boolean; write(str: string, encoding?: string, fd?: string): boolean; + path: string; write(chunk: any, encoding?: string): void; abort(): void; setTimeout(timeout: number, callback?: Function): void; diff --git a/types/node/v10/http.d.ts b/types/node/v10/http.d.ts index 5e1ebcc127..bc2f6d2939 100644 --- a/types/node/v10/http.d.ts +++ b/types/node/v10/http.d.ts @@ -154,6 +154,7 @@ declare module "http" { constructor(url: string | URL | ClientRequestArgs, cb?: (res: IncomingMessage) => void); + path: string; abort(): void; onSocket(socket: net.Socket): void; setTimeout(timeout: number, callback?: () => void): this; diff --git a/types/node/v4/index.d.ts b/types/node/v4/index.d.ts index f52a8d01f8..197a79a9a6 100644 --- a/types/node/v4/index.d.ts +++ b/types/node/v4/index.d.ts @@ -785,6 +785,7 @@ declare module "http" { write(str: string, encoding?: string, cb?: Function): boolean; write(str: string, encoding?: string, fd?: string): boolean; + path: string; write(chunk: any, encoding?: string): void; abort(): void; setTimeout(timeout: number, callback?: Function): void; diff --git a/types/node/v6/index.d.ts b/types/node/v6/index.d.ts index 6dd1ad1dc0..24256edd25 100644 --- a/types/node/v6/index.d.ts +++ b/types/node/v6/index.d.ts @@ -857,6 +857,7 @@ declare module "http" { write(str: string, encoding?: string, cb?: Function): boolean; write(str: string, encoding?: string, fd?: string): boolean; + path: string; write(chunk: any, encoding?: string): void; abort(): void; setTimeout(timeout: number, callback?: Function): void; diff --git a/types/node/v7/index.d.ts b/types/node/v7/index.d.ts index a4fde30a97..27f9a04a7a 100644 --- a/types/node/v7/index.d.ts +++ b/types/node/v7/index.d.ts @@ -854,6 +854,7 @@ declare module "http" { write(str: string, encoding?: string, cb?: Function): boolean; write(str: string, encoding?: string, fd?: string): boolean; + path: string; write(chunk: any, encoding?: string): void; abort(): void; setTimeout(timeout: number, callback?: Function): void; diff --git a/types/node/v8/index.d.ts b/types/node/v8/index.d.ts index 1fac090367..141e7a61c7 100644 --- a/types/node/v8/index.d.ts +++ b/types/node/v8/index.d.ts @@ -1101,6 +1101,7 @@ declare module "http" { constructor(url: string | URL | ClientRequestArgs, cb?: (res: IncomingMessage) => void); + path: string; abort(): void; onSocket(socket: net.Socket): void; setTimeout(timeout: number, callback?: () => void): this; diff --git a/types/node/v9/index.d.ts b/types/node/v9/index.d.ts index 220afd9e60..d37b7a14bc 100644 --- a/types/node/v9/index.d.ts +++ b/types/node/v9/index.d.ts @@ -1186,6 +1186,7 @@ declare module "http" { constructor(url: string | URL | ClientRequestArgs, cb?: (res: IncomingMessage) => void); + path: string; abort(): void; onSocket(socket: net.Socket): void; setTimeout(timeout: number, callback?: () => void): this; From 96426c7f0448aea975a61ddc1cdbc1d5e90bce99 Mon Sep 17 00:00:00 2001 From: Kei Ito Date: Fri, 15 Feb 2019 14:38:00 +0900 Subject: [PATCH 2/3] fix(node): make request.path readonly --- types/node/http.d.ts | 2 +- types/node/v0/index.d.ts | 2 +- types/node/v10/http.d.ts | 2 +- types/node/v4/index.d.ts | 2 +- types/node/v6/index.d.ts | 2 +- types/node/v7/index.d.ts | 2 +- types/node/v8/index.d.ts | 2 +- types/node/v9/index.d.ts | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/types/node/http.d.ts b/types/node/http.d.ts index 7c790c3d41..18256eb49c 100644 --- a/types/node/http.d.ts +++ b/types/node/http.d.ts @@ -159,7 +159,7 @@ declare module "http" { constructor(url: string | URL | ClientRequestArgs, cb?: (res: IncomingMessage) => void); - path: string; + readonly path: string; abort(): void; onSocket(socket: net.Socket): void; setTimeout(timeout: number, callback?: () => void): this; diff --git a/types/node/v0/index.d.ts b/types/node/v0/index.d.ts index 6991514b3b..2190660451 100644 --- a/types/node/v0/index.d.ts +++ b/types/node/v0/index.d.ts @@ -531,7 +531,7 @@ declare module "http" { write(str: string, encoding?: string, cb?: Function): boolean; write(str: string, encoding?: string, fd?: string): boolean; - path: string; + readonly path: string; write(chunk: any, encoding?: string): void; abort(): void; setTimeout(timeout: number, callback?: Function): void; diff --git a/types/node/v10/http.d.ts b/types/node/v10/http.d.ts index bc2f6d2939..b55ab680cf 100644 --- a/types/node/v10/http.d.ts +++ b/types/node/v10/http.d.ts @@ -154,7 +154,7 @@ declare module "http" { constructor(url: string | URL | ClientRequestArgs, cb?: (res: IncomingMessage) => void); - path: string; + readonly path: string; abort(): void; onSocket(socket: net.Socket): void; setTimeout(timeout: number, callback?: () => void): this; diff --git a/types/node/v4/index.d.ts b/types/node/v4/index.d.ts index 197a79a9a6..279c3cefbf 100644 --- a/types/node/v4/index.d.ts +++ b/types/node/v4/index.d.ts @@ -785,7 +785,7 @@ declare module "http" { write(str: string, encoding?: string, cb?: Function): boolean; write(str: string, encoding?: string, fd?: string): boolean; - path: string; + readonly path: string; write(chunk: any, encoding?: string): void; abort(): void; setTimeout(timeout: number, callback?: Function): void; diff --git a/types/node/v6/index.d.ts b/types/node/v6/index.d.ts index 24256edd25..f4fa74291c 100644 --- a/types/node/v6/index.d.ts +++ b/types/node/v6/index.d.ts @@ -857,7 +857,7 @@ declare module "http" { write(str: string, encoding?: string, cb?: Function): boolean; write(str: string, encoding?: string, fd?: string): boolean; - path: string; + readonly path: string; write(chunk: any, encoding?: string): void; abort(): void; setTimeout(timeout: number, callback?: Function): void; diff --git a/types/node/v7/index.d.ts b/types/node/v7/index.d.ts index 27f9a04a7a..2bf7056a42 100644 --- a/types/node/v7/index.d.ts +++ b/types/node/v7/index.d.ts @@ -854,7 +854,7 @@ declare module "http" { write(str: string, encoding?: string, cb?: Function): boolean; write(str: string, encoding?: string, fd?: string): boolean; - path: string; + readonly path: string; write(chunk: any, encoding?: string): void; abort(): void; setTimeout(timeout: number, callback?: Function): void; diff --git a/types/node/v8/index.d.ts b/types/node/v8/index.d.ts index 141e7a61c7..b4d2d99a2c 100644 --- a/types/node/v8/index.d.ts +++ b/types/node/v8/index.d.ts @@ -1101,7 +1101,7 @@ declare module "http" { constructor(url: string | URL | ClientRequestArgs, cb?: (res: IncomingMessage) => void); - path: string; + readonly path: string; abort(): void; onSocket(socket: net.Socket): void; setTimeout(timeout: number, callback?: () => void): this; diff --git a/types/node/v9/index.d.ts b/types/node/v9/index.d.ts index d37b7a14bc..7f0517a64c 100644 --- a/types/node/v9/index.d.ts +++ b/types/node/v9/index.d.ts @@ -1186,7 +1186,7 @@ declare module "http" { constructor(url: string | URL | ClientRequestArgs, cb?: (res: IncomingMessage) => void); - path: string; + readonly path: string; abort(): void; onSocket(socket: net.Socket): void; setTimeout(timeout: number, callback?: () => void): this; From 231112a508b1cc8a579ddc0ca6f9bdd1495ab4b1 Mon Sep 17 00:00:00 2001 From: Kei Ito Date: Fri, 15 Feb 2019 14:39:21 +0900 Subject: [PATCH 3/3] fix(node): accept the suggested change --- types/node/test/http.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/types/node/test/http.ts b/types/node/test/http.ts index 20a07f0048..7a79baddc0 100644 --- a/types/node/test/http.ts +++ b/types/node/test/http.ts @@ -1,7 +1,6 @@ import * as http from 'http'; import * as url from 'url'; import * as net from 'net'; -import * as assert from 'assert'; // http Server { @@ -115,7 +114,7 @@ import * as assert from 'assert'; req.on('data', () => { }); // path - assert.equal(req.path.charAt(0), '/'); + const path: string = req.path; } {