feat(network): introduce Response.remoteAddress() (#3192)
Closes #2171.
This commit is contained in:
parent
52cf16c73c
commit
1ba2b8540d
@ -265,6 +265,7 @@
|
||||
* [response.headers()](#responseheaders)
|
||||
* [response.json()](#responsejson)
|
||||
* [response.ok()](#responseok)
|
||||
* [response.remoteAddress()](#responseremoteaddress)
|
||||
* [response.request()](#responserequest)
|
||||
* [response.securityDetails()](#responsesecuritydetails)
|
||||
* [response.status()](#responsestatus)
|
||||
@ -3072,6 +3073,11 @@ This method will throw if the response body is not parsable via `JSON.parse`.
|
||||
|
||||
Contains a boolean stating whether the response was successful (status in the range 200-299) or not.
|
||||
|
||||
#### response.remoteAddress()
|
||||
- returns: <[Object]>
|
||||
- `ip` <[string]> the IP address of the remote server
|
||||
- `port` <[number]> the port used to connect to the remote server
|
||||
|
||||
#### response.request()
|
||||
- returns: <[Request]> A matching [Request] object.
|
||||
|
||||
|
@ -522,6 +522,10 @@ class Response {
|
||||
this._bodyLoadedPromiseFulfill = fulfill;
|
||||
});
|
||||
|
||||
this._remoteAddress = {
|
||||
ip: responsePayload.remoteIPAddress,
|
||||
port: responsePayload.remotePort,
|
||||
};
|
||||
this._status = responsePayload.status;
|
||||
this._url = request.url();
|
||||
this._fromDiskCache = !!responsePayload.fromDiskCache;
|
||||
@ -532,6 +536,13 @@ class Response {
|
||||
this._securityDetails = responsePayload.securityDetails ? new SecurityDetails(responsePayload.securityDetails) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {{ip: string, port: number}}
|
||||
*/
|
||||
remoteAddress() {
|
||||
return this._remoteAddress;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {string}
|
||||
*/
|
||||
|
@ -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');
|
||||
|
@ -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`;
|
||||
|
Loading…
Reference in New Issue
Block a user