httphttp-headersrfchttpcookie

In HTTP specification, what is the string that separates cookies?


Semicolon ;, the Cookie: string or some other string?


Solution

  • Inspecting cookies in an HTTP request

    The Cookie: header has the following syntax:

    Cookie: <Name> = <Value> { ; <Name> = <Value> }
    

    Hence individual cookies are separated with the semicolon and a space.

    Setting cookies in an HTTP response

    On the other hand, when setting a cookie in the response, there one cookie per the Set-Cookie: header:

    Set-Cookie: <Name> = <Value> [ ; expires = <Date>] [ ; path = <Path> ] [ ; domain = <Domain> ] // etc…
    

    To set multiple cookies the Set-Cookie header is repeated in an HTTP response.


    Notes: