feat(network): introduce Response.remoteAddress() (#3192)

Closes #2171.
This commit is contained in:
Andrey Lushnikov
2018-09-04 20:39:59 +01:00
committed by GitHub
parent 52cf16c73c
commit 1ba2b8540d
4 changed files with 25 additions and 0 deletions

View File

@@ -56,6 +56,10 @@ module.exports.addTests = function({testRunner, expect}) {
expect(responses[0].fromCache()).toBe(false);
expect(responses[0].fromServiceWorker()).toBe(false);
expect(responses[0].request()).toBeTruthy();
const remoteAddress = responses[0].remoteAddress();
// Either IPv6 or IPv4, depending on environment.
expect(remoteAddress.ip === '[::1]' || remoteAddress.ip === '127.0.0.1').toBe(true);
expect(remoteAddress.port).toBe(server.PORT);
});
it('Response.fromCache()', async({page, server}) => {
@@ -196,6 +200,7 @@ module.exports.addTests = function({testRunner, expect}) {
const redirectChain = response.request().redirectChain();
expect(redirectChain.length).toBe(1);
expect(redirectChain[0].url()).toContain('/foo.html');
expect(redirectChain[0].response().remoteAddress().port).toBe(server.PORT);
});
});
@@ -250,6 +255,7 @@ module.exports.addTests = function({testRunner, expect}) {
});
const response = await page.goto(server.EMPTY_PAGE);
expect(response.ok()).toBe(true);
expect(response.remoteAddress().port).toBe(server.PORT);
});
xit('should work when POST is redirected with 302', async({page, server}) => {
server.setRedirect('/rredirect', '/empty.html');

View File

@@ -77,6 +77,7 @@ beforeAll(async state => {
const port = 8907 + state.parallelIndex * 2;
state.server = await SimpleServer.create(assetsPath, port);
state.server.enableHTTPCache(cachedPath);
state.server.PORT = port;
state.server.PREFIX = `http://localhost:${port}`;
state.server.CROSS_PROCESS_PREFIX = `http://127.0.0.1:${port}`;
state.server.EMPTY_PAGE = `http://localhost:${port}/empty.html`;
@@ -84,6 +85,7 @@ beforeAll(async state => {
const httpsPort = port + 1;
state.httpsServer = await SimpleServer.createHTTPS(assetsPath, httpsPort);
state.httpsServer.enableHTTPCache(cachedPath);
state.httpsServer.PORT = httpsPort;
state.httpsServer.PREFIX = `https://localhost:${httpsPort}`;
state.httpsServer.CROSS_PROCESS_PREFIX = `https://127.0.0.1:${httpsPort}`;
state.httpsServer.EMPTY_PAGE = `https://localhost:${httpsPort}/empty.html`;