@@ -9,9 +9,6 @@ const once = require('once')
9
9
const querystring = require ( 'querystring' )
10
10
const url = require ( 'url' )
11
11
12
- var flag = false
13
- var original_host ;
14
-
15
12
const isStream = o => o !== null && typeof o === 'object' && typeof o . pipe === 'function'
16
13
17
14
function simpleGet ( opts , cb ) {
@@ -37,13 +34,8 @@ function simpleGet (opts, cb) {
37
34
opts . headers [ 'content-type' ] = 'application/x-www-form-urlencoded'
38
35
}
39
36
40
- //getting original host
41
- if ( ! flag ) {
42
- original_host = opts . hostname
43
- //console.log(original_host)
44
- flag = true
45
- }
46
-
37
+ const ohost = opts . hostname
38
+
47
39
if ( body ) {
48
40
if ( ! opts . method ) opts . method = 'POST'
49
41
if ( ! isStream ( body ) ) opts . headers [ 'content-length' ] = Buffer . byteLength ( body )
@@ -61,13 +53,13 @@ function simpleGet (opts, cb) {
61
53
delete opts . headers . host // Discard `host` header on redirect (see #32)
62
54
res . resume ( ) // Discard response
63
55
64
- var redirect_host = url . parse ( opts . url ) . hostname //getting redirected hostname
65
- //if redirected host is different than original host then drop cookie header to prevent cookie leak in thirdparty site redirect
66
- if ( redirect_host !== null && redirect_host !== original_host ) {
67
- delete opts . headers . cookie ;
68
- delete opts . headers . authorization ;
69
- }
70
-
56
+ const rhost = url . parse ( opts . url ) . hostname // eslint-disable-line node/no-deprecated-api
57
+ // if redirected host is different than original host then drop cookie header to prevent cookie leak in thirdparty site redirect
58
+ if ( rhost !== null && rhost !== ohost ) {
59
+ delete opts . headers . cookie
60
+ delete opts . headers . authorization
61
+ }
62
+
71
63
if ( opts . method === 'POST' && [ 301 , 302 ] . includes ( res . statusCode ) ) {
72
64
opts . method = 'GET' // On 301/302 redirect, change POST to GET (see #35)
73
65
delete opts . headers [ 'content-length' ] ; delete opts . headers [ 'content-type' ]
0 commit comments