@@ -314,58 +314,22 @@ int aws_http_headers_get_index(
314314 return aws_array_list_get_at (& headers -> array_list , out_header , index );
315315}
316316
317- int aws_http_headers_get_single (
318- const struct aws_http_headers * headers ,
319- struct aws_byte_cursor name ,
320- struct aws_byte_cursor * out_value ) {
321-
322- AWS_PRECONDITION (headers );
323- AWS_PRECONDITION (out_value );
324- AWS_PRECONDITION (aws_byte_cursor_is_valid (& name ));
325-
326- AWS_ZERO_STRUCT (* out_value );
327-
328- bool found = false;
329- struct aws_byte_cursor value ;
330- AWS_ZERO_STRUCT (value );
331- struct aws_http_header * header = NULL ;
332- const size_t count = aws_http_headers_count (headers );
333- for (size_t i = 0 ; i < count ; ++ i ) {
334- aws_array_list_get_at_ptr (& headers -> array_list , (void * * )& header , i );
335- AWS_ASSUME (header );
336-
337- if (aws_http_header_name_eq (header -> name , name )) {
338- if (found ) {
339- return aws_raise_error (AWS_ERROR_HTTP_UNEXPECTED_DUPLICATE_HEADER );
340- }
341- value = header -> value ;
342- found = true;
343- }
344- }
345-
346- if (found ) {
347- * out_value = value ;
348- return AWS_OP_SUCCESS ;
349- } else {
350- return aws_raise_error (AWS_ERROR_HTTP_HEADER_NOT_FOUND );
351- }
352- }
353-
354- /* RFC-7230 - 3.2.2
355- * A recipient MAY combine multiple header fields with the same field name
356- * into one "field-name: field-value" pair, without changing the semantics
357- * of the message, by appending each subsequent field value to the combined
358- * field value in order, separated by a comma */
317+ /* RFC-9110 - 5.3
318+ * A recipient MAY combine multiple field lines within a field section that
319+ * have the same field name into one field line, without changing the semantics
320+ * of the message, by appending each subsequent field line value to the initial
321+ * field line value in order, separated by a comma (",") and optional whitespace
322+ * (OWS, defined in Section 5.6.3). For consistency, use comma SP. */
359323AWS_HTTP_API
360- struct aws_string * aws_http_headers_get_comma_separated (
361- const struct aws_http_headers * headers ,
362- struct aws_byte_cursor name ) {
324+ struct aws_string * aws_http_headers_get_all (const struct aws_http_headers * headers , struct aws_byte_cursor name ) {
363325
364326 AWS_PRECONDITION (headers );
365327 AWS_PRECONDITION (aws_byte_cursor_is_valid (& name ));
366328
367329 struct aws_string * value_str = NULL ;
368330
331+ const struct aws_byte_cursor separator = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL (", " );
332+
369333 struct aws_byte_buf value_builder ;
370334 aws_byte_buf_init (& value_builder , headers -> alloc , 0 );
371335 bool found = false;
@@ -377,7 +341,7 @@ struct aws_string *aws_http_headers_get_comma_separated(
377341 if (!found ) {
378342 found = true;
379343 } else {
380- aws_byte_buf_append_byte_dynamic (& value_builder , ',' );
344+ aws_byte_buf_append_dynamic (& value_builder , & separator );
381345 }
382346 aws_byte_buf_append_dynamic (& value_builder , & header -> value );
383347 }
@@ -419,48 +383,38 @@ int aws_http_headers_get(
419383
420384bool aws_http_headers_has (const struct aws_http_headers * headers , struct aws_byte_cursor name ) {
421385
422- AWS_PRECONDITION (headers );
423- AWS_PRECONDITION (aws_byte_cursor_is_valid (& name ));
424-
425- struct aws_http_header * header = NULL ;
426- const size_t count = aws_http_headers_count (headers );
427- for (size_t i = 0 ; i < count ; ++ i ) {
428- aws_array_list_get_at_ptr (& headers -> array_list , (void * * )& header , i );
429- AWS_ASSUME (header );
430-
431- if (aws_http_header_name_eq (header -> name , name )) {
432- return true;
433- }
386+ struct aws_byte_cursor out_value ;
387+ if (aws_http_headers_get (headers , name , & out_value )) {
388+ return false;
434389 }
435-
436- return false;
390+ return true;
437391}
438392
439393int aws_http2_headers_get_request_method (
440394 const struct aws_http_headers * h2_headers ,
441395 struct aws_byte_cursor * out_method ) {
442- return aws_http_headers_get_single (h2_headers , aws_http_header_method , out_method );
396+ return aws_http_headers_get (h2_headers , aws_http_header_method , out_method );
443397}
444398
445399int aws_http2_headers_get_request_scheme (
446400 const struct aws_http_headers * h2_headers ,
447401 struct aws_byte_cursor * out_scheme ) {
448- return aws_http_headers_get_single (h2_headers , aws_http_header_scheme , out_scheme );
402+ return aws_http_headers_get (h2_headers , aws_http_header_scheme , out_scheme );
449403}
450404
451405int aws_http2_headers_get_request_authority (
452406 const struct aws_http_headers * h2_headers ,
453407 struct aws_byte_cursor * out_authority ) {
454- return aws_http_headers_get_single (h2_headers , aws_http_header_authority , out_authority );
408+ return aws_http_headers_get (h2_headers , aws_http_header_authority , out_authority );
455409}
456410
457411int aws_http2_headers_get_request_path (const struct aws_http_headers * h2_headers , struct aws_byte_cursor * out_path ) {
458- return aws_http_headers_get_single (h2_headers , aws_http_header_path , out_path );
412+ return aws_http_headers_get (h2_headers , aws_http_header_path , out_path );
459413}
460414
461415int aws_http2_headers_get_response_status (const struct aws_http_headers * h2_headers , int * out_status_code ) {
462416 struct aws_byte_cursor status_code_cur ;
463- int return_code = aws_http_headers_get_single (h2_headers , aws_http_header_status , & status_code_cur );
417+ int return_code = aws_http_headers_get (h2_headers , aws_http_header_status , & status_code_cur );
464418 if (return_code == AWS_OP_SUCCESS ) {
465419 uint64_t code_val_u64 ;
466420 if (aws_byte_cursor_utf8_parse_u64 (status_code_cur , & code_val_u64 )) {
@@ -1006,7 +960,7 @@ struct aws_http_message *aws_http2_message_new_from_http1(
1006960 */
1007961 struct aws_byte_cursor host_value ;
1008962 AWS_ZERO_STRUCT (host_value );
1009- if (aws_http_headers_get_single (http1_msg -> headers , aws_byte_cursor_from_c_str ("host" ), & host_value ) ==
963+ if (aws_http_headers_get (http1_msg -> headers , aws_byte_cursor_from_c_str ("host" ), & host_value ) ==
1010964 AWS_OP_SUCCESS ) {
1011965 if (aws_http_headers_add (copied_headers , aws_http_header_authority , host_value )) {
1012966 goto error ;
@@ -1018,14 +972,6 @@ struct aws_http_message *aws_http2_message_new_from_http1(
1018972 aws_http_header_authority .ptr ,
1019973 (int )host_value .len ,
1020974 host_value .ptr );
1021- } else if (aws_last_error () != AWS_ERROR_HTTP_HEADER_NOT_FOUND ) {
1022- AWS_LOGF_ERROR (
1023- AWS_LS_HTTP_GENERAL ,
1024- "Failed to create HTTP/2 message from HTTP/1 message, ip: %p, due to error with host header: %d %s" ,
1025- (void * )http1_msg ,
1026- aws_last_error (),
1027- aws_error_name (aws_last_error ()));
1028- goto error ;
1029975 }
1030976 /* TODO: If the host headers is missing, the target URI could be the other source of the authority information
1031977 */
0 commit comments