(
res: HttpResponse,
req: HttpRequest & { res: any; _query: any },
context,
)
| 170 | } |
| 171 | |
| 172 | private handleUpgrade( |
| 173 | res: HttpResponse, |
| 174 | req: HttpRequest & { res: any; _query: any }, |
| 175 | context, |
| 176 | ) { |
| 177 | debug("on upgrade"); |
| 178 | |
| 179 | this.prepare(req as unknown as HttpRequest & EngineRequest, res); |
| 180 | |
| 181 | req.res = res; |
| 182 | |
| 183 | const callback = async (errorCode, errorContext) => { |
| 184 | if (errorCode !== undefined) { |
| 185 | this.emit("connection_error", { |
| 186 | req, |
| 187 | code: errorCode, |
| 188 | message: Server.errorMessages[errorCode], |
| 189 | context: errorContext, |
| 190 | }); |
| 191 | this.abortRequest(res, errorCode, errorContext); |
| 192 | return; |
| 193 | } |
| 194 | |
| 195 | const id = req._query.sid; |
| 196 | let transport; |
| 197 | |
| 198 | if (id) { |
| 199 | const client = this.clients[id]; |
| 200 | if (!client) { |
| 201 | debug("upgrade attempt for closed client"); |
| 202 | return res.close(); |
| 203 | } else if (client.upgrading) { |
| 204 | debug("transport has already been trying to upgrade"); |
| 205 | return res.close(); |
| 206 | } else if (client.upgraded) { |
| 207 | debug("transport had already been upgraded"); |
| 208 | return res.close(); |
| 209 | } else { |
| 210 | debug("upgrading existing transport"); |
| 211 | transport = this.createTransport( |
| 212 | req._query.transport, |
| 213 | req as unknown as EngineRequest, |
| 214 | ); |
| 215 | client._maybeUpgrade(transport); |
| 216 | } |
| 217 | } else { |
| 218 | transport = await this.handshake( |
| 219 | req._query.transport, |
| 220 | req as unknown as EngineRequest, |
| 221 | (errorCode, errorContext) => |
| 222 | this.abortRequest(res, errorCode, errorContext), |
| 223 | ); |
| 224 | if (!transport) { |
| 225 | return; |
| 226 | } |
| 227 | } |
| 228 | |
| 229 | // emit headers events for WebSocket upgrades |
nothing calls this directly
no test coverage detected