in azure/functions/http.py [0:0]
def encode(cls, obj: typing.Any, *,
expected_type: typing.Optional[type]) -> meta.Datum:
if isinstance(obj, str):
return meta.Datum(type='string', value=obj)
if isinstance(obj, azf_abc.HttpResponse):
status = obj.status_code
headers: Headers = obj.headers
if 'content-type' not in headers:
if obj.mimetype.startswith('text/'):
ct = f'{obj.mimetype}; charset={obj.charset}'
else:
ct = f'{obj.mimetype}'
headers['content-type'] = ct
body = obj.get_body()
if body is not None:
datum_body = meta.Datum(type='bytes', value=body)
else:
datum_body = meta.Datum(type='bytes', value=b'')
cookies = None
if sys.version_info.major == 3 and sys.version_info.minor <= 7:
# SimpleCookie api in http.cookies - Python Standard Library
# is not supporting 'samesite' in cookie attribute in python
# 3.7 or below and would cause cookie parsing error
# https://docs.python.org/3/library/http.cookies.html
# ?msclkid=d78849ddcd7311ecadd81f2f51d08b8e
logging.warning(
"Setting multiple 'Set-Cookie' response headers is not "
"supported in Azure Python Function with python version "
"3.7, please upgrade to python 3.8 or above.")
else:
if "Set-Cookie" in headers:
cookies = [SimpleCookie(cookie) for cookie in
headers.get_all('Set-Cookie')]
headers.pop("Set-Cookie")
return meta.Datum(
type='http',
value=dict(
status_code=meta.Datum(type='string', value=str(status)),
headers={
n: meta.Datum(type='string', value=h)
for n, h in headers.items()
},
cookies=cookies,
body=datum_body,
)
)
raise NotImplementedError