@@ -63,15 +63,18 @@ function Request(uri, options) {
6363 console . log ( "Building multipart request without Content-Length header, please specify all file sizes" ) ;
6464 }
6565 } else {
66- if ( typeof this . options . data == 'object' ) {
67- this . options . data = qs . stringify ( this . options . data ) ;
68- this . headers [ 'Content-Type' ] = 'application/x-www-form-urlencoded' ;
69- this . headers [ 'Content-Length' ] = this . options . data . length ;
70- }
71- if ( typeof this . options . data == 'string' ) {
72- var buffer = new Buffer ( this . options . data , this . options . encoding || 'utf8' ) ;
73- this . options . data = buffer ;
74- this . headers [ 'Content-Length' ] = buffer . length ;
66+ if ( ! this . data ) {
67+ this . data = this . options . data ;
68+ if ( typeof this . data == 'object' ) {
69+ this . data = qs . stringify ( this . data ) ;
70+ this . headers [ 'Content-Type' ] = 'application/x-www-form-urlencoded' ;
71+ this . headers [ 'Content-Length' ] = this . data . length ;
72+ }
73+ if ( typeof this . data == 'string' ) {
74+ var buffer = new Buffer ( this . data , this . options . encoding || 'utf8' ) ;
75+ this . data = buffer ;
76+ this . headers [ 'Content-Length' ] = buffer . length ;
77+ }
7578 }
7679 }
7780
@@ -125,6 +128,7 @@ mixin(Request.prototype, {
125128 self . url = url . parse ( url . resolve ( self . url . href , response . headers [ 'location' ] ) ) ;
126129 self . options . method = 'GET' ;
127130 delete self . options . data ;
131+ delete self . data ;
128132 self . _retry ( ) ;
129133 } else {
130134 self . url = url . parse ( url . resolve ( self . url . href , response . headers [ 'location' ] ) ) ;
@@ -239,12 +243,12 @@ mixin(Request.prototype, {
239243 run : function ( ) {
240244 var self = this ;
241245 if ( this . options . multipart ) {
242- multipart . write ( this . request , this . options . data , function ( ) {
246+ multipart . write ( this . request , this . data , function ( ) {
243247 self . request . end ( ) ;
244248 } ) ;
245249 } else {
246- if ( this . options . data ) {
247- this . request . write ( this . options . data . toString ( ) , this . options . encoding || 'utf8' ) ;
250+ if ( this . data ) {
251+ this . request . write ( this . data . toString ( ) , this . options . encoding || 'utf8' ) ;
248252 }
249253 this . request . end ( ) ;
250254 }
0 commit comments