Hassan Abedi
Hassan Abedi

Reputation: 900

How to set multiple cookies in BaseHttpServer?

I'm trying to use BaseHttpServer in Python2.7 to make a simple HTTP SERVER, and the problem is when want to set multiple cookies on the browser via

     self.send_header('Set-Cookie', 'A=LDJDSFLKSDJLDSF; \n  B=545DS4SD54DSDS54')

everything after '\n' is not sent!!, it seems send_header drops anything after '\n' so the browser only receives 'A=LDJDSFLKSDJLDSF'!!!, any suggestions on how to solve this? is it a bug in Python2 BaseHttpServer? and thanks in advance.

Upvotes: 1

Views: 1949

Answers (1)

Daniel Roseman
Daniel Roseman

Reputation: 599630

That's not valid in a header, and that's nothing to do with BaseHttpServer. You can only set one cookie in a single header; however, you can certainly send multiple headers. So:

self.send_header('Set-Cookie', 'A=LDJDSFLKSDJLDSF')
self.send_header('Set-Cookie', 'B=545DS4SD54DSDS54')

Upvotes: 4

Related Questions