We're trying to use the javascript Fetch api to make requests to the server. While normally we are fine with sending cookies (using the credentials: 'include'
option), in this particular use case we want to hit the same api endpoint while not sending all our cookies, but rather just a select few cookies.
Our use case is to allow us to behave anonymously to the api based on our URL parameters on our site. For example, if we go to our site at https://SomeRadSite.com
(no idea if that's an actual site, don't go there to find out) we want our cookies to be sent to validate we're logged in and behave as such. But if we go to our site at https://SomeRadSite.com?isAnonymous=true
, then we don't want to send all our cookies (only a few) so that any interactions and api calls that take place will all be anonymous.
Again, to summarize the question. Can I selectively choose which cookies (not an all or nothing approach) to send when making a Fetch request?
Edit:
Whether or not the example posted is best practice isn't really the question (that particular code is out of my hands). I'm ultimately trying to discover if I can selectively choose which cookies can be submitted with a fetch request.
question from:
https://stackoverflow.com/questions/65602356/only-include-specific-cookies-in-fetch-request 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…