HTML and CSS Reference
In-Depth Information
Listing 13.67 Adding a custom header
function connect() {
/* ... */
if (!this.poller) {
this.poller = ajax.poll(this.url, {
/* ... */
headers: {
"Content-Type": "application/json",
"X-Access-Token": ""
}
});
}
}
For the first request the token will be blank. In a more sophisticated imple-
mentation the initial token could possibly be set manually, e.g., by reading it from
a cookie or local database to allow a user to pick up where she left off.
Sending blank tokens on every request doesn't really help us track requests. The
next test, shown in Listing 13.68, expects that the token returned from the server
is sent on the following request.
Listing 13.68 Expecting the received token to be passed on second request
tearDown: function () {
/* ... */
Clock.reset();
},
/* ... */
"test should pass token on following request":
function () {
this.client.connect();
var data = { token: 1267482145219 };
this.xhr.complete(200, JSON.stringify(data));
Clock.tick(1000);
var headers = this.xhr.headers;
assertEquals(data.token, headers["X-Access-Token"]);
}
 
Search WWH ::




Custom Search