@@ -1721,110 +1721,6 @@ static void s_stream_complete(struct aws_h2_connection *connection, struct aws_h
17211721 aws_http_stream_release (& stream -> base );
17221722}
17231723
1724- struct aws_http_headers * aws_h2_create_headers_from_request (
1725- struct aws_http_message * request ,
1726- struct aws_allocator * alloc ) {
1727-
1728- struct aws_http_headers * old_headers = aws_http_message_get_headers (request );
1729- bool is_pseudoheader = false;
1730- struct aws_http_headers * result = aws_http_headers_new (alloc );
1731- struct aws_http_header header_iter ;
1732- struct aws_byte_buf lower_name_buf ;
1733- AWS_ZERO_STRUCT (lower_name_buf );
1734-
1735- /* Check whether the old_headers have pseudo header or not */
1736- if (aws_http_headers_count (old_headers )) {
1737- if (aws_http_headers_get_index (old_headers , 0 , & header_iter )) {
1738- goto error ;
1739- }
1740- is_pseudoheader = header_iter .name .ptr [0 ] == ':' ;
1741- }
1742- if (!is_pseudoheader ) {
1743- /* TODO: Set pseudo headers all from message, which will lead an API change to aws_http_message */
1744- /* No pseudoheader detected, we set them from the request */
1745- /* Set pseudo headers */
1746- struct aws_byte_cursor method ;
1747- if (aws_http_message_get_request_method (request , & method )) {
1748- /* error will happen when the request is invalid */
1749- aws_raise_error (AWS_ERROR_HTTP_INVALID_METHOD );
1750- goto error ;
1751- }
1752- if (aws_http_headers_add (result , aws_http_header_method , method )) {
1753- goto error ;
1754- }
1755- /* we set a default value, "https", for now */
1756- struct aws_byte_cursor scheme_cursor = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL ("https" );
1757- if (aws_http_headers_add (result , aws_http_header_scheme , scheme_cursor )) {
1758- goto error ;
1759- }
1760- /* Set an empty authority for now, if host header field is found, we set it as the value of host */
1761- struct aws_byte_cursor authority_cursor ;
1762- struct aws_byte_cursor host_cursor = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL ("host" );
1763- if (!aws_http_headers_get (old_headers , host_cursor , & authority_cursor )) {
1764- if (aws_http_headers_add (result , aws_http_header_authority , authority_cursor )) {
1765- goto error ;
1766- }
1767- }
1768- struct aws_byte_cursor path_cursor ;
1769- if (aws_http_message_get_request_path (request , & path_cursor )) {
1770- aws_raise_error (AWS_ERROR_HTTP_INVALID_PATH );
1771- goto error ;
1772- }
1773- if (aws_http_headers_add (result , aws_http_header_path , path_cursor )) {
1774- goto error ;
1775- }
1776- }
1777- /* if pseudoheader is included in message, we just convert all the headers from old_headers to result */
1778- if (aws_byte_buf_init (& lower_name_buf , alloc , 256 )) {
1779- goto error ;
1780- }
1781- for (size_t iter = 0 ; iter < aws_http_headers_count (old_headers ); iter ++ ) {
1782- /* name should be converted to lower case */
1783- if (aws_http_headers_get_index (old_headers , iter , & header_iter )) {
1784- goto error ;
1785- }
1786- /* append lower case name to the buffer */
1787- aws_byte_buf_append_with_lookup (& lower_name_buf , & header_iter .name , aws_lookup_table_to_lower_get ());
1788- struct aws_byte_cursor lower_name_cursor = aws_byte_cursor_from_buf (& lower_name_buf );
1789- enum aws_http_header_name name_enum = aws_http_lowercase_str_to_header_name (lower_name_cursor );
1790- switch (name_enum ) {
1791- case AWS_HTTP_HEADER_COOKIE :
1792- /* split cookie if USE CACHE */
1793- if (header_iter .compression == AWS_HTTP_HEADER_COMPRESSION_USE_CACHE ) {
1794- struct aws_byte_cursor cookie_chunk ;
1795- AWS_ZERO_STRUCT (cookie_chunk );
1796- while (aws_byte_cursor_next_split (& header_iter .value , ';' , & cookie_chunk )) {
1797- if (aws_http_headers_add (
1798- result , lower_name_cursor , aws_strutil_trim_http_whitespace (cookie_chunk ))) {
1799- goto error ;
1800- }
1801- }
1802- } else {
1803- if (aws_http_headers_add (result , lower_name_cursor , header_iter .value )) {
1804- goto error ;
1805- }
1806- }
1807- break ;
1808- case AWS_HTTP_HEADER_HOST :
1809- /* host header has been converted to :authority, do nothing here */
1810- break ;
1811- /* TODO: handle connection-specific header field (RFC7540 8.1.2.2) */
1812- default :
1813- if (aws_http_headers_add (result , lower_name_cursor , header_iter .value )) {
1814- goto error ;
1815- }
1816- break ;
1817- }
1818- aws_byte_buf_reset (& lower_name_buf , false);
1819- }
1820- aws_byte_buf_clean_up (& lower_name_buf );
1821- return result ;
1822- error :
1823- aws_http_headers_release (result );
1824- aws_byte_buf_clean_up (& lower_name_buf );
1825- return NULL ;
1826- }
1827-
18281724int aws_h2_connection_on_stream_closed (
18291725 struct aws_h2_connection * connection ,
18301726 struct aws_h2_stream * stream ,
0 commit comments