Thanks @TatiBarros , I’ll try to add some informations and ways that I already tried to accomplish what I want to achieve.
I have several files in my meteor-files
collection, that I’d like to serve via http. I would like to add an access protection mechanism via meteor-files
method protected
, passed to the constructor of the FilesCollection
(cf. https://github.com/veliovgroup/Meteor-Files/blob/master/docs/constructor.md).
The access control mechanism I try to implement is based on the userId
in this method. In order to determine the userId
in an http request, meteor-files
relies on a cookie x_mtok
. That cookie stores the Meteor.connection._lastSessionId
in order to determine the user for that request.
Now, if you use multiple instances of your meteor server behind a load balancer, you need to make sure that the http (file)-requests is forwarded to the correct server instance. This is the instance to which the client is connected to via ddp.
I’m hosting my app on scalingo. They send a set-cookie
in the header, which allows them to forward requests to the same backend, aka a sticky-session. So in order to send the http request to the correct backend I need to set the sticky-session cookie. I managed to get the sessionId in the meteor-react-native
client (cf. the commit 6fd0e17 in my PR)
The problem now is that if I do not send the correct “sticky-session-cookie”, my request might end at the wrong instance (i.e. any instance where my meteor-session is not running).
Right now I try to work around this by first sending a HEAD request prior to the download request, read out the set-cookie value for the sticky-session and then send the download request. I have minimum two instances running behind the balancer, so if I send my requests without that sticky-session-cookie I get auth failures at around ~50%, which is what you would expect. With my workaround I get success at around 90% of the time, so maybe this could be ok, but I’m really not sure, if this is the exact sticky-session-cookie that I get from the WebSocket handshake on when the ddp session begins.
So I try to catch the set-cookie header at the first occurence, which I guess is the WebSocket http handshake.
Maybe @jkuester or @therealnate can help out with this? How does meteor-react-native
handle sticky session?