From 82a77e339e09ed016af305fcfcdb6d15cc6883b0 Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Tue, 2 Nov 2021 14:01:58 -0700 Subject: [PATCH 1/4] add unicode content input test --- sdk/core/azure-core/tests/test_rest_http_request.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/sdk/core/azure-core/tests/test_rest_http_request.py b/sdk/core/azure-core/tests/test_rest_http_request.py index 70c184b5cc3d..c56871dcd477 100644 --- a/sdk/core/azure-core/tests/test_rest_http_request.py +++ b/sdk/core/azure-core/tests/test_rest_http_request.py @@ -255,6 +255,17 @@ def test_data_str_input(): assert len(request.headers) == 1 assert request.headers['Content-Type'] == 'application/x-www-form-urlencoded' +def test_content_str_input(): + requests = [ + HttpRequest("POST", "/fake", content="hello, world!"), + HttpRequest("POST", "/fake", content=u"hello, world!"), + ] + for request in requests: + assert len(request.headers) == 2 + assert request.headers["Content-Type"] == "text/plain" + assert request.headers["Content-Length"] == "13" + assert request.content == "hello, world!" + @pytest.mark.parametrize(("value"), (object(), {"key": "value"})) def test_multipart_invalid_value(value): From 71379c368927c5f290fba21fba607632bd26dd23 Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Tue, 2 Nov 2021 14:03:40 -0700 Subject: [PATCH 2/4] switch str check to six.string_types check --- sdk/core/azure-core/azure/core/rest/_helpers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/core/azure-core/azure/core/rest/_helpers.py b/sdk/core/azure-core/azure/core/rest/_helpers.py index 934bfa613c76..aa5b05bd9e10 100644 --- a/sdk/core/azure-core/azure/core/rest/_helpers.py +++ b/sdk/core/azure-core/azure/core/rest/_helpers.py @@ -134,7 +134,7 @@ def _shared_set_content_body(content): if isinstance(content, ET.Element): # XML body return set_xml_body(content) - if isinstance(content, (str, bytes)): + if isinstance(content, (six.string_types, bytes)): headers = {} body = content if isinstance(content, six.string_types): From a7946ba2635c2e4916da684fe2e541d95fcb8f55 Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Tue, 2 Nov 2021 14:05:28 -0700 Subject: [PATCH 3/4] update changelog --- sdk/core/azure-core/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/sdk/core/azure-core/CHANGELOG.md b/sdk/core/azure-core/CHANGELOG.md index 6b1bbf9ba9a2..c11a96792162 100644 --- a/sdk/core/azure-core/CHANGELOG.md +++ b/sdk/core/azure-core/CHANGELOG.md @@ -13,6 +13,7 @@ ### Bugs Fixed - UnboundLocalError when SansIOHTTPPolicy handles an exception #15222 +- Add default content type header of `text/plain` and content length header for users who pass unicode strings to the `content` kwarg of `HttpRequest` in 2.7 #21550 ### Other Changes From d41cc37679a85eac735c98e06f35876360856138 Mon Sep 17 00:00:00 2001 From: Xiang Yan Date: Wed, 3 Nov 2021 09:14:42 -0700 Subject: [PATCH 4/4] Update CHANGELOG.md --- sdk/core/azure-core/CHANGELOG.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/sdk/core/azure-core/CHANGELOG.md b/sdk/core/azure-core/CHANGELOG.md index c11a96792162..a64c64f44e06 100644 --- a/sdk/core/azure-core/CHANGELOG.md +++ b/sdk/core/azure-core/CHANGELOG.md @@ -15,8 +15,6 @@ - UnboundLocalError when SansIOHTTPPolicy handles an exception #15222 - Add default content type header of `text/plain` and content length header for users who pass unicode strings to the `content` kwarg of `HttpRequest` in 2.7 #21550 -### Other Changes - ## 1.19.1 (2021-11-01) ### Bugs Fixed