@@ -571,6 +571,10 @@ pub struct Auth {
571
571
pub struct SslOpt {
572
572
bits : c_long ,
573
573
}
574
+ /// Structure which stores possible post redirection options to pass to `post_redirections`.
575
+ pub struct PostRedirections {
576
+ bits : c_ulong ,
577
+ }
574
578
575
579
impl < H : Handler > Easy2 < H > {
576
580
/// Creates a new "easy" handle which is the core of almost all operations
@@ -1474,7 +1478,14 @@ impl<H> Easy2<H> {
1474
1478
self . setopt_long ( curl_sys:: CURLOPT_MAXREDIRS , max as c_long )
1475
1479
}
1476
1480
1477
- // TODO: post_redirections
1481
+ /// Set the policy for handling redirects to POST requests.
1482
+ ///
1483
+ /// By default a POST is changed to a GET when following a redirect. Setting any
1484
+ /// of the `PostRedirections` flags will preserve the POST method for the
1485
+ /// selected response codes.
1486
+ pub fn post_redirections ( & mut self , redirects : & PostRedirections ) -> Result < ( ) , Error > {
1487
+ self . setopt_long ( curl_sys:: CURLOPT_POSTREDIR , redirects. bits as c_long )
1488
+ }
1478
1489
1479
1490
/// Make an HTTP PUT request.
1480
1491
///
@@ -3911,3 +3922,66 @@ impl fmt::Debug for SslOpt {
3911
3922
. finish ( )
3912
3923
}
3913
3924
}
3925
+
3926
+ impl PostRedirections {
3927
+ /// Create an empty PostRedirection setting with no flags set.
3928
+ pub fn new ( ) -> PostRedirections {
3929
+ PostRedirections { bits : 0 }
3930
+ }
3931
+
3932
+ /// Configure POST method behaviour on a 301 redirect. Setting the value
3933
+ /// to true will preserve the method when following the redirect, else
3934
+ /// the method is changed to GET.
3935
+ pub fn redirect_301 ( & mut self , on : bool ) -> & mut PostRedirections {
3936
+ self . flag ( curl_sys:: CURL_REDIR_POST_301 , on)
3937
+ }
3938
+
3939
+ /// Configure POST method behaviour on a 302 redirect. Setting the value
3940
+ /// to true will preserve the method when following the redirect, else
3941
+ /// the method is changed to GET.
3942
+ pub fn redirect_302 ( & mut self , on : bool ) -> & mut PostRedirections {
3943
+ self . flag ( curl_sys:: CURL_REDIR_POST_302 , on)
3944
+ }
3945
+
3946
+ /// Configure POST method behaviour on a 303 redirect. Setting the value
3947
+ /// to true will preserve the method when following the redirect, else
3948
+ /// the method is changed to GET.
3949
+ pub fn redirect_303 ( & mut self , on : bool ) -> & mut PostRedirections {
3950
+ self . flag ( curl_sys:: CURL_REDIR_POST_303 , on)
3951
+ }
3952
+
3953
+ /// Configure POST method behaviour for all redirects. Setting the value
3954
+ /// to true will preserve the method when following the redirect, else
3955
+ /// the method is changed to GET.
3956
+ pub fn redirect_all ( & mut self , on : bool ) -> & mut PostRedirections {
3957
+ self . flag ( curl_sys:: CURL_REDIR_POST_ALL , on)
3958
+ }
3959
+
3960
+ fn flag ( & mut self , bit : c_ulong , on : bool ) -> & mut PostRedirections {
3961
+ if on {
3962
+ self . bits |= bit;
3963
+ } else {
3964
+ self . bits &= !bit;
3965
+ }
3966
+ self
3967
+ }
3968
+ }
3969
+
3970
+ impl fmt:: Debug for PostRedirections {
3971
+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
3972
+ f. debug_struct ( "PostRedirections" )
3973
+ . field (
3974
+ "redirect_301" ,
3975
+ & ( self . bits & curl_sys:: CURL_REDIR_POST_301 != 0 ) ,
3976
+ )
3977
+ . field (
3978
+ "redirect_302" ,
3979
+ & ( self . bits & curl_sys:: CURL_REDIR_POST_302 != 0 ) ,
3980
+ )
3981
+ . field (
3982
+ "redirect_303" ,
3983
+ & ( self . bits & curl_sys:: CURL_REDIR_POST_303 != 0 ) ,
3984
+ )
3985
+ . finish ( )
3986
+ }
3987
+ }
0 commit comments