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

Microsoft.AspNetCore.Server.Kestrel.Core throw when using Set-Cookie workaround #5661

Open
kepikoi opened this issue Feb 18, 2020 · 8 comments
Assignees

Comments

@kepikoi
Copy link

kepikoi commented Feb 18, 2020

This comment #2737 (comment) describes a workaround for setting multiple cookies in a HTTP triggered function. Unfortunatly it doesn't seem to work in azure-functions-core-tools

#Repro

module.exports = async function (context, req) {
    context.res = {
        body: "Hello",
        headers: {
            "Set-Cookie": "cookie1=value",
            "Set-Cookie ": "cookie2=value", // added extra space as a workaround from #2737 for setting multiple cookies 
        }
    };
};

Calling this function yields Microsoft.AspNetCore.Server.Kestrel.Core: Invalid non-ASCII or control character in header: 0x0020. The 0x0020 bit probalby refers to the extra space character in the Set-Cookie header. Here's an execution log from my local azure-functions-core-tools:

Http Functions:

        hello: [GET,POST] http://localhost:7071/api/hello

        httpy: [GET,POST] http://localhost:7071/api/httpy

[18.02.2020 15:31:33] Executing HTTP request: {
[18.02.2020 15:31:33]   "requestId": "a53111a4-2ce3-47d0-bfbc-0c71c8ba52b3",
[18.02.2020 15:31:33]   "method": "GET",
[18.02.2020 15:31:33]   "uri": "/api/httpy"
[18.02.2020 15:31:33] }
[18.02.2020 15:31:33] Executing 'Functions.httpy' (Reason='This function was programmatically called via the host APIs.', Id=9f86f521-8d48-4ac9-9e3b-91d80fe0f901)
[18.02.2020 15:31:33] Executed 'Functions.httpy' (Succeeded, Id=9f86f521-8d48-4ac9-9e3b-91d80fe0f901)
[18.02.2020 15:31:33] An unhandled host error has occurred.
[18.02.2020 15:31:33] Microsoft.AspNetCore.Server.Kestrel.Core: Invalid non-ASCII or control character in header: 0x0020.
[18.02.2020 15:31:33] Executed HTTP request: {
[18.02.2020 15:31:33]   "requestId": "a53111a4-2ce3-47d0-bfbc-0c71c8ba52b3",
[18.02.2020 15:31:33]   "method": "GET",
[18.02.2020 15:31:33]   "uri": "/api/httpy",
[18.02.2020 15:31:33]   "identities": [
[18.02.2020 15:31:33]     {
[18.02.2020 15:31:33]       "type": "WebJobsAuthLevel",
[18.02.2020 15:31:33]       "level": "Admin"
[18.02.2020 15:31:33]     }
[18.02.2020 15:31:33]   ],
[18.02.2020 15:31:33]   "status": 500,
[18.02.2020 15:31:33]   "duration": 455
[18.02.2020 15:31:33] }
[18.02.2020 15:31:38] Host lock lease acquired by instance ID '00000000000000000000000064B2E1FD'.

Environment:

PS C:\> node -v
v12.14.1
PS C:\> npm -v
6.13.4
PS C:\> func -v
2.7.2184
PS C:\> [System.Environment]::OSVersion.Version

Major  Minor  Build  Revision
-----  -----  -----  --------
10     0      18362  0

@anthonychu anthonychu transferred this issue from Azure/azure-functions-core-tools Feb 18, 2020
@ghost ghost assigned alrod Feb 18, 2020
@alrod
Copy link
Member

alrod commented Mar 11, 2020

cc: @mhoeger, is the issue related? can you please comment if yes?
#2737

@alrod alrod added this to the Triaged milestone Mar 11, 2020
@alrod alrod removed their assignment Mar 11, 2020
@mhoeger
Copy link
Contributor

mhoeger commented Mar 11, 2020

@kepikoi - the workaround is a bit old, are you able to do this?

module.exports = async function (context, req) {
    context.res = {
        body: "Hello",
        cookies: [
            {
                name: "cookie1",
                value: "value"
            },
            {
                name: "cookie2",
                value: "value"
            },
        ]
    };
};

@kepikoi
Copy link
Author

kepikoi commented Mar 11, 2020

@mhoeger thank you, I am aware of this solution. Unfortunately this approach has its own limitations, which is it doesn't work via the $return notation in due to Azure/azure-functions-nodejs-worker#228 as noted in Azure/azure-functions-nodejs-worker#284 (comment)

@ThejaChoudary
Copy link

@mhoeger can you please look it into this.

@v-anvari
Copy link

v-anvari commented May 7, 2021

@kepikoi , Apologies for the delay, Can you let us know if you were able to find a solution. Let us know if you require a follow up for this issue

@kepikoi
Copy link
Author

kepikoi commented May 7, 2021

@v-anvari I haven't found a solution. AFAIK this is still an issue

@v-anvari
Copy link

Thank you for the update, I shall follow up with the team

@v-anvari
Copy link

v-anvari commented May 17, 2021

Hi @alrod , Do you have any inputs here.

@fabiocav fabiocav removed this from the Triaged milestone Jan 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants