@@ -71,13 +71,20 @@ impl HttpAuthType {
7171 fn from_value ( input : & Value ) -> Result < HttpAuthType , String > {
7272 match input. kind . as_ref ( ) {
7373 Some ( Kind :: NullValue ( _) ) | None => Ok ( HttpAuthType :: None ) ,
74- Some ( Kind :: StringValue ( value) ) => match value. as_str ( ) {
75- "Bearer" => Ok ( HttpAuthType :: Bearer ) ,
76- "Basic" => Ok ( HttpAuthType :: Basic ) ,
77- "X-API-Key" => Ok ( HttpAuthType :: XApiKey ) ,
78- "undefined" | "" => Ok ( HttpAuthType :: None ) ,
79- custom => Ok ( HttpAuthType :: Custom ( custom. to_string ( ) ) ) ,
80- } ,
74+ Some ( Kind :: StringValue ( value) ) => {
75+ if value. eq_ignore_ascii_case ( "bearer" ) {
76+ Ok ( HttpAuthType :: Bearer )
77+ } else if value. eq_ignore_ascii_case ( "basic" ) {
78+ Ok ( HttpAuthType :: Basic )
79+ } else if value. eq_ignore_ascii_case ( "x-api-key" ) {
80+ Ok ( HttpAuthType :: XApiKey )
81+ } else {
82+ match value. as_str ( ) {
83+ "undefined" | "" => Ok ( HttpAuthType :: None ) ,
84+ custom => Ok ( HttpAuthType :: Custom ( custom. to_string ( ) ) ) ,
85+ }
86+ }
87+ }
8188 _ => Err ( "Auth Type must be a string or undefined" . to_string ( ) ) ,
8289 }
8390 }
@@ -335,9 +342,7 @@ fn apply_auth(
335342 HttpAuthType :: Custom ( scheme) => {
336343 let value = auth_string_value ( auth_value, "Custom auth value" ) ?;
337344 match place {
338- HttpAuthPlace :: Header => {
339- insert_header ( headers, "authorization" , format ! ( "{} {}" , scheme, value) )
340- }
345+ HttpAuthPlace :: Header => insert_header ( headers, "authorization" , value) ,
341346 HttpAuthPlace :: Url => append_query_param ( url, scheme, & value) ,
342347 }
343348 Ok ( ( ) )
@@ -677,6 +682,22 @@ mod tests {
677682 assert_eq ! ( url, "https://example.test/resource?X-API-Key=a%20b" ) ;
678683 }
679684
685+ #[ test]
686+ fn auth_type_parses_builtin_values_case_insensitively ( ) {
687+ assert_eq ! (
688+ HttpAuthType :: from_value( & string_value( "bearer" ) ) ,
689+ Ok ( HttpAuthType :: Bearer )
690+ ) ;
691+ assert_eq ! (
692+ HttpAuthType :: from_value( & string_value( "basic" ) ) ,
693+ Ok ( HttpAuthType :: Basic )
694+ ) ;
695+ assert_eq ! (
696+ HttpAuthType :: from_value( & string_value( "x-api-key" ) ) ,
697+ Ok ( HttpAuthType :: XApiKey )
698+ ) ;
699+ }
700+
680701 #[ test]
681702 fn encode_headers_rejects_null_values ( ) {
682703 let headers = Struct {
0 commit comments