[Rt-commit] rt branch, 4.2/mailgate-post-redirect, created. rt-4.2.3-87-g584cb53

? sunnavy sunnavy at bestpractical.com
Fri Apr 18 12:23:07 EDT 2014


The branch, 4.2/mailgate-post-redirect has been created
        at  584cb532c1f68beab3cbd569bda053e4833c8d58 (commit)

- Log -----------------------------------------------------------------
commit 584cb532c1f68beab3cbd569bda053e4833c8d58
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Fri Apr 18 23:58:57 2014 +0800

    follow redirects(up to 3 times) for post requests in mailgate
    
    in case http server is configured to redirect http requests to https requests
    or something like that.
    
    we can't simply "push @{ $ua−>requests_redirectable }, 'POST';" because for a
    302/303 redirect, LWP performs an empty GET request instead of re-POSTing the
    original content. see also #14114

diff --git a/bin/rt-mailgate.in b/bin/rt-mailgate.in
index b270c4c..8547f63 100644
--- a/bin/rt-mailgate.in
+++ b/bin/rt-mailgate.in
@@ -218,6 +218,14 @@ sub upload_message {
 
     $ua->timeout( exists( $opts->{'timeout'} ) ? $opts->{'timeout'} : 180 );
     my $r = $ua->post( $full_url, $post_params, Content_Type => 'form-data' );
+
+    # Follow 3 redirects
+    my $n = 0;
+    while ($n++ < 3 and $r->is_redirect) {
+        $full_url = $r->header( "Location" );
+        $r = $ua->post( $full_url, $post_params, Content_Type => 'form-data' );
+    }
+
     $self->check_failure($r);
 
     my $content = $r->content;

-----------------------------------------------------------------------


More information about the rt-commit mailing list