Function Apps | java

Abhay Chandramouli 1,026 Reputation points
2022-11-15T21:23:04.967+00:00

Hi
I want to send Set-Cookie header as a function app response header. Function App is in Java.
I have been trying to send via .header(key,val) but the second one overrides the first
.header("Set-Cookie", "cookie1=das"+";HttpOnly")
.header("Set-Cookie", "cookie2=asd"+";HttpOnly")

only cookie2 appears

Please suggest a solution

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,077 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Rudy Cortembert 1 Reputation point
    2022-11-15T21:37:07.403+00:00

    Hello,

    Your second statement overrides the first one.
    You should call .header("Set-Cookie"...) only once.

    Example :
    .header("Set-Cookie", "cookie1=das;cookie2=asd;HttpOnly")

    Side note: you should consider a StringBuilder to concatenate several cookies.

    Best Regards


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.