@@ -367,7 +367,10 @@ static int s_set_string_from_cursor(
367
367
* dst = new_str ;
368
368
return AWS_OP_SUCCESS ;
369
369
}
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
+
371
374
struct aws_http_message * message = aws_mem_calloc (allocator , 1 , sizeof (struct aws_http_message ));
372
375
if (!message ) {
373
376
goto error ;
@@ -376,9 +379,14 @@ static struct aws_http_message *s_message_new_common(struct aws_allocator *alloc
376
379
message -> allocator = allocator ;
377
380
aws_atomic_init_int (& message -> refcount , 1 );
378
381
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
+ }
382
390
}
383
391
384
392
return message ;
@@ -387,20 +395,36 @@ static struct aws_http_message *s_message_new_common(struct aws_allocator *alloc
387
395
return NULL ;
388
396
}
389
397
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 ) {
392
401
393
- struct aws_http_message * message = s_message_new_common (allocator );
402
+ struct aws_http_message * message = s_message_new_common (allocator , existing_headers );
394
403
if (message ) {
395
404
message -> request_data = & message -> subclass_data .request ;
396
405
}
397
406
return message ;
398
407
}
399
408
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
+
400
424
struct aws_http_message * aws_http_message_new_response (struct aws_allocator * allocator ) {
401
425
AWS_PRECONDITION (allocator );
402
426
403
- struct aws_http_message * message = s_message_new_common (allocator );
427
+ struct aws_http_message * message = s_message_new_common (allocator , NULL );
404
428
if (message ) {
405
429
message -> response_data = & message -> subclass_data .response ;
406
430
message -> response_data -> status = AWS_HTTP_STATUS_UNKNOWN ;
0 commit comments