@@ -367,7 +367,10 @@ static int s_set_string_from_cursor(
367367 * dst = new_str ;
368368 return AWS_OP_SUCCESS ;
369369}
370- static struct aws_http_message * s_message_new_common (struct aws_allocator * allocator ) {
370+ static struct aws_http_message * s_message_new_common (
371+ struct aws_allocator * allocator ,
372+ struct aws_http_headers * existing_headers ) {
373+
371374 struct aws_http_message * message = aws_mem_calloc (allocator , 1 , sizeof (struct aws_http_message ));
372375 if (!message ) {
373376 goto error ;
@@ -376,9 +379,14 @@ static struct aws_http_message *s_message_new_common(struct aws_allocator *alloc
376379 message -> allocator = allocator ;
377380 aws_atomic_init_int (& message -> refcount , 1 );
378381
379- message -> headers = aws_http_headers_new (allocator );
380- if (!message -> headers ) {
381- goto error ;
382+ if (existing_headers ) {
383+ message -> headers = existing_headers ;
384+ aws_http_headers_acquire (message -> headers );
385+ } else {
386+ message -> headers = aws_http_headers_new (allocator );
387+ if (!message -> headers ) {
388+ goto error ;
389+ }
382390 }
383391
384392 return message ;
@@ -387,20 +395,36 @@ static struct aws_http_message *s_message_new_common(struct aws_allocator *alloc
387395 return NULL ;
388396}
389397
390- struct aws_http_message * aws_http_message_new_request (struct aws_allocator * allocator ) {
391- AWS_PRECONDITION (allocator );
398+ static struct aws_http_message * s_message_new_request_common (
399+ struct aws_allocator * allocator ,
400+ struct aws_http_headers * existing_headers ) {
392401
393- struct aws_http_message * message = s_message_new_common (allocator );
402+ struct aws_http_message * message = s_message_new_common (allocator , existing_headers );
394403 if (message ) {
395404 message -> request_data = & message -> subclass_data .request ;
396405 }
397406 return message ;
398407}
399408
409+ struct aws_http_message * aws_http_message_new_request_with_headers (
410+ struct aws_allocator * allocator ,
411+ struct aws_http_headers * existing_headers ) {
412+
413+ AWS_PRECONDITION (allocator );
414+ AWS_PRECONDITION (existing_headers );
415+
416+ return s_message_new_request_common (allocator , existing_headers );
417+ }
418+
419+ struct aws_http_message * aws_http_message_new_request (struct aws_allocator * allocator ) {
420+ AWS_PRECONDITION (allocator );
421+ return s_message_new_request_common (allocator , NULL );
422+ }
423+
400424struct aws_http_message * aws_http_message_new_response (struct aws_allocator * allocator ) {
401425 AWS_PRECONDITION (allocator );
402426
403- struct aws_http_message * message = s_message_new_common (allocator );
427+ struct aws_http_message * message = s_message_new_common (allocator , NULL );
404428 if (message ) {
405429 message -> response_data = & message -> subclass_data .response ;
406430 message -> response_data -> status = AWS_HTTP_STATUS_UNKNOWN ;
0 commit comments