title: Request a file with a custom header
body: <p>I have an unusual requirement. Essentially I need a way so that, when the user clicks on a link or button, they will receive a PDF. The tricky part here is that the server won't process the request <em>at all</em> unless a custom header is sent with it (otherwise it deems the person logged out and sends them to the login screen).</p>
  
  <p>At the moment the way the header works cannot be changed so please don't dwell on it; it will get changed in the future and is an internal application that I have no control over.</p>
  
  <p>The options I have explored:</p>
  
  <ul>
  <li>Using an iframe or simply opening a new window with some sort of path that will return the PDF. This can't work because I cannot specify the required header for the PDF and would be redirected before reaching the PDF itself.</li>
  <li>Using a form and submitting the request can't work because I can't
  add any custom headers to forms (only XHR and plugins can, AFAIK).</li>
  <li>Using XHR can't work because, while it can add the header and
  retrieve the file, there is no way to save it on the client side.</li>
  </ul>
  
  <p>It would appear my only options at this point are essentially:</p>
  
  <ul>
  <li>Use some sort of plugin such as Flash or Silverlight to request the file.</li>
  <li>Force the change of the requirement much earlier than expected so that a header is no longer required.</li>
  </ul>
  
  <p>Is there anything I am missing here? I'm hoping someone can either verify my findings or point me to something I missed because, as far as I can tell, there isn't really anything I can do here.</p>
  
  <p>EDIT: This seems apt and confirms what I was thinking: <a href="https://stackoverflow.com/questions/4750461/xmlhttprequest-to-open-pdf-in-browser">XMLHttpRequest to open PDF in browser</a></p>