Subin Jacob
Subin Jacob

Reputation: 4864

When will a cookie from server response set in Browser?

When will the cookie from server response will be set to client browser? Suppose I have a get request from client side and it returns a larger file, then when will be the cookie will be set to client. Before the download complete or after ?

ie, If it requires 30 seconds to load the complete file, then when can I access that cookie from client side (javaScript)?

Any Ideas?

Upvotes: 2

Views: 814

Answers (1)

BalusC
BalusC

Reputation: 1108742

The cookie will be set in the browser immediately once the Set-Cookie response header is arrived, not when the last byte of the response has been arrived. Thus, at exactly the same moment as when the Save As dialogue shows up in case of Content-Disposition: attachment.

So, whenever you'd like to track download progress, setting such a cookie is only useful when you want to poll for the "start" event of the download. Generally, in those situations when it can take seconds or even minutes to prepare the file download before it's being streamed.

Upvotes: 2

Related Questions