@@ -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 }
@@ -93,15 +100,21 @@ impl HttpAuthPlace {
93100 fn from_value ( input : & Value ) -> Result < Option < HttpAuthPlace > , String > {
94101 match input. kind . as_ref ( ) {
95102 Some ( Kind :: NullValue ( _) ) | None => Ok ( None ) ,
96- Some ( Kind :: StringValue ( value) ) => match value. as_str ( ) {
97- "Header" => Ok ( Some ( HttpAuthPlace :: Header ) ) ,
98- "Url" => Ok ( Some ( HttpAuthPlace :: Url ) ) ,
99- "undefined" | "" => Ok ( None ) ,
100- other => Err ( format ! (
101- "Auth Placement must be 'Header', 'Url', or undefined, got '{}'" ,
102- other
103- ) ) ,
104- } ,
103+ Some ( Kind :: StringValue ( value) ) => {
104+ if value. eq_ignore_ascii_case ( "header" ) {
105+ Ok ( Some ( HttpAuthPlace :: Header ) )
106+ } else if value. eq_ignore_ascii_case ( "url" ) {
107+ Ok ( Some ( HttpAuthPlace :: Url ) )
108+ } else {
109+ match value. as_str ( ) {
110+ "undefined" | "" => Ok ( None ) ,
111+ other => Err ( format ! (
112+ "Auth Placement must be 'Header', 'Url', or undefined, got '{}'" ,
113+ other
114+ ) ) ,
115+ }
116+ }
117+ }
105118 _ => Err ( "Auth Placement must be a string or undefined" . to_string ( ) ) ,
106119 }
107120 }
@@ -335,9 +348,7 @@ fn apply_auth(
335348 HttpAuthType :: Custom ( scheme) => {
336349 let value = auth_string_value ( auth_value, "Custom auth value" ) ?;
337350 match place {
338- HttpAuthPlace :: Header => {
339- insert_header ( headers, "authorization" , format ! ( "{} {}" , scheme, value) )
340- }
351+ HttpAuthPlace :: Header => insert_header ( headers, "authorization" , value) ,
341352 HttpAuthPlace :: Url => append_query_param ( url, scheme, & value) ,
342353 }
343354 Ok ( ( ) )
@@ -677,6 +688,34 @@ mod tests {
677688 assert_eq ! ( url, "https://example.test/resource?X-API-Key=a%20b" ) ;
678689 }
679690
691+ #[ test]
692+ fn auth_type_parses_builtin_values_case_insensitively ( ) {
693+ assert_eq ! (
694+ HttpAuthType :: from_value( & string_value( "bearer" ) ) ,
695+ Ok ( HttpAuthType :: Bearer )
696+ ) ;
697+ assert_eq ! (
698+ HttpAuthType :: from_value( & string_value( "basic" ) ) ,
699+ Ok ( HttpAuthType :: Basic )
700+ ) ;
701+ assert_eq ! (
702+ HttpAuthType :: from_value( & string_value( "x-api-key" ) ) ,
703+ Ok ( HttpAuthType :: XApiKey )
704+ ) ;
705+ }
706+
707+ #[ test]
708+ fn auth_place_parses_values_case_insensitively ( ) {
709+ assert_eq ! (
710+ HttpAuthPlace :: from_value( & string_value( "header" ) ) ,
711+ Ok ( Some ( HttpAuthPlace :: Header ) )
712+ ) ;
713+ assert_eq ! (
714+ HttpAuthPlace :: from_value( & string_value( "url" ) ) ,
715+ Ok ( Some ( HttpAuthPlace :: Url ) )
716+ ) ;
717+ }
718+
680719 #[ test]
681720 fn encode_headers_rejects_null_values ( ) {
682721 let headers = Struct {
0 commit comments