mirror of
https://github.com/danog/code-server.git
synced 2024-11-27 04:45:52 +01:00
Remove unnecessary return types
This commit is contained in:
parent
f6a5eaa965
commit
253cf1c438
@ -93,7 +93,7 @@ export class ApiHttpProvider extends HttpProvider {
|
||||
request: http.IncomingMessage,
|
||||
socket: net.Socket,
|
||||
head: Buffer,
|
||||
): Promise<true> {
|
||||
): Promise<void> {
|
||||
if (!this.authenticated(request)) {
|
||||
throw new Error("not authenticated")
|
||||
}
|
||||
@ -107,7 +107,7 @@ export class ApiHttpProvider extends HttpProvider {
|
||||
throw new HttpError("Not found", HttpCode.NotFound)
|
||||
}
|
||||
|
||||
private async handleStatusSocket(request: http.IncomingMessage, socket: net.Socket, head: Buffer): Promise<true> {
|
||||
private async handleStatusSocket(request: http.IncomingMessage, socket: net.Socket, head: Buffer): Promise<void> {
|
||||
const getMessageResponse = async (event: "health"): Promise<ServerMessage> => {
|
||||
switch (event) {
|
||||
case "health":
|
||||
@ -134,8 +134,6 @@ export class ApiHttpProvider extends HttpProvider {
|
||||
resolve()
|
||||
})
|
||||
})
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
/**
|
||||
@ -146,7 +144,7 @@ export class ApiHttpProvider extends HttpProvider {
|
||||
request: http.IncomingMessage,
|
||||
socket: net.Socket,
|
||||
head: Buffer,
|
||||
): Promise<true> {
|
||||
): Promise<void> {
|
||||
const sessionId = route.requestPath.replace(/^\//, "")
|
||||
logger.debug("connecting session", field("sessionId", sessionId))
|
||||
const ws = await new Promise<WebSocket>((resolve, reject) => {
|
||||
@ -177,8 +175,6 @@ export class ApiHttpProvider extends HttpProvider {
|
||||
}),
|
||||
),
|
||||
)
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -89,7 +89,7 @@ export class VscodeHttpProvider extends HttpProvider {
|
||||
return this._vscode
|
||||
}
|
||||
|
||||
public async handleWebSocket(route: Route, request: http.IncomingMessage, socket: net.Socket): Promise<true> {
|
||||
public async handleWebSocket(route: Route, request: http.IncomingMessage, socket: net.Socket): Promise<void> {
|
||||
if (!this.authenticated(request)) {
|
||||
throw new Error("not authenticated")
|
||||
}
|
||||
@ -113,7 +113,6 @@ export class VscodeHttpProvider extends HttpProvider {
|
||||
|
||||
const vscode = await this._vscode
|
||||
this.send({ type: "socket", query: route.query }, vscode, socket)
|
||||
return true
|
||||
}
|
||||
|
||||
private send(message: CodeServerMessage, vscode?: cp.ChildProcess, socket?: net.Socket): void {
|
||||
|
@ -147,14 +147,14 @@ export abstract class HttpProvider {
|
||||
_socket: net.Socket,
|
||||
_head: Buffer,
|
||||
/* eslint-enable @typescript-eslint/no-unused-vars */
|
||||
): Promise<true | undefined> {
|
||||
): Promise<void> {
|
||||
throw new HttpError("Not found", HttpCode.NotFound)
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle requests to the registered endpoint.
|
||||
*/
|
||||
public abstract handleRequest(route: Route, request: http.IncomingMessage): Promise<HttpResponse | undefined>
|
||||
public abstract handleRequest(route: Route, request: http.IncomingMessage): Promise<HttpResponse>
|
||||
|
||||
/**
|
||||
* Get the base relative to the provided route. For each slash we need to go
|
||||
@ -529,9 +529,6 @@ export class HttpServer {
|
||||
const route = this.parseUrl(request)
|
||||
try {
|
||||
const payload = this.maybeRedirect(request, route) || (await route.provider.handleRequest(route, request))
|
||||
if (!payload) {
|
||||
throw new HttpError("Not found", HttpCode.NotFound)
|
||||
}
|
||||
response.writeHead(payload.redirect ? HttpCode.Redirect : payload.code || HttpCode.Ok, {
|
||||
"Content-Type": payload.mime || getMediaMime(payload.filePath),
|
||||
...(payload.redirect ? { Location: this.constructRedirect(request, route, payload as RedirectResponse) } : {}),
|
||||
@ -633,11 +630,7 @@ export class HttpServer {
|
||||
throw new HttpError("Not found", HttpCode.NotFound)
|
||||
}
|
||||
|
||||
if (
|
||||
!(await route.provider.handleWebSocket(route, request, await this.socketProvider.createProxy(socket), head))
|
||||
) {
|
||||
throw new HttpError("Not found", HttpCode.NotFound)
|
||||
}
|
||||
await route.provider.handleWebSocket(route, request, await this.socketProvider.createProxy(socket), head)
|
||||
} catch (error) {
|
||||
socket.destroy(error)
|
||||
logger.warn(`discarding socket connection: ${error.message}`)
|
||||
|
Loading…
Reference in New Issue
Block a user