Search code examples
c++mongoosemongoose-web-server

How set cookies on mongoose server?


How can I set cookies with c++ on a mongoose web server? I found something here https://www.cesanta.com/developer/mongoose#_mg_http_parse_header But i'm not sure if is what I'm looking.


Solution

  • You should send a Set-Cookie HTTP header to the client. There multiple ways of doing that with mongoose, for example using mg_send_head() , https://www.cesanta.com/developer/mongoose#_mg_send_head :

    mg_send_head(conn, 200, content_len, "Set-Cookie: token=1234; Expires=Wed, 09 Jun 2021 10:18:14 GMT");
    

    Set-Cookie header format is described in https://www.rfc-editor.org/rfc/rfc6265. Wikipedia also has a good article on it, https://en.wikipedia.org/wiki/HTTP_cookie