Skip to content

Commit 4d446e4

Browse files
committed
inspector: support Network.Response.statusText property
1 parent d823d8a commit 4d446e4

5 files changed

Lines changed: 27 additions & 5 deletions

File tree

lib/internal/inspector_network_tracking.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ function onClientResponseFinish({ request, response }) {
4040
response: {
4141
url,
4242
status: response.statusCode,
43+
statusText: response.statusMessage ?? '',
4344
headers: response.headers,
4445
},
4546
});

src/inspector/network_agent.cc

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,14 @@ std::unique_ptr<Network::Request> createRequest(
1717
}
1818

1919
std::unique_ptr<Network::Response> createResponse(
20-
const String& url, int status, std::unique_ptr<Network::Headers> headers) {
20+
const String& url,
21+
int status,
22+
const String& statusText,
23+
std::unique_ptr<Network::Headers> headers) {
2124
return Network::Response::create()
2225
.setUrl(url)
2326
.setStatus(status)
27+
.setStatusText(statusText)
2428
.setHeaders(std::move(headers))
2529
.build();
2630
}
@@ -96,6 +100,8 @@ void NetworkAgent::responseReceived(
96100
response->getString("url", &url);
97101
int status;
98102
response->getInteger("status", &status);
103+
String statusText;
104+
response->getString("statusText", &statusText);
99105

100106
ErrorSupport errors;
101107
auto headers =
@@ -104,10 +110,11 @@ void NetworkAgent::responseReceived(
104110
headers = std::make_unique<Network::Headers>(DictionaryValue::create());
105111
}
106112

107-
frontend_->responseReceived(request_id,
108-
timestamp,
109-
type,
110-
createResponse(url, status, std::move(headers)));
113+
frontend_->responseReceived(
114+
request_id,
115+
timestamp,
116+
type,
117+
createResponse(url, status, statusText, std::move(headers)));
111118
}
112119

113120
void NetworkAgent::loadingFinished(

src/inspector/node_protocol.pdl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ experimental domain Network
144144
properties
145145
string url
146146
integer status
147+
string statusText
147148
Headers headers
148149

149150
# Request / response headers as keys / values of JSON object.

test/parallel/test-inspector-emit-protocol-event.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,17 @@ const EXPECTED_EVENTS = {
4242
status: 200,
4343
headers: { host: 'nodejs.org' }
4444
}
45+
},
46+
expected: {
47+
requestId: 'request-id-1',
48+
timestamp: 1000,
49+
type: 'Other',
50+
response: {
51+
url: 'https://nodejs.org/en',
52+
status: 200,
53+
statusText: '', // Status text should be an empty string if not provided.
54+
headers: { host: 'nodejs.org' }
55+
}
4556
}
4657
},
4758
{

test/parallel/test-inspector-network-domain.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ const testHttpGet = () => new Promise((resolve, reject) => {
6161
assert.strictEqual(typeof params.timestamp, 'number');
6262
assert.strictEqual(params.type, 'Other');
6363
assert.strictEqual(params.response.status, 200);
64+
assert.strictEqual(params.response.statusText, 'OK');
6465
assert.strictEqual(params.response.url, 'http://127.0.0.1/hello-world');
6566
assert.strictEqual(typeof params.response.headers, 'object');
6667
}));
@@ -91,6 +92,7 @@ const testHttpsGet = () => new Promise((resolve, reject) => {
9192
assert.strictEqual(typeof params.timestamp, 'number');
9293
assert.strictEqual(params.type, 'Other');
9394
assert.strictEqual(params.response.status, 200);
95+
assert.strictEqual(params.response.statusText, 'OK');
9496
assert.strictEqual(params.response.url, 'https://127.0.0.1/hello-world');
9597
assert.strictEqual(typeof params.response.headers, 'object');
9698
}));

0 commit comments

Comments
 (0)