@@ -119,9 +119,18 @@ mixin(Request.prototype, {
119119
120120 if ( self . _isRedirect ( response ) && self . options . followRedirects ) {
121121 try {
122- self . url = url . parse ( url . resolve ( self . url . href , response . headers [ 'location' ] ) ) ;
123- self . _retry ( ) ;
124- // todo handle somehow infinite redirects
122+ // 303 should redirect and retrieve content with the GET method
123+ // http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.4
124+ if ( response . statusCode === 303 ) {
125+ self . url = url . parse ( url . resolve ( self . url . href , response . headers [ 'location' ] ) ) ;
126+ self . options . method = 'GET' ;
127+ delete self . options . data ;
128+ self . _retry ( ) ;
129+ } else {
130+ self . url = url . parse ( url . resolve ( self . url . href , response . headers [ 'location' ] ) ) ;
131+ self . _retry ( ) ;
132+ // todo handle somehow infinite redirects
133+ }
125134 } catch ( err ) {
126135 err . message = 'Failed to follow redirect: ' + err . message ;
127136 self . _fireError ( err , response ) ;
@@ -229,7 +238,6 @@ mixin(Request.prototype, {
229238 } ,
230239 run : function ( ) {
231240 var self = this ;
232-
233241 if ( this . options . multipart ) {
234242 multipart . write ( this . request , this . options . data , function ( ) {
235243 self . request . end ( ) ;
@@ -326,7 +334,7 @@ function json(url, data, options, method) {
326334 options . parser = ( typeof options . parser !== "undefined" ) ? options . parser : parsers . auto ;
327335 options . headers = options . headers || { } ;
328336 options . headers [ 'content-type' ] = 'application/json' ;
329- options . data = JSON . stringify ( data ) ;
337+ options . data = JSON . stringify ( data || { } ) ;
330338 options . method = method || 'GET' ;
331339 return request ( url , options ) ;
332340}
@@ -497,3 +505,4 @@ mixin(exports, {
497505 file : multipart . file ,
498506 data : multipart . data
499507} ) ;
508+
0 commit comments