@@ -83,19 +83,20 @@ static struct aws_log_subject_info_list s_log_subject_list = {
8383 * Key is aws_byte_cursor* (pointing into cursor from array) and comparisons are case-insensitive.
8484 * Value is the array index cast to a void*.
8585 */
86- static void s_init_case_insensitive_hash_table (
86+ static void s_init_str_to_enum_hash_table (
8787 struct aws_hash_table * table ,
8888 struct aws_allocator * alloc ,
8989 struct aws_byte_cursor * str_array ,
9090 int start_index ,
91- int end_index ) {
91+ int end_index ,
92+ bool ignore_case ) {
9293
9394 int err = aws_hash_table_init (
9495 table ,
9596 alloc ,
9697 end_index - start_index ,
97- aws_hash_byte_cursor_ptr_ignore_case ,
98- (aws_hash_callback_eq_fn * )aws_byte_cursor_eq_ignore_case ,
98+ ignore_case ? aws_hash_byte_cursor_ptr_ignore_case : aws_hash_byte_cursor_ptr ,
99+ (aws_hash_callback_eq_fn * )( ignore_case ? aws_byte_cursor_eq_ignore_case : aws_byte_cursor_eq ) ,
99100 NULL ,
100101 NULL );
101102 AWS_FATAL_ASSERT (!err );
@@ -108,10 +109,10 @@ static void s_init_case_insensitive_hash_table(
108109}
109110
110111/**
111- * Given key, get value from table initialized by s_init_case_insensitive_hash_table ().
112+ * Given key, get value from table initialized by s_init_str_to_enum_hash_table ().
112113 * Returns -1 if key not found.
113114 */
114- static int s_find_in_case_insensitive_hash_table (const struct aws_hash_table * table , struct aws_byte_cursor * key ) {
115+ static int s_find_in_str_to_enum_hash_table (const struct aws_hash_table * table , struct aws_byte_cursor * key ) {
115116 struct aws_hash_element * elem ;
116117 aws_hash_table_find (table , key , & elem );
117118 if (elem ) {
@@ -127,16 +128,21 @@ static struct aws_byte_cursor s_method_enum_to_str[AWS_HTTP_METHOD_COUNT]; /* fo
127128static void s_methods_init (struct aws_allocator * alloc ) {
128129 s_method_enum_to_str [AWS_HTTP_METHOD_HEAD ] = aws_byte_cursor_from_c_str ("HEAD" );
129130
130- s_init_case_insensitive_hash_table (
131- & s_method_str_to_enum , alloc , s_method_enum_to_str , AWS_HTTP_METHOD_UNKNOWN + 1 , AWS_HTTP_METHOD_COUNT );
131+ s_init_str_to_enum_hash_table (
132+ & s_method_str_to_enum ,
133+ alloc ,
134+ s_method_enum_to_str ,
135+ AWS_HTTP_METHOD_UNKNOWN + 1 ,
136+ AWS_HTTP_METHOD_COUNT ,
137+ false /* DO NOT ignore case of method */ );
132138}
133139
134140static void s_methods_clean_up (void ) {
135141 aws_hash_table_clean_up (& s_method_str_to_enum );
136142}
137143
138144enum aws_http_method aws_http_str_to_method (struct aws_byte_cursor cursor ) {
139- int method = s_find_in_case_insensitive_hash_table (& s_method_str_to_enum , & cursor );
145+ int method = s_find_in_str_to_enum_hash_table (& s_method_str_to_enum , & cursor );
140146 if (method >= 0 ) {
141147 return (enum aws_http_method )method ;
142148 }
@@ -173,16 +179,21 @@ static void s_headers_init(struct aws_allocator *alloc) {
173179 s_header_enum_to_str [AWS_HTTP_HEADER_CONTENT_LENGTH ] = aws_byte_cursor_from_c_str ("content-length" );
174180 s_header_enum_to_str [AWS_HTTP_HEADER_EXPECT ] = aws_byte_cursor_from_c_str ("expect" );
175181
176- s_init_case_insensitive_hash_table (
177- & s_header_str_to_enum , alloc , s_header_enum_to_str , AWS_HTTP_HEADER_UNKNOWN + 1 , AWS_HTTP_HEADER_COUNT );
182+ s_init_str_to_enum_hash_table (
183+ & s_header_str_to_enum ,
184+ alloc ,
185+ s_header_enum_to_str ,
186+ AWS_HTTP_HEADER_UNKNOWN + 1 ,
187+ AWS_HTTP_HEADER_COUNT ,
188+ true /* ignore case */ );
178189}
179190
180191static void s_headers_clean_up (void ) {
181192 aws_hash_table_clean_up (& s_header_str_to_enum );
182193}
183194
184195enum aws_http_header_name aws_http_str_to_header_name (struct aws_byte_cursor cursor ) {
185- int header = s_find_in_case_insensitive_hash_table (& s_header_str_to_enum , & cursor );
196+ int header = s_find_in_str_to_enum_hash_table (& s_header_str_to_enum , & cursor );
186197 if (header >= 0 ) {
187198 return (enum aws_http_header_name )header ;
188199 }
0 commit comments