Sometimes http cookie headers are not being set
Below is the log of how we're communicating with our backend. You send a "POST" to :5000 to register as a user, if successful, a "Set-Cookie" header is returned, and you then use that to communicate with :5001, our main data server. On first registration, it works 100% of the time. On second registration (when someone's registered with a social network, in this case Facebook), we get a new "Set-Cookie" header and basically become a new user. About 50% of the time, this succeeds. And for the other 50%, any of the last 3 calls may fail.
The "/debug_session_api/get" calls are purely debug calls, which return the cookie that was sent with the request, along with it decoded.
As I said, with the first registration, it works 100% of the time, a header is set, and you're that person. But it seems for whatever reason, that second "Set-Cookie" response instruction does nothing, or the future URLRequests sometimes don't use it, and send the cached cookie instead. I have absolute no idea what's going on here.
This is happening on Android, with request.manageCookies still at their default "true", but because what happens there is such a black-box, I've no idea about how to go about solving this, other than us managing the cookies ourselves, which we'd prefer not to do, but obviously if we can't trust /rely on what's happening in the background, we'll have to.
-----------------------------------------------
POST http://api-local.sixminute.com:5000/user
SENT {"uid":null,"email":null,"username":"guest_131838266","getDeviceVersion":true,"game":"1","hasVersion":"and_0bfe7cb-96c06ab","paid":false}
RECV {"username": "guest_131838266", "last_accessed": "2014-02-05 14:15:14", "uid": "52f28577adb6a8b389bcb3f2", "new_user": false, "gender": null, "fbid": null, "joined": "2014-02-05 18:39:51", "paid": false, "fb_email": null, "games": ["1"], "password": "sha1$wx8n8mDI$995319fe2ee20a707ce211509a2a0b1f12f759a5", "email": null}
Set-Cookie session="gPsSyr994wA3imMXKCjul3Gl2RI=?session_start=RjEzOTE2ODU3NjguMDUyNTU1MQou&uid=Uyc1MmYyODU3N2FkYjZhOGIzODliY2IzZjInCnAxCi4="
-----------------------------------------------
GET http://api-local.sixminute.com:5000/debug_session_api/get
SENT getDeviceVersion=true&hasVersion=and%5F0bfe7cb%2D96c06ab&ts=1391685671445
RECV [[["session", "gPsSyr994wA3imMXKCjul3Gl2RI=?session_start=RjEzOTE2ODU3NjguMDUyNTU1MQou&uid=Uyc1MmYyODU3N2FkYjZhOGIzODliY2IzZjInCnAxCi4="]], [["session_start", 1391685768.052555], ["uid", "52f28577adb6a8b389bcb3f2"]]]
-----------------------------------------------
GET http://api-local.sixminute.com:5001/debug_session_api/get
SENT getDeviceVersion=true&hasVersion=and%5F0bfe7cb%2D96c06ab&ts=1391685671660
RECV [[["session", "gPsSyr994wA3imMXKCjul3Gl2RI=?session_start=RjEzOTE2ODU3NjguMDUyNTU1MQou&uid=Uyc1MmYyODU3N2FkYjZhOGIzODliY2IzZjInCnAxCi4="]], [["session_start", 1391685768.052555], ["uid", "52f28577adb6a8b389bcb3f2"]]]
-----------------------------------------------
GET http://api-local.sixminute.com:5001/1/user/52f28577adb6a8b389bcb3f2/key/sd
SENT getDeviceVersion=true&hasVersion=and%5F0bfe7cb%2D96c06ab&ts=1391685672396
RECV {}
-----------------------------------------------
POST http://api-local.sixminute.com:5000/facebook
SENT {"getDeviceVersion":true,"access_token":"xxx","game":"1","fbid":"xxx","hasVersion":"and_0bfe7cb-96c06ab","paid":false}
RECV {"username": "seaders", "last_accessed": "2013-12-12 11:38:51", "uid": "52a73e81ba4c09281cc75bf5", "new_user": false, "gender": "male", "fbid": "xxx", "joined": "2013-12-10 16:17:05", "paid": false, "fb_email": "xxx", "games": ["1"], "fbexpires_at": "2014-04-04 16:11:18", "fbaccess_token": "xxx", "password": "sha1$mjGHjuru$c4415797c3398266ca4c1d5eb66c936436693467", "email": null}
Set-Cookie session="GHY+IpN/mFuSN+Fbzcrtm1rX41I=?has_session=STAxCi4=&uid=Uyc1MmE3M2U4MWJhNGMwOTI4MWNjNzViZjUnCnAxCi4="
-----------------------------------------------
GET http://api-local.sixminute.com:5000/debug_session_api/get
SENT getDeviceVersion=true&hasVersion=and%5F0bfe7cb%2D96c06ab&ts=1391685675702
RECV [[["session", "gPsSyr994wA3imMXKCjul3Gl2RI=?session_start=RjEzOTE2ODU3NjguMDUyNTU1MQou&uid=Uyc1MmYyODU3N2FkYjZhOGIzODliY2IzZjInCnAxCi4="]], [["uid", "52a73e81ba4c09281cc75bf5"], ["has_session", true]]]
-----------------------------------------------
GET http://api-local.sixminute.com:5001/debug_session_api/get
SENT getDeviceVersion=true&hasVersion=and%5F0bfe7cb%2D96c06ab&ts=1391685675901
RECV [[["session", "gPsSyr994wA3imMXKCjul3Gl2RI=?session_start=RjEzOTE2ODU3NjguMDUyNTU1MQou&uid=Uyc1MmYyODU3N2FkYjZhOGIzODliY2IzZjInCnAxCi4="]], [["uid", "52a73e81ba4c09281cc75bf5"], ["has_session", true]]]
-----------------------------------------------
GET http://api-local.sixminute.com:5001/1/user/52a73e81ba4c09281cc75bf5/key/sd
SENT getDeviceVersion=true&hasVersion=and%5F0bfe7cb%2D96c06ab&ts=1391685676377
RECV {"UNAUTHORISED"}
