@@ -16,18 +16,10 @@ module.exports = function(Api) {
1616 options . path = path_module . join ( this . httpOptions . path , path ) ;
1717
1818 if ( fields . length !== 0 ) {
19- params [ " fields" ] = fields . join ( ) ;
19+ params [ ' fields' ] = fields . join ( ) ;
2020 }
2121 options . path += '?' + queryString . stringify ( params ) ;
2222
23- // Add xsrf header
24- //var xsrfValue = urlIsSameOrigin(config.url)
25- // ? cookies.read(config.xsrfCookieName || defaults.xsrfCookieName)
26- // : undefined;
27- //if (xsrfValue) {
28- // headers[config.xsrfHeaderName || defaults.xsrfHeaderName] = xsrfValue;
29- //}
30-
3123 return new Promise ( function ( resolve , reject ) {
3224 /*options = {
3325 hostname: 'echo.jsontest.com',
@@ -36,13 +28,15 @@ module.exports = function(Api) {
3628 withCredentials: false
3729 };*/
3830
39- var req = http . request ( options , function ( res ) {
31+ var request = http . request ( options , function ( response ) {
4032 var body = '' ;
41- //res.setEncoding('utf8');
42- res . on ( 'data' , function ( chunk ) {
33+ if ( typeof response . setEncoding === 'function' ) {
34+ response . setEncoding ( 'utf8' ) ;
35+ }
36+ response . on ( 'data' , function ( chunk ) {
4337 body += chunk ;
4438 } ) ;
45- res . on ( 'end' , function ( ) {
39+ response . on ( 'end' , function ( ) {
4640 var data = JSON . parse ( body ) ;
4741 if ( data . error ) {
4842 reject ( data ) ;
@@ -51,8 +45,8 @@ module.exports = function(Api) {
5145 }
5246 } ) ;
5347 } ) ;
54- req . on ( 'error' , reject ) ;
55- req . end ( ) ;
48+ request . on ( 'error' , reject ) ;
49+ request . end ( ) ;
5650 } ) ;
5751 } ;
5852} ;
0 commit comments