-
Notifications
You must be signed in to change notification settings - Fork 107
Enable support for multiple Set-Cookie response headers (native & wsgi/asgi) #1004
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
85a5807
initial add cookies attempt
5efa854
exclude workindexing proto api from this pr
f9d066e
Add parsing and nullable tests
113d761
initial add cookies attempt
3fe9f26
exclude workindexing proto api from this pr
8f710bb
Merge branch 'wangbill/multi-cookie-resp-headers' of https://github.c…
1df9789
delete random test
bf1ced6
Merge branch 'dev' of https://github.com/Azure/azure-functions-python…
07e7621
update multi-ccokie tests;add pystein tests
b1a6dc1
change to self.assertEqual
a57156c
fix flakey8
47f51f5
fix flakey8
a5e26bf
make dateutil install required
48c08d0
skip setting multi cookie headers test for py 3.7
7a9e5c4
Merge branch 'dev' into wangbill/multi-cookie-resp-headers
YunchuWang f1d411f
Merge branch 'dev' into wangbill/multi-cookie-resp-headers
YunchuWang 3199f94
Merge branch 'dev' into wangbill/multi-cookie-resp-headers
YunchuWang a0f946d
skip 3.7 multi cookie tests
6a469e5
Merge branch 'dev' into wangbill/multi-cookie-resp-headers
YunchuWang 6d461d5
skip linux consumption tests until dateutil goes in
fcafe6a
flakey8 fix
277f5be
Merge branch 'dev' into wangbill/multi-cookie-resp-headers
YunchuWang ec9bf5d
Merge branch 'dev' into wangbill/multi-cookie-resp-headers
YunchuWang a42bed1
update cookie tests
e845986
fix test
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
from datetime import datetime | ||
from typing import Optional, Union | ||
|
||
from google.protobuf.timestamp_pb2 import Timestamp | ||
|
||
from azure_functions_worker import protos | ||
|
||
|
||
def to_nullable_string(nullable: Optional[str], property_name: str) -> \ | ||
Optional[protos.NullableString]: | ||
"""Converts string input to an 'NullableString' to be sent through the | ||
RPC layer. Input that is not a string but is also not null or undefined | ||
logs a function app level warning. | ||
|
||
:param nullable Input to be converted to an NullableString if it is a | ||
valid string | ||
:param property_name The name of the property that the caller will | ||
assign the output to. Used for debugging. | ||
""" | ||
if isinstance(nullable, str): | ||
return protos.NullableString(value=nullable) | ||
|
||
if nullable is not None: | ||
raise TypeError( | ||
f"A 'str' type was expected instead of a '{type(nullable)}' " | ||
f"type. Cannot parse value {nullable} of '{property_name}'.") | ||
|
||
return None | ||
|
||
|
||
def to_nullable_bool(nullable: Optional[bool], property_name: str) -> \ | ||
Optional[protos.NullableBool]: | ||
"""Converts boolean input to an 'NullableBool' to be sent through the | ||
RPC layer. Input that is not a boolean but is also not null or undefined | ||
logs a function app level warning. | ||
|
||
:param nullable Input to be converted to an NullableBool if it is a | ||
valid boolean | ||
:param property_name The name of the property that the caller will | ||
assign the output to. Used for debugging. | ||
""" | ||
if isinstance(nullable, bool): | ||
return protos.NullableBool(value=nullable) | ||
|
||
if nullable is not None: | ||
raise TypeError( | ||
f"A 'bool' type was expected instead of a '{type(nullable)}' " | ||
f"type. Cannot parse value {nullable} of '{property_name}'.") | ||
|
||
return None | ||
|
||
|
||
def to_nullable_double(nullable: Optional[Union[str, int, float]], | ||
property_name: str) -> \ | ||
Optional[protos.NullableDouble]: | ||
"""Converts int or float or str that parses to a number to an | ||
'NullableDouble' to be sent through the RPC layer. Input that is not a | ||
valid number but is also not null or undefined logs a function app level | ||
warning. | ||
:param nullable Input to be converted to an NullableDouble if it is a | ||
valid number | ||
:param property_name The name of the property that the caller will | ||
assign the output to. Used for debugging. | ||
""" | ||
if isinstance(nullable, int) or isinstance(nullable, float): | ||
return protos.NullableDouble(value=nullable) | ||
elif isinstance(nullable, str): | ||
if len(nullable) == 0: | ||
return None | ||
|
||
try: | ||
return protos.NullableDouble(value=float(nullable)) | ||
except Exception: | ||
raise TypeError( | ||
f"Cannot parse value {nullable} of '{property_name}' to " | ||
f"float.") | ||
|
||
if nullable is not None: | ||
raise TypeError( | ||
f"A 'int' or 'float'" | ||
f" type was expected instead of a '{type(nullable)}' " | ||
f"type. Cannot parse value {nullable} of '{property_name}'.") | ||
|
||
return None | ||
|
||
|
||
def to_nullable_timestamp(date_time: Optional[Union[datetime, int]], | ||
property_name: str) -> protos.NullableTimestamp: | ||
"""Converts Date or number input to an 'NullableTimestamp' to be sent | ||
through the RPC layer. Input that is not a Date or number but is also | ||
not null or undefined logs a function app level warning. | ||
|
||
:param date_time Input to be converted to an NullableTimestamp if it is | ||
valid input | ||
:param property_name The name of the property that the caller will | ||
assign the output to. Used for debugging. | ||
""" | ||
if date_time is not None: | ||
try: | ||
time_in_seconds = date_time if isinstance(date_time, | ||
int) else \ | ||
date_time.timestamp() | ||
|
||
return protos.NullableTimestamp( | ||
value=Timestamp(seconds=int(time_in_seconds))) | ||
except Exception: | ||
raise TypeError( | ||
f"A 'datetime' or 'int'" | ||
f" type was expected instead of a '{type(date_time)}' " | ||
f"type. Cannot parse value {date_time} of '{property_name}'.") | ||
return None |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
tests/unittests/http_functions/multiple_set_cookie_resp_headers/function.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"scriptFile": "main.py", | ||
"bindings": [ | ||
{ | ||
"type": "httpTrigger", | ||
"direction": "in", | ||
"name": "req" | ||
}, | ||
{ | ||
"type": "http", | ||
"direction": "out", | ||
"name": "$return" | ||
} | ||
] | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.