title: How to set request headers asynchronously in typeahead/bloodhound
body: <p>Environment:</p>
  
  <ul>
  <li>I am using typeahead/bloodhound for a search field in my mobile app (steroids/cordova)</li>
  <li>Every request from my app to the API needs to be signed and the signature added to auth headers</li>
  </ul>
  
  <p>Obviously setting the headers in the ajax settings won't work as each request bloodhound sends will be different and require different signatures.</p>
  
  <p>In my first implementation, I was using the <code>beforeSend</code> ajax setting to achieve this. Simply calculate the signature in that function and add it to the request headers.</p>
  
  <p>However, this was not very secure so I have decided to place the secret used and the signature calculation into a Cordova custom plugin's native code to be compiled. Not bullet proof but a reasonable amount of security.</p>
  
  <p>As Cordova plugins are asynchronous, <code>beforeSend</code> became useless in this case. The function will complete before the signing and setting of the headers are done.</p>
  
  <p>So, in summary, the question is: How can I asynchronously calculate and set those headers with typeahead/bloodhound?</p>