Skip to content

Commit f774425

Browse files
authored
http2 headers (#330)
### HTTP2 headers - pseudo headers are pushed into the front of the array list, and other than that, it will be treated the same as normal headers - Trade off: - We know that push front to the array list is expensive. But, it should be used only few times, as you don't want to change pseudo headers a lot and there are at most 4 of them. More than that, we don't need to do the push front later when we need to send the headers into the wire. - The advantage of it is that we will have the mostly the same behavior as netty, which is used by Java SDK team already. - `add` will push the pseudo header to the front of the list when needed (the last header is NOT pseudo header)
1 parent 07cac78 commit f774425

File tree

7 files changed

+420
-32
lines changed

7 files changed

+420
-32
lines changed

include/aws/http/private/strutil.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,5 +114,11 @@ bool aws_strutil_is_http_reason_phrase(struct aws_byte_cursor cursor);
114114
AWS_HTTP_API
115115
bool aws_strutil_is_http_request_target(struct aws_byte_cursor cursor);
116116

117+
/**
118+
* Return whether this ASCII/UTF-8 sequence start with ":" or not as the requirement for pseudo headers.
119+
*/
120+
AWS_HTTP_API
121+
bool aws_strutil_is_http_pseudo_header_name(struct aws_byte_cursor cursor);
122+
117123
AWS_EXTERN_C_END
118124
#endif /* AWS_HTTP_STRUTIL_H */

include/aws/http/request_response.h

Lines changed: 97 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -497,8 +497,77 @@ AWS_HTTP_API
497497
void aws_http_headers_clear(struct aws_http_headers *headers);
498498

499499
/**
500-
* Create a new request message.
500+
* Get the `:method` value (HTTP/2 headers only).
501+
*/
502+
AWS_HTTP_API
503+
int aws_http2_headers_get_request_method(const struct aws_http_headers *h2_headers, struct aws_byte_cursor *out_method);
504+
505+
/**
506+
* Set `:method` (HTTP/2 headers only).
507+
* The headers makes its own copy of the underlying string.
508+
*/
509+
AWS_HTTP_API
510+
int aws_http2_headers_set_request_method(struct aws_http_headers *h2_headers, struct aws_byte_cursor method);
511+
512+
/*
513+
* Get the `:scheme` value (HTTP/2 headers only).
514+
*/
515+
AWS_HTTP_API
516+
int aws_http2_headers_get_request_scheme(const struct aws_http_headers *h2_headers, struct aws_byte_cursor *out_scheme);
517+
518+
/**
519+
* Set `:scheme` (request pseudo headers only).
520+
* The pseudo headers makes its own copy of the underlying string.
521+
*/
522+
AWS_HTTP_API
523+
int aws_http2_headers_set_request_scheme(struct aws_http_headers *h2_headers, struct aws_byte_cursor scheme);
524+
525+
/*
526+
* Get the `:authority` value (request pseudo headers only).
527+
*/
528+
AWS_HTTP_API
529+
int aws_http2_headers_get_request_authority(
530+
const struct aws_http_headers *h2_headers,
531+
struct aws_byte_cursor *out_authority);
532+
533+
/**
534+
* Set `:authority` (request pseudo headers only).
535+
* The pseudo headers makes its own copy of the underlying string.
536+
*/
537+
AWS_HTTP_API
538+
int aws_http2_headers_set_request_authority(struct aws_http_headers *h2_headers, struct aws_byte_cursor authority);
539+
540+
/*
541+
* Get the `:path` value (request pseudo headers only).
542+
*/
543+
AWS_HTTP_API
544+
int aws_http2_headers_get_request_path(const struct aws_http_headers *h2_headers, struct aws_byte_cursor *out_path);
545+
546+
/**
547+
* Set `:path` (request pseudo headers only).
548+
* The pseudo headers makes its own copy of the underlying string.
549+
*/
550+
AWS_HTTP_API
551+
int aws_http2_headers_set_request_path(struct aws_http_headers *h2_headers, struct aws_byte_cursor path);
552+
553+
/**
554+
* Get `:status` (response pseudo headers only).
555+
* If no status is set, AWS_ERROR_HTTP_DATA_NOT_AVAILABLE is raised.
556+
*/
557+
AWS_HTTP_API
558+
int aws_http2_headers_get_response_status(const struct aws_http_headers *h2_headers, int *out_status_code);
559+
560+
/**
561+
* Set `:status` (response pseudo headers only).
562+
*/
563+
AWS_HTTP_API
564+
int aws_http2_headers_set_response_status(struct aws_http_headers *h2_headers, int status_code);
565+
566+
/**
567+
* Create a new HTTP/1.1 request message.
501568
* The message is blank, all properties (method, path, etc) must be set individually.
569+
* If HTTP/1.1 message used in HTTP/2 connection, the transformation will be automatically applied.
570+
* A HTTP/2 message will created and sent based on the HTTP/1.1 message.
502571
*
503572
* The caller has a hold on the object and must call aws_http_message_release() when they are done with it.
504573
*/
@@ -515,14 +584,34 @@ struct aws_http_message *aws_http_message_new_request_with_headers(
515584
struct aws_http_headers *existing_headers);
516585

517586
/**
518-
* Create a new response message.
587+
* Create a new HTTP/1.1 response message.
519588
* The message is blank, all properties (status, headers, etc) must be set individually.
520589
*
521590
* The caller has a hold on the object and must call aws_http_message_release() when they are done with it.
522591
*/
523592
AWS_HTTP_API
524593
struct aws_http_message *aws_http_message_new_response(struct aws_allocator *allocator);
525594

595+
/**
596+
* Create a new HTTP/2 request message.
597+
* pseudo headers need to be set from aws_http2_headers_set_request_* to the headers of the aws_http_message.
598+
* Will be errored out if used in HTTP/1.1 connection.
599+
*
600+
* The caller has a hold on the object and must call aws_http_message_release() when they are done with it.
601+
*/
602+
AWS_HTTP_API
603+
struct aws_http_message *aws_http2_message_new_request(struct aws_allocator *allocator);
604+
605+
/**
606+
* Create a new HTTP/2 response message.
607+
* pseudo headers need to be set from aws_http2_headers_set_response_status to the headers of the aws_http_message.
608+
* Will be errored out if used in HTTP/1.1 connection.
609+
*
610+
* The caller has a hold on the object and must call aws_http_message_release() when they are done with it.
611+
*/
612+
AWS_HTTP_API
613+
struct aws_http_message *aws_http2_message_new_response(struct aws_allocator *allocator);
614+
526615
/**
527616
* Acquire a hold on the object, preventing it from being deleted until
528617
* aws_http_message_release() is called by all those with a hold on it.
@@ -549,6 +638,12 @@ bool aws_http_message_is_request(const struct aws_http_message *message);
549638
AWS_HTTP_API
550639
bool aws_http_message_is_response(const struct aws_http_message *message);
551640

641+
/**
642+
* Get the protocol version of the http message.
643+
*/
644+
AWS_HTTP_API
645+
enum aws_http_version aws_http_message_get_protocol_version(const struct aws_http_message *message);
646+
552647
/**
553648
* Get the method (request messages only).
554649
*/

0 commit comments

Comments
 (0)