-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make HTTPModule more abstract to be able to use it in non-Node.JS env…
…ironments (#3655) Co-authored-by: Kamil Ogórek <[email protected]>
- Loading branch information
1 parent
888c14a
commit 4f401ab
Showing
2 changed files
with
54 additions
and
28 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import http, { IncomingHttpHeaders } from 'http'; | ||
import https from 'https'; | ||
import { URL } from 'url'; | ||
|
||
export type HTTPModuleRequestOptions = http.RequestOptions | https.RequestOptions | string | URL; | ||
|
||
/** | ||
* Cut version of http.IncomingMessage. | ||
* Some transports work in a special Javascript environment where http.IncomingMessage is not available. | ||
*/ | ||
export interface HTTPModuleRequestIncomingMessage { | ||
headers: IncomingHttpHeaders; | ||
statusCode?: number; | ||
on(event: 'data' | 'end', listener: () => void): void; | ||
setEncoding(encoding: string): void; | ||
} | ||
|
||
/** | ||
* Cut version of http.ClientRequest. | ||
* Some transports work in a special Javascript environment where http.IncomingMessage is not available. | ||
*/ | ||
export interface HTTPModuleClientRequest { | ||
end(chunk: string): void; | ||
on(event: 'error', listener: () => void): void; | ||
} | ||
|
||
/** | ||
* Internal used interface for typescript. | ||
* @hidden | ||
*/ | ||
export interface HTTPModule { | ||
/** | ||
* Request wrapper | ||
* @param options These are {@see TransportOptions} | ||
* @param callback Callback when request is finished | ||
*/ | ||
request( | ||
options: HTTPModuleRequestOptions, | ||
callback?: (res: HTTPModuleRequestIncomingMessage) => void, | ||
): HTTPModuleClientRequest; | ||
|
||
// This is the type for nodejs versions that handle the URL argument | ||
// (v10.9.0+), but we do not use it just yet because we support older node | ||
// versions: | ||
|
||
// request( | ||
// url: string | URL, | ||
// options: http.RequestOptions | https.RequestOptions, | ||
// callback?: (res: http.IncomingMessage) => void, | ||
// ): http.ClientRequest; | ||
} |
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