mirror of https://github.com/grpc/grpc-node.git
chore: extraneous closure, dont need server ref
This commit is contained in:
parent
0b79b7420a
commit
74102fcc87
|
@ -1191,131 +1191,127 @@ export class Server {
|
||||||
channelzSessionInfo?.streamTracker.addCallFailed();
|
channelzSessionInfo?.streamTracker.addCallFailed();
|
||||||
}
|
}
|
||||||
|
|
||||||
private _channelzHandler(http2Server: http2.Http2Server) {
|
private _channelzHandler(
|
||||||
return (
|
stream: http2.ServerHttp2Stream,
|
||||||
stream: http2.ServerHttp2Stream,
|
headers: http2.IncomingHttpHeaders
|
||||||
headers: http2.IncomingHttpHeaders
|
) {
|
||||||
) => {
|
// for handling idle timeout
|
||||||
// for handling idle timeout
|
this.onStreamOpened(stream);
|
||||||
this.onStreamOpened(stream);
|
|
||||||
|
|
||||||
const channelzSessionInfo = this.sessions.get(
|
const channelzSessionInfo = this.sessions.get(
|
||||||
stream.session as http2.ServerHttp2Session
|
stream.session as http2.ServerHttp2Session
|
||||||
);
|
);
|
||||||
|
|
||||||
this.callTracker.addCallStarted();
|
this.callTracker.addCallStarted();
|
||||||
channelzSessionInfo?.streamTracker.addCallStarted();
|
channelzSessionInfo?.streamTracker.addCallStarted();
|
||||||
|
|
||||||
if (!this._verifyContentType(stream, headers)) {
|
if (!this._verifyContentType(stream, headers)) {
|
||||||
this.callTracker.addCallFailed();
|
this.callTracker.addCallFailed();
|
||||||
channelzSessionInfo?.streamTracker.addCallFailed();
|
channelzSessionInfo?.streamTracker.addCallFailed();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const path = headers[HTTP2_HEADER_PATH] as string;
|
const path = headers[HTTP2_HEADER_PATH] as string;
|
||||||
|
|
||||||
const handler = this._retrieveHandler(path);
|
const handler = this._retrieveHandler(path);
|
||||||
if (!handler) {
|
if (!handler) {
|
||||||
this._respondWithError(
|
this._respondWithError(
|
||||||
getUnimplementedStatusResponse(path),
|
getUnimplementedStatusResponse(path),
|
||||||
stream,
|
|
||||||
channelzSessionInfo
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const callEventTracker: CallEventTracker = {
|
|
||||||
addMessageSent: () => {
|
|
||||||
if (channelzSessionInfo) {
|
|
||||||
channelzSessionInfo.messagesSent += 1;
|
|
||||||
channelzSessionInfo.lastMessageSentTimestamp = new Date();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
addMessageReceived: () => {
|
|
||||||
if (channelzSessionInfo) {
|
|
||||||
channelzSessionInfo.messagesReceived += 1;
|
|
||||||
channelzSessionInfo.lastMessageReceivedTimestamp = new Date();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
onCallEnd: status => {
|
|
||||||
if (status.code === Status.OK) {
|
|
||||||
this.callTracker.addCallSucceeded();
|
|
||||||
} else {
|
|
||||||
this.callTracker.addCallFailed();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
onStreamEnd: success => {
|
|
||||||
if (channelzSessionInfo) {
|
|
||||||
if (success) {
|
|
||||||
channelzSessionInfo.streamTracker.addCallSucceeded();
|
|
||||||
} else {
|
|
||||||
channelzSessionInfo.streamTracker.addCallFailed();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
const call = getServerInterceptingCall(
|
|
||||||
this.interceptors,
|
|
||||||
stream,
|
stream,
|
||||||
headers,
|
channelzSessionInfo
|
||||||
callEventTracker,
|
|
||||||
handler,
|
|
||||||
this.options
|
|
||||||
);
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!this._runHandlerForCall(call, handler)) {
|
const callEventTracker: CallEventTracker = {
|
||||||
this.callTracker.addCallFailed();
|
addMessageSent: () => {
|
||||||
channelzSessionInfo?.streamTracker.addCallFailed();
|
if (channelzSessionInfo) {
|
||||||
|
channelzSessionInfo.messagesSent += 1;
|
||||||
call.sendStatus({
|
channelzSessionInfo.lastMessageSentTimestamp = new Date();
|
||||||
code: Status.INTERNAL,
|
}
|
||||||
details: `Unknown handler type: ${handler.type}`,
|
},
|
||||||
});
|
addMessageReceived: () => {
|
||||||
}
|
if (channelzSessionInfo) {
|
||||||
|
channelzSessionInfo.messagesReceived += 1;
|
||||||
|
channelzSessionInfo.lastMessageReceivedTimestamp = new Date();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onCallEnd: status => {
|
||||||
|
if (status.code === Status.OK) {
|
||||||
|
this.callTracker.addCallSucceeded();
|
||||||
|
} else {
|
||||||
|
this.callTracker.addCallFailed();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onStreamEnd: success => {
|
||||||
|
if (channelzSessionInfo) {
|
||||||
|
if (success) {
|
||||||
|
channelzSessionInfo.streamTracker.addCallSucceeded();
|
||||||
|
} else {
|
||||||
|
channelzSessionInfo.streamTracker.addCallFailed();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const call = getServerInterceptingCall(
|
||||||
|
this.interceptors,
|
||||||
|
stream,
|
||||||
|
headers,
|
||||||
|
callEventTracker,
|
||||||
|
handler,
|
||||||
|
this.options
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!this._runHandlerForCall(call, handler)) {
|
||||||
|
this.callTracker.addCallFailed();
|
||||||
|
channelzSessionInfo?.streamTracker.addCallFailed();
|
||||||
|
|
||||||
|
call.sendStatus({
|
||||||
|
code: Status.INTERNAL,
|
||||||
|
details: `Unknown handler type: ${handler.type}`,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private _streamHandler(http2Server: http2.Http2Server) {
|
private _streamHandler(
|
||||||
return (
|
stream: http2.ServerHttp2Stream,
|
||||||
stream: http2.ServerHttp2Stream,
|
headers: http2.IncomingHttpHeaders
|
||||||
headers: http2.IncomingHttpHeaders
|
) {
|
||||||
) => {
|
// for handling idle timeout
|
||||||
// for handling idle timeout
|
this.onStreamOpened(stream);
|
||||||
this.onStreamOpened(stream);
|
|
||||||
|
|
||||||
if (this._verifyContentType(stream, headers) !== true) {
|
if (this._verifyContentType(stream, headers) !== true) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const path = headers[HTTP2_HEADER_PATH] as string;
|
const path = headers[HTTP2_HEADER_PATH] as string;
|
||||||
|
|
||||||
const handler = this._retrieveHandler(path);
|
const handler = this._retrieveHandler(path);
|
||||||
if (!handler) {
|
if (!handler) {
|
||||||
this._respondWithError(
|
this._respondWithError(
|
||||||
getUnimplementedStatusResponse(path),
|
getUnimplementedStatusResponse(path),
|
||||||
stream,
|
|
||||||
null
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const call = getServerInterceptingCall(
|
|
||||||
this.interceptors,
|
|
||||||
stream,
|
stream,
|
||||||
headers,
|
null
|
||||||
null,
|
|
||||||
handler,
|
|
||||||
this.options
|
|
||||||
);
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!this._runHandlerForCall(call, handler)) {
|
const call = getServerInterceptingCall(
|
||||||
call.sendStatus({
|
this.interceptors,
|
||||||
code: Status.INTERNAL,
|
stream,
|
||||||
details: `Unknown handler type: ${handler.type}`,
|
headers,
|
||||||
});
|
null,
|
||||||
}
|
handler,
|
||||||
};
|
this.options
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!this._runHandlerForCall(call, handler)) {
|
||||||
|
call.sendStatus({
|
||||||
|
code: Status.INTERNAL,
|
||||||
|
details: `Unknown handler type: ${handler.type}`,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private _runHandlerForCall(
|
private _runHandlerForCall(
|
||||||
|
@ -1361,14 +1357,14 @@ export class Server {
|
||||||
this.serverAddressString = serverAddressString;
|
this.serverAddressString = serverAddressString;
|
||||||
|
|
||||||
const handler = this.channelzEnabled
|
const handler = this.channelzEnabled
|
||||||
? this._channelzHandler(http2Server)
|
? this._channelzHandler
|
||||||
: this._streamHandler(http2Server);
|
: this._streamHandler;
|
||||||
|
|
||||||
const sessionHandler = this.channelzEnabled
|
const sessionHandler = this.channelzEnabled
|
||||||
? this._channelzSessionHandler(http2Server)
|
? this._channelzSessionHandler(http2Server)
|
||||||
: this._sessionHandler(http2Server);
|
: this._sessionHandler(http2Server);
|
||||||
|
|
||||||
http2Server.on('stream', handler);
|
http2Server.on('stream', handler.bind(this));
|
||||||
http2Server.on('session', sessionHandler);
|
http2Server.on('session', sessionHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue