Skip to content
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

HttpRequestData.Cookies is Empty #694

Closed
jrhodnik opened this issue Oct 29, 2021 · 3 comments · Fixed by #696
Closed

HttpRequestData.Cookies is Empty #694

jrhodnik opened this issue Oct 29, 2021 · 3 comments · Fixed by #696

Comments

@jrhodnik
Copy link

When using an HTTP triggered function, it appears that HttpRequestData.Cookies is empty. This appears to be an issue that was previously reported and resolved in #466 though I am still not seeing cookies despite them being present in Headers. I am currently using version 1.5.2.

As a workaround I copied ToHttpCookie locally to my project to keep moving and may have noticed another bug.

When splitting the cookies out of the full cookie string, cookie names are not trimmed and contain leading whitespace if it was included in the string.
Example:
Browser sends the following cookie header: another-token=aasdfasdf; some-token=asdfasdf

The dict key for some-token will in fact be [space]some-token.
Note that when I set the cookie I did not include a leading whitespace. The browser (Chrome in this case) seems to separate multiple cookies with ; rather than simply ;.

@ghost ghost assigned fabiocav Oct 29, 2021
@satvu satvu self-assigned this Nov 1, 2021
@satvu
Copy link
Member

satvu commented Nov 1, 2021

Thanks for catching the white-space bug! Repro'd it and will be putting in a fix.

Could you provide a little more info about your environment @jrhodnik (like core tools version)? Or see if the sample below works for you? I just tested it with the latest branch and was able to grab from the Cookies field.

[Function("Function4")]
public static HttpResponseData Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequestData req, FunctionContext executionContext)
 {
    var logger = executionContext.GetLogger("FunctionApp.Function4");

    logger.LogInformation("message logged");
    var response = req.CreateResponse(HttpStatusCode.OK);

    var cookies = req.Cookies;

    foreach(var c in cookies)
    {
         logger.LogInformation(c.Name);
    }
    
    response.Headers.Add("Date", "Mon, 18 Jul 2016 16:06:00 GMT");
    response.Headers.Add("Content-Type", "text/html; charset=utf-8");
    response.WriteString("Welcome to .NET 5!!");
    
    return response;
}

@jrhodnik
Copy link
Author

jrhodnik commented Nov 1, 2021

@satvu,

Thank you for your response, glad to hear about the bug fix. Below is the version I'm running on. I was able to reproduce the cookie issue with your sample above. Was the aforementioned fix not published to 3x yet?

Azure Functions Core Tools
Core Tools Version:       3.0.3904 Commit hash: c345f7140a8f968c5dbc621f8a8374d8e3234206  (64-bit)
Function Runtime Version: 3.3.1.0

Thanks!

-John

@satvu
Copy link
Member

satvu commented Nov 3, 2021

@jrhodnik if you update the worker to version 1.6.0 it should work now

@ghost ghost locked as resolved and limited conversation to collaborators Dec 3, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants