Repository navigation
[node] net.Server, http.Server, http.ServerRequest, http.ServerResponse, http.ClientRequest, http.IncomingMessage, http.ClientResponse fix from interface to class and add constructors. - #18281
11 commits merged into
Conversation
…se, http.ClientRequest, http.IncomingMessage, http.ClientResponse, http.Server fix from interface to class and add constructors.
|
types/node/index.d.ts to authors (@DefinitelyTyped/DefinitelyTyped @parambirs @robdesideri @tellnes @WilcoBakker @octo-sniffle @smac89 @Flarna @mwiktorczyk Microsoft TypeScript (account can't be detected)). Could you review this PR? Checklist
|
| agent?: Agent | boolean; | ||
| _defaultAgent?: Agent, | ||
| timeout?: number; | ||
| rejectUnauthorized?: boolean; |
There was a problem hiding this comment.
I think rejectUnauthorized is only available for https.
There was a problem hiding this comment.
rejectUnauthorized is used here. it will be passed to underlying agent if socketpath provided
There was a problem hiding this comment.
Yes, because ClientRequest class is reused by HTTPS. Setting this flag for plain http doesn't make much sense as it is related to tls.
There was a problem hiding this comment.
you're right. I removed it.
| _defaultAgent?: Agent, | ||
| timeout?: number; | ||
| rejectUnauthorized?: boolean; | ||
| createConnection?: Function; |
There was a problem hiding this comment.
would be nice to have a more concrete typing of this function here. Maybe there is a reuse with agent.createConnection().
There was a problem hiding this comment.
judging from code here
https://github.com/nodejs/node/blob/master/lib/_http_client.js#L278
I think the type should be
createConnection?: (options: ClientRequestArgs, oncreate: (err: Error, socket: net.Socket) => void) => net.Socket;|
|
||
| export interface Server extends net.Server { | ||
| export class Server extends net.Server { | ||
| constructor(requestListener?: Function); |
There was a problem hiding this comment.
Please consider to use a more specific type for requestListener, e.a. (req: IncomingMessage, res: ServerResponse) => void
There was a problem hiding this comment.
after checking source code here
https://github.com/nodejs/node/blob/master/lib/_http_server.js#L563-L593
you're right. the type should be
constructor(requestListener?: (req: IncomingMessage, res: ServerResponse) => void);|
|
||
| export interface ServerResponse extends stream.Writable { | ||
| // https://github.com/nodejs/node/blob/master/lib/_http_server.js#L108 | ||
| export class ServerResponse extends stream.Writable { |
There was a problem hiding this comment.
ServerResponse inherits from OutgoingMessage (see https://github.com/nodejs/node/blob/master/lib/_http_server.js#L122).
I think a new export OutgoingMessage should be added here and used as base for ServerResponse and ClientRequest. see also #17720
There was a problem hiding this comment.
@Flarna fix! please take a look. thanks!
There was a problem hiding this comment.
I also add more tests for http
|
|
||
| // https://github.com/nodejs/node/blob/master/lib/_http_client.js#L77 | ||
| export class ClientRequest extends stream.Writable { | ||
| constructor(url: string, cb?: Function); |
There was a problem hiding this comment.
Consider to combine the constructors by using union types.
Consider also to use a stricter typing for the cb (e.a. (res: IncomingMessage) => void).
There was a problem hiding this comment.
@Flarna fixed in the new commit. please take a look. thanks.
createConnection callback make more detailed, http.Server requestListener more detailed, add export OutgoingMessage, ServerResponse and ClientRequest extends OutgoingMessage. combine the constructors in ClientRequest
|
@Flarna - Thanks for your review of this PR! Can you please look at the new code and update your review status if appropriate? |
| ciphers?: string; | ||
| honorCipherOrder?: boolean; | ||
| requestCert?: boolean; | ||
| rejectUnauthorized?: boolean; |
There was a problem hiding this comment.
I think rejectUnauthorized should be kept here as this are https server options. It should be removed in http.ClientRequestArgs
There was a problem hiding this comment.
maybe add another httpsClientArgs extends ClientRequestArgs with own prop rejectUnauthorized ?
There was a problem hiding this comment.
This is already in place but in https it's still named RequestOptions: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/node/index.d.ts#L1522
There was a problem hiding this comment.
omg. totally mistake. should remove from ClientRequestArgs. Must be tired. lol
| import { URL } from "url"; | ||
|
|
||
| export interface RequestOptions { | ||
| export interface HttpHeaders { |
There was a problem hiding this comment.
Please note that incoming headers will never contain numbers but setting response headers allows nubmers (as they are converted internally to strings). Therefore using HttpHeaders in incoming message forces everyone to check if type is string or number.
I think we should keep two distinct types for incoming and outgoing headers.
| } | ||
| // https://github.com/nodejs/node/blob/master/lib/_http_outgoing.js | ||
| export class OutgoingMessage extends stream.Writable { | ||
| output: any[]; |
There was a problem hiding this comment.
Not sure if it is a good idea to add non documented properties here which were not yet here before as they may change even on patch version of NodeJs.
There was a problem hiding this comment.
since OutgoingMessage is not documented on Nodejs official document, I had hard time determine which should be kept in props.
I think we should keep props below for sure.
upgrading: boolean;
chunkedEncoding: boolean;
shouldKeepAlive: boolean;
useChunkedEncodingByDefault: boolean;
sendDate: boolean;
finished: boolean;
headersSent: boolean;
connection: net.Socket;and remove output, outputEncodings, outputCallbacks.
@Flarna what to you think?
There was a problem hiding this comment.
I think we should remove upgrading. chunkedEncoding. shouldKeepAlive, and useChunkedEncodingByDefault as they are undocumented and implementation details.
And socket (currently in ClientRequest) should be here.
| detachSocket(socket: net.Socket): void; | ||
| // https://github.com/nodejs/node/blob/master/test/parallel/test-http-write-callbacks.js#L53 | ||
| // no args in writeContinue callback | ||
| writeContinue(callback?: Function): void; |
There was a problem hiding this comment.
Use () => voidfor callback.
| /** | ||
| * @deprecated Docs-only deprecated: DEP0063 | ||
| */ | ||
| writeHeader(statusCode: number, reasonPhrase?: string, headers?: HttpHeaders): void; |
There was a problem hiding this comment.
Why add deprecated APIs here?
There was a problem hiding this comment.
it's still work in current version of node.
so I think it would be better we still support it
There was a problem hiding this comment.
I would not add deprecated APIs (in special as they are no longer in the docs) as this "invites" to us it. Same is valid for other internal/private properties.
But this is just my vote.
There was a problem hiding this comment.
make sense. going to remove deprecated
|
|
||
| // https://github.com/nodejs/node/blob/master/lib/_http_client.js#L77 | ||
| export class ClientRequest extends OutgoingMessage { | ||
| agent: Agent; |
There was a problem hiding this comment.
Not sure if adding non document properties here is a good idea as they may change without notice.
There was a problem hiding this comment.
maybe just props I found on document?
request.aborted
request.connection
request.socketThere was a problem hiding this comment.
I think so yes. Undocumented stuff should be anyway not used therefore no need to provide typings.
|
Nice work! I reviewed once more and had a few more comments. |
…aders to incoming and outgoing, fix rejectUnauthorized prop misplaced, use () => void for callback
|
@Flarna all fixed! |
|
@wwwy3y3 Please address the merge conflict. |
| export class Server extends net.Server { | ||
| constructor(requestListener?: (req: IncomingMessage, res: ServerResponse) => void); | ||
|
|
||
| setTimeout(msecs: number, callback: () => void): NodeJS.Timer; |
There was a problem hiding this comment.
setTimeout is returning this.
| trailers: { [key: string]: string }; | ||
| rawTrailers: string[]; | ||
| setTimeout(msecs: number, callback: Function): NodeJS.Timer; | ||
| setTimeout(msecs: number, callback: () => void): NodeJS.Timer; |
|
Approved by a listed owner. PR appears ready to merge pending express review by a maintainer. |
|
Thanks! |
…se, http.ClientRequest, http.IncomingMessage, http.ClientResponse fix from interface to class and add constructors. (DefinitelyTyped#18281) * [node] net.Server, http.Server, http.ServerRequest, http.ServerResponse, http.ClientRequest, http.IncomingMessage, http.ClientResponse, http.Server fix from interface to class and add constructors. * add http constructor tests * fix lint * add author * fix: remove rejectUnauthorized, createConnection callback make more detailed, http.Server requestListener more detailed, add export OutgoingMessage, ServerResponse and ClientRequest extends OutgoingMessage. combine the constructors in ClientRequest * add more http tests * remove trailing space * remove deprecated apis, private props not documented, seperate httpHeaders to incoming and outgoing, fix rejectUnauthorized prop misplaced, use () => void for callback * typo * settimeout return this
…se, http.ClientRequest, http.IncomingMessage, http.ClientResponse fix from interface to class and add constructors. (DefinitelyTyped#18281) * [node] net.Server, http.Server, http.ServerRequest, http.ServerResponse, http.ClientRequest, http.IncomingMessage, http.ClientResponse, http.Server fix from interface to class and add constructors. * add http constructor tests * fix lint * add author * fix: remove rejectUnauthorized, createConnection callback make more detailed, http.Server requestListener more detailed, add export OutgoingMessage, ServerResponse and ClientRequest extends OutgoingMessage. combine the constructors in ClientRequest * add more http tests * remove trailing space * remove deprecated apis, private props not documented, seperate httpHeaders to incoming and outgoing, fix rejectUnauthorized prop misplaced, use () => void for callback * typo * settimeout return this
Fix
httpandnetshould beclassinstead (net.Server, http.Server, http.ServerRequest, http.ServerResponse, http.ClientRequest, http.IncomingMessage, http.ClientResponse)Template
Please fill in this template.
npm run lint package-name(ortscif notslint.jsonis present).Select one of these and delete the others:
If changing an existing definition:
tslint.jsoncontaining{ "extends": "dtslint/dt.json" }.