Update 2022
Apparently, it works with XHR now as shown in this answer. Thanks goes to Jamie Pete for the reference.
Original answer
This not possible, because the only way to add HTTP headers is using the XHR, but XHR cannot be used to download files.
You could however use cookies to do that.
- Just set the cookie, with a returned value from the server.
- Wait till the user clicks the link.
- Invalidate the cookie after the user clicked the link.