headers.js
1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
casper.test.comment('Casper.headers.get()');
var server = require('webserver').create();
var service = server.listen(8090, function (request, response) {
response.statusCode = 200;
response.headers = {
'Content-Language': 'en',
'Content-Type': 'text/html',
'Date': new Date().toUTCString()
};
response.write("\o/");
response.close();
});
function dumpHeaders () {
casper.test.comment('Dumping current response headers');
casper.currentResponse.headers.forEach(function (header) {
casper.test.comment('- ' + header.name + ': ' + header.value);
});
}
casper.start('tests/site/index.html', function thenLocalPage () {
this.test.assertEquals(casper.currentResponse, undefined, 'No response available on local page');
});
casper.thenOpen('http://localhost:8090/', function thenLocalhost () {
var headers = casper.currentResponse.headers;
this.test.assertEquals(headers.get('Content-Language'), 'en', 'Checking existing header (case sensitive)');
this.test.assertEquals(headers.get('content-language'), 'en', 'Checking existing header (case insensitive)');
this.test.assertEquals(headers.get('X-Is-Troll'), null, 'Checking unexisting header');
});
casper.run(function () {
server.close();
this.test.done();
});