File tree 6 files changed +19
-2416
lines changed
6 files changed +19
-2416
lines changed Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " request-light" ,
3
- "version" : " 0.1 .0" ,
3
+ "version" : " 0.2 .0" ,
4
4
"description" : " Lightweight request library. Promise based, with proxy support." ,
5
5
"main" : " ./lib/main.js" ,
6
6
"typings" : " ./lib/main" ,
14
14
"url" : " https://github.com/Microsoft/node-request-light/issues"
15
15
},
16
16
"devDependencies" : {
17
- "typescript" : " ^1.8.9"
17
+ "typescript" : " ^2.1.5" ,
18
+ "@types/node" : " ^6.0.51" ,
19
+ "@types/mocha" : " ^2.2.33"
18
20
},
19
21
"dependencies" : {
20
22
"http-proxy-agent" : " ^0.2.6" ,
21
23
"https-proxy-agent" : " ^0.3.5" ,
22
- "vscode-nls" : " ^1 .0.4 "
24
+ "vscode-nls" : " ^2 .0.2 "
23
25
},
24
26
"scripts" : {
25
27
"prepublish" : " tsc -p ./src" ,
Original file line number Diff line number Diff line change @@ -57,7 +57,7 @@ export function xhr(options: XHROptions): Promise<XHRResponse> {
57
57
58
58
return request ( options ) . then ( result => new Promise < XHRResponse > ( ( c , e ) => {
59
59
let res = result . res ;
60
- let data : string [ ] = [ ] ;
60
+ let data : any = [ ] ;
61
61
res . on ( 'data' , c => data . push ( c ) ) ;
62
62
res . on ( 'end' , ( ) => {
63
63
if ( options . followRedirects > 0 && ( res . statusCode >= 300 && res . statusCode <= 303 || res . statusCode === 307 ) ) {
@@ -129,8 +129,7 @@ function request(options: XHROptions): Promise<RequestResult> {
129
129
opts . auth = options . user + ':' + options . password ;
130
130
}
131
131
132
- let protocol = endpoint . protocol === 'https:' ? https : http ;
133
- req = protocol . request ( opts , ( res : http . ClientResponse ) => {
132
+ let handler = ( res : http . ClientResponse ) => {
134
133
if ( res . statusCode >= 300 && res . statusCode < 400 && options . followRedirects && options . followRedirects > 0 && res . headers [ 'location' ] ) {
135
134
c ( < any > request ( assign ( { } , options , {
136
135
url : res . headers [ 'location' ] ,
@@ -139,7 +138,13 @@ function request(options: XHROptions): Promise<RequestResult> {
139
138
} else {
140
139
c ( { req, res } ) ;
141
140
}
142
- } ) ;
141
+ }
142
+ if ( endpoint . protocol === 'https:' ) {
143
+ req = https . request ( opts , handler ) ;
144
+ } else {
145
+ req = http . request ( opts , handler ) ;
146
+ }
147
+
143
148
req . on ( 'error' , e ) ;
144
149
145
150
if ( options . timeout ) {
Original file line number Diff line number Diff line change 6
6
"sourceMap" : true ,
7
7
"declaration" : true ,
8
8
"stripInternal" : true ,
9
- "outDir" : " ../lib"
9
+ "outDir" : " ../lib" ,
10
+ "lib" : [
11
+ " es5" ,
12
+ " es2015.promise"
13
+ ]
10
14
}
11
15
}
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments