Skip to content

Commit

Permalink
[rest] fix str check in content kwarg to be six.string_types check fo…
Browse files Browse the repository at this point in the history
…r 2.7 (#21550)
  • Loading branch information
iscai-msft authored Nov 3, 2021
1 parent 60e11ba commit 9d5c864
Showing 3 changed files with 13 additions and 3 deletions.
3 changes: 1 addition & 2 deletions sdk/core/azure-core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -17,8 +17,7 @@
rather than silently truncating data in case the underlying tcp connection is closed prematurely.
(thanks to @jochen-ott-by for the contribution) #20412
- UnboundLocalError when SansIOHTTPPolicy handles an exception #15222

### Other Changes
- 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

## 1.19.1 (2021-11-01)

2 changes: 1 addition & 1 deletion sdk/core/azure-core/azure/core/rest/_helpers.py
Original file line number Diff line number Diff line change
@@ -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):
11 changes: 11 additions & 0 deletions sdk/core/azure-core/tests/test_rest_http_request.py
Original file line number Diff line number Diff line change
@@ -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):

0 comments on commit 9d5c864

Please sign in to comment.