@@ -28,7 +28,7 @@ use super::cookie_store::CookieStore;
2828use super :: header:: { Header , HeaderVec , CONTENT_TYPE } ;
2929use super :: options:: ClientOptions ;
3030use super :: param:: Param ;
31- use super :: request:: { IpResolve , RequestedHttpVersion } ;
31+ use super :: request:: { CredentialForwarding , FollowLocation , IpResolve , RequestedHttpVersion } ;
3232use super :: request_spec:: { Body , FileParam , Method , MultipartParam , RequestSpec } ;
3333
3434/// Represents a curl command, with arguments.
@@ -93,7 +93,7 @@ impl CurlCmd {
9393}
9494
9595/// Returns the curl args corresponding to the HTTP method, from a request spec.
96- fn method_params ( request_spec : & RequestSpec , follow_location : bool ) -> Vec < String > {
96+ fn method_params ( request_spec : & RequestSpec , follow_location : FollowLocation ) -> Vec < String > {
9797 let has_body = !request_spec. multipart . is_empty ( )
9898 || !request_spec. form . is_empty ( )
9999 || !request_spec. body . bytes ( ) . is_empty ( ) ;
@@ -294,7 +294,7 @@ fn encode_bytes(bytes: &[u8]) -> String {
294294
295295impl Method {
296296 /// Returns the curl args for HTTP method, given the request has a body or not.
297- fn curl_args ( & self , has_body : bool , follow_location : bool ) -> Vec < String > {
297+ fn curl_args ( & self , has_body : bool , follow_location : FollowLocation ) -> Vec < String > {
298298 match self . 0 . as_str ( ) {
299299 "GET" => {
300300 if has_body {
@@ -317,7 +317,7 @@ impl Method {
317317 // method of the redirection steps.
318318 if has_body {
319319 vec ! [ ]
320- } else if follow_location {
320+ } else if matches ! ( follow_location, FollowLocation :: Follow ( _ ) ) {
321321 vec ! [ "--data" . to_string( ) , "''" . to_string( ) ]
322322 } else {
323323 vec ! [ "--request" . to_string( ) , "POST" . to_string( ) ]
@@ -442,10 +442,14 @@ impl ClientOptions {
442442 IpResolve :: IpV4 => arguments. push ( "--ipv4" . to_string ( ) ) ,
443443 IpResolve :: IpV6 => arguments. push ( "--ipv6" . to_string ( ) ) ,
444444 }
445- if self . follow_location_trusted {
446- arguments. push ( "--location-trusted" . to_string ( ) ) ;
447- } else if self . follow_location {
448- arguments. push ( "--location" . to_string ( ) ) ;
445+ match self . follow_location {
446+ FollowLocation :: Follow ( CredentialForwarding :: OnlyInitialHost ) => {
447+ arguments. push ( "--location" . to_string ( ) ) ;
448+ }
449+ FollowLocation :: Follow ( CredentialForwarding :: AllHosts ) => {
450+ arguments. push ( "--location-trusted" . to_string ( ) ) ;
451+ }
452+ FollowLocation :: No => { }
449453 }
450454 if let Some ( max_filesize) = self . max_filesize {
451455 arguments. push ( "--max-filesize" . to_string ( ) ) ;
@@ -682,8 +686,7 @@ mod tests {
682686 connects_to : vec ! [ "example.com:443:host-47.example.com:443" . to_string( ) ] ,
683687 cookie_input_file : Some ( "cookie_file" . to_string ( ) ) ,
684688 digest : false ,
685- follow_location : true ,
686- follow_location_trusted : false ,
689+ follow_location : FollowLocation :: Follow ( CredentialForwarding :: OnlyInitialHost ) ,
687690 headers,
688691 http_version : RequestedHttpVersion :: Http10 ,
689692 insecure : true ,
0 commit comments