-
Notifications
You must be signed in to change notification settings - Fork 184
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
Populating Cookies using requestData headers #642
Conversation
@@ -1,8 +0,0 @@ | |||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was this file causing a problem? If not, we should revert these changes to avoid increasing the scope of the PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was making changes from this PR to allow local debugging - will revert when I no longer need to debug it.
public static IReadOnlyCollection<IHttpCookie> CookieStringsToHttpCookie(KeyValuePair<string, IEnumerable<string>> cookieStrings) | ||
{ | ||
// cookieStrings.Value comes in the format "Cookie_1=value;Cookie_2=value;Cookie_3=value" | ||
var separateCookies = cookieStrings.Value.First().ToString().Split(";"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the changes proposed above, you should be able to modify this method to work directly with the string.
}); | ||
} | ||
|
||
private IReadOnlyCollection<IHttpCookie> ToHttpCookies(IEnumerable<string> cookieString) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: arg name sounds singular while the type is a collection. May be you can change the type to string and pass the first item in line 41 ?
if (cookieString != null && cookieString.Any()) | ||
{ | ||
|
||
return ToHttpCookies(cookieString.First().ToString()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the ToString()
call really needed ? cookieString.First()
is returning a string.
|
||
public GrpcHttpRequestData(RpcHttp httpData, FunctionContext functionContext) | ||
: base(functionContext) | ||
{ | ||
_httpData = httpData ?? throw new ArgumentNullException(nameof(httpData)); | ||
_cookies = new Lazy<IReadOnlyCollection<IHttpCookie>>(() => | ||
{ | ||
if(Headers is null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Add a whitespace after if
. (Visual studio has a"fix formatting" quick action item which will do these kind of things for you. Keep cursor here and press Ctrl + . )
@@ -66,7 +102,13 @@ public override Stream Body | |||
|
|||
public override HttpHeadersCollection Headers => _headers ??= new HttpHeadersCollection(_httpData.NullableHeaders.Select(h => new KeyValuePair<string, string>(h.Key, h.Value.Value))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unrelated question: Should we consider bringing the lazy loading behavior to Headers
property as well ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
}); | ||
} | ||
|
||
private IReadOnlyCollection<IHttpCookie> ToHttpCookies(string cookieString) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Consider moving the private method down, after all public members.
First iteration of populating cookies in the HttpRequestData using the headers.