@@ -94,14 +94,20 @@ const char* MatchPathSegment(const char* path, const char* expected) {
94
94
return nullptr ;
95
95
}
96
96
97
- void SendHttpResponse (InspectorSocket* socket, const std::string& response) {
98
- const char HEADERS[] = " HTTP/1.0 200 OK\r\n "
97
+ void SendHttpResponse (InspectorSocket* socket,
98
+ const std::string& response,
99
+ int code) {
100
+ const char HEADERS[] = " HTTP/1.0 %d OK\r\n "
99
101
" Content-Type: application/json; charset=UTF-8\r\n "
100
102
" Cache-Control: no-cache\r\n "
101
103
" Content-Length: %zu\r\n "
102
104
" \r\n " ;
103
105
char header[sizeof (HEADERS) + 20 ];
104
- int header_len = snprintf (header, sizeof (header), HEADERS, response.size ());
106
+ int header_len = snprintf (header,
107
+ sizeof (header),
108
+ HEADERS,
109
+ code,
110
+ response.size ());
105
111
socket->Write (header, header_len);
106
112
socket->Write (response.data (), response.size ());
107
113
}
@@ -110,7 +116,11 @@ void SendVersionResponse(InspectorSocket* socket) {
110
116
std::map<std::string, std::string> response;
111
117
response[" Browser" ] = " node.js/" NODE_VERSION;
112
118
response[" Protocol-Version" ] = " 1.1" ;
113
- SendHttpResponse (socket, MapToString (response));
119
+ SendHttpResponse (socket, MapToString (response), 200 );
120
+ }
121
+
122
+ void SendHttpNotFound (InspectorSocket* socket) {
123
+ SendHttpResponse (socket, " " , 404 );
114
124
}
115
125
116
126
void SendProtocolJson (InspectorSocket* socket) {
@@ -131,7 +141,7 @@ void SendProtocolJson(InspectorSocket* socket) {
131
141
CHECK_EQ (Z_STREAM_END, inflate (&strm, Z_FINISH));
132
142
CHECK_EQ (0 , strm.avail_out );
133
143
CHECK_EQ (Z_OK, inflateEnd (&strm));
134
- SendHttpResponse (socket, data);
144
+ SendHttpResponse (socket, data, 200 );
135
145
}
136
146
} // namespace
137
147
@@ -224,8 +234,9 @@ void PrintDebuggerReadyMessage(
224
234
const std::string& host,
225
235
const std::vector<InspectorSocketServer::ServerSocketPtr>& server_sockets,
226
236
const std::vector<std::string>& ids,
237
+ bool publish_uid_stderr,
227
238
FILE* out) {
228
- if (out == nullptr ) {
239
+ if (!publish_uid_stderr || out == nullptr ) {
229
240
return ;
230
241
}
231
242
for (const auto & server_socket : server_sockets) {
@@ -241,9 +252,15 @@ void PrintDebuggerReadyMessage(
241
252
242
253
InspectorSocketServer::InspectorSocketServer (
243
254
std::unique_ptr<SocketServerDelegate> delegate, uv_loop_t * loop,
244
- const std::string& host, int port, FILE* out)
245
- : loop_(loop), delegate_(std::move(delegate)), host_(host), port_(port),
246
- next_session_id_ (0 ), out_(out) {
255
+ const std::string& host, int port,
256
+ const InspectPublishUid& inspect_publish_uid, FILE* out)
257
+ : loop_(loop),
258
+ delegate_ (std::move(delegate)),
259
+ host_(host),
260
+ port_(port),
261
+ inspect_publish_uid_(inspect_publish_uid),
262
+ next_session_id_(0 ),
263
+ out_(out) {
247
264
delegate_->AssignServer (this );
248
265
state_ = ServerState::kNew ;
249
266
}
@@ -280,8 +297,11 @@ void InspectorSocketServer::SessionTerminated(int session_id) {
280
297
if (connected_sessions_.empty ()) {
281
298
if (was_attached && state_ == ServerState::kRunning
282
299
&& !server_sockets_.empty ()) {
283
- PrintDebuggerReadyMessage (host_, server_sockets_,
284
- delegate_->GetTargetIds (), out_);
300
+ PrintDebuggerReadyMessage (host_,
301
+ server_sockets_,
302
+ delegate_->GetTargetIds (),
303
+ inspect_publish_uid_.console ,
304
+ out_);
285
305
}
286
306
if (state_ == ServerState::kStopped ) {
287
307
delegate_.reset ();
@@ -294,6 +314,10 @@ bool InspectorSocketServer::HandleGetRequest(int session_id,
294
314
const std::string& path) {
295
315
SocketSession* session = Session (session_id);
296
316
InspectorSocket* socket = session->ws_socket ();
317
+ if (!inspect_publish_uid_.http ) {
318
+ SendHttpNotFound (socket);
319
+ return true ;
320
+ }
297
321
const char * command = MatchPathSegment (path.c_str (), " /json" );
298
322
if (command == nullptr )
299
323
return false ;
@@ -342,7 +366,7 @@ void InspectorSocketServer::SendListResponse(InspectorSocket* socket,
342
366
formatted_address);
343
367
target_map[" webSocketDebuggerUrl" ] = FormatAddress (detected_host, id, true );
344
368
}
345
- SendHttpResponse (socket, MapsToString (response));
369
+ SendHttpResponse (socket, MapsToString (response), 200 );
346
370
}
347
371
348
372
std::string InspectorSocketServer::GetFrontendURL (bool is_compat,
@@ -397,8 +421,11 @@ bool InspectorSocketServer::Start() {
397
421
}
398
422
delegate_.swap (delegate_holder);
399
423
state_ = ServerState::kRunning ;
400
- PrintDebuggerReadyMessage (host_, server_sockets_,
401
- delegate_->GetTargetIds (), out_);
424
+ PrintDebuggerReadyMessage (host_,
425
+ server_sockets_,
426
+ delegate_->GetTargetIds (),
427
+ inspect_publish_uid_.console ,
428
+ out_);
402
429
return true ;
403
430
}
404
431
0 commit comments