Skip to content

Commit

Permalink
Use socket instead of connection (#915)
Browse files Browse the repository at this point in the history
* Use socket instead of connection

The request.connection and response.connection properties are now runtime deprecated.

* Update request-as-event-emitter.ts

* Switch to socket

* Add NodeJS 13
  • Loading branch information
Cerberooo authored and sindresorhus committed Nov 4, 2019
1 parent 95bed1e commit b0dfc95
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 2 deletions.
1 change: 1 addition & 0 deletions .travis.yml
@@ -1,5 +1,6 @@
language: node_js
node_js:
- '13'
- '12'
- '10'
after_success:
Expand Down
3 changes: 2 additions & 1 deletion source/request-as-event-emitter.ts
Expand Up @@ -127,7 +127,8 @@ export default (options: NormalizedOptions, input?: TransformStream) => {
delete typedResponse.fromCache;

if (!typedResponse.isFromCache) {
typedResponse.ip = response.connection.remoteAddress;
// @ts-ignore Node typings haven't been updated yet
typedResponse.ip = response.socket.remoteAddress;
}

const rawCookies = typedResponse.headers['set-cookie'];
Expand Down
2 changes: 1 addition & 1 deletion source/utils/types.ts
Expand Up @@ -71,7 +71,7 @@ export interface Response extends http.IncomingMessage {
// TODO: The `ResponseLike` type should be properly fixed instead:
// https://github.com/sindresorhus/got/pull/827/files#r323633794
export interface ResponseObject extends ResponseLike {
connection: {
socket: {
remoteAddress: string;
};
}
Expand Down

0 comments on commit b0dfc95

Please sign in to comment.