@@ -295,24 +295,7 @@ def assume_utf16_is_big_endian
295
295
296
296
def handle_response ( raw_body , &block )
297
297
if response_redirects?
298
- options [ :limit ] -= 1
299
- if options [ :logger ]
300
- logger = HTTParty ::Logger . build ( options [ :logger ] , options [ :log_level ] , options [ :log_format ] )
301
- logger . format ( self , last_response )
302
- end
303
- self . path = last_response [ 'location' ]
304
- self . redirect = true
305
- if last_response . class == Net ::HTTPSeeOther
306
- unless options [ :maintain_method_across_redirects ] && options [ :resend_on_redirect ]
307
- self . http_method = Net ::HTTP ::Get
308
- end
309
- elsif last_response . code != '307' && last_response . code != '308'
310
- unless options [ :maintain_method_across_redirects ]
311
- self . http_method = Net ::HTTP ::Get
312
- end
313
- end
314
- capture_cookies ( last_response )
315
- perform ( &block )
298
+ handle_redirection ( &block )
316
299
else
317
300
raw_body ||= last_response . body
318
301
@@ -331,6 +314,30 @@ def handle_response(raw_body, &block)
331
314
end
332
315
end
333
316
317
+ def handle_redirection ( &block )
318
+ options [ :limit ] -= 1
319
+ if options [ :logger ]
320
+ logger = HTTParty ::Logger . build ( options [ :logger ] , options [ :log_level ] , options [ :log_format ] )
321
+ logger . format ( self , last_response )
322
+ end
323
+ self . path = last_response [ 'location' ]
324
+ self . redirect = true
325
+ if last_response . class == Net ::HTTPSeeOther
326
+ unless options [ :maintain_method_across_redirects ] && options [ :resend_on_redirect ]
327
+ self . http_method = Net ::HTTP ::Get
328
+ end
329
+ elsif last_response . code != '307' && last_response . code != '308'
330
+ unless options [ :maintain_method_across_redirects ]
331
+ self . http_method = Net ::HTTP ::Get
332
+ end
333
+ end
334
+ if http_method == Net ::HTTP ::Get
335
+ clear_body
336
+ end
337
+ capture_cookies ( last_response )
338
+ perform ( &block )
339
+ end
340
+
334
341
def handle_host_redirection
335
342
check_duplicate_location_header
336
343
redirect_path = options [ :uri_adapter ] . parse ( last_response [ 'location' ] ) . normalize
@@ -362,6 +369,14 @@ def parse_response(body)
362
369
parser . call ( body , format )
363
370
end
364
371
372
+ # Some Web Application Firewalls reject incoming GET requests that have a body
373
+ # if we redirect, and the resulting verb is GET then we will clear the body that
374
+ # may be left behind from the initiating request
375
+ def clear_body
376
+ options [ :body ] = nil
377
+ @raw_request . body = nil
378
+ end
379
+
365
380
def capture_cookies ( response )
366
381
return unless response [ 'Set-Cookie' ]
367
382
cookies_hash = HTTParty ::CookieHash . new
0 commit comments