mirror of
https://github.com/encounter/phantomjs.git
synced 2026-03-30 11:35:11 -07:00
f20835735c
The HTTP server launched by the test runner has a new endpoint called /echo. This simply echoes back some information (current on the made request, in the future it will be expanded to further information) formatted as JSON. This echo system facilitates easy testing for request header manipulation feature. https://github.com/ariya/phantomjs/issues/12439
26 lines
864 B
JavaScript
26 lines
864 B
JavaScript
var assert = require('../../assert');
|
|
var webpage = require('webpage');
|
|
|
|
// NOTE: HTTP header names are case-insensitive. Our test server
|
|
// returns the name in lowercase.
|
|
|
|
var page = webpage.create();
|
|
assert.typeOf(page.customHeaders, 'object');
|
|
assert.strictEqual(JSON.stringify(page.customHeaders), '{}');
|
|
|
|
page.customHeaders = { 'CustomHeader': 'ModifiedCustomValue' };
|
|
|
|
page.onResourceRequested = function(requestData, request) {
|
|
assert.typeOf(request.setHeader, 'function');
|
|
request.setHeader('CustomHeader', 'ModifiedCustomValue');
|
|
};
|
|
page.open('http://localhost:9180/echo', function (status) {
|
|
var json, headers;
|
|
assert.equal(status, 'success');
|
|
json = JSON.parse(page.plainText);
|
|
headers = json.headers;
|
|
assert.isTrue(headers.hasOwnProperty('customheader'));
|
|
assert.equal(headers.customheader, 'ModifiedCustomValue');
|
|
});
|
|
|