File tree Expand file tree Collapse file tree 3 files changed +31
-1
lines changed Expand file tree Collapse file tree 3 files changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -292,8 +292,14 @@ async def _marshal_request(
292
292
"""Create :py:class:`awscrt.http.HttpRequest` from
293
293
:py:class:`smithy_http.aio.HTTPRequest`"""
294
294
headers_list = []
295
+ if "Host" not in request .fields :
296
+ request .fields .set_field (
297
+ Field (name = "Host" , values = [request .destination .host ])
298
+ )
299
+
295
300
for fld in request .fields .entries .values ():
296
- if fld .kind != FieldPosition .HEADER :
301
+ # TODO: Use literal values for "header"/"trailer".
302
+ if fld .kind .value != FieldPosition .HEADER .value :
297
303
continue
298
304
for val in fld .values :
299
305
headers_list .append ((fld .name , val ))
Original file line number Diff line number Diff line change @@ -98,6 +98,10 @@ def __len__(self) -> int:
98
98
"""Get total number of Field entries."""
99
99
...
100
100
101
+ def __contains__ (self , key : str ) -> bool :
102
+ """Allows in/not in checks on Field entries."""
103
+ ...
104
+
101
105
def get_by_type (self , kind : FieldPosition ) -> list [Field ]:
102
106
"""Helper function for retrieving specific types of fields.
103
107
Original file line number Diff line number Diff line change 1
1
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
# SPDX-License-Identifier: Apache-2.0
3
3
from copy import deepcopy
4
+ from io import BytesIO
4
5
5
6
import pytest
6
7
8
+ from smithy_core import URI
9
+ from smithy_http import Fields
10
+ from smithy_http .aio import HTTPRequest
7
11
from smithy_http .aio .crt import AWSCRTHTTPClient , BufferableByteStream
8
12
9
13
@@ -12,6 +16,22 @@ def test_deepcopy_client() -> None:
12
16
deepcopy (client )
13
17
14
18
19
+ async def test_client_marshal_request () -> None :
20
+ client = AWSCRTHTTPClient ()
21
+ request = HTTPRequest (
22
+ method = "GET" ,
23
+ destination = URI (
24
+ host = "example.com" , path = "/path" , query = "key1=value1&key2=value2"
25
+ ),
26
+ body = BytesIO (),
27
+ fields = Fields (),
28
+ )
29
+ crt_request = await client ._marshal_request (request ) # type: ignore
30
+ assert crt_request .headers .get ("host" ) == "example.com" # type: ignore
31
+ assert crt_request .method == "GET" # type: ignore
32
+ assert crt_request .path == "/path?key1=value1&key2=value2" # type: ignore
33
+
34
+
15
35
def test_stream_write () -> None :
16
36
stream = BufferableByteStream ()
17
37
stream .write (b"foo" )
You can’t perform that action at this time.
0 commit comments