(url)
| 338 | class BadSessionPath extends Error {} |
| 339 | |
| 340 | function parseSessionPath(url) { |
| 341 | if (!url.startsWith(SESSIONS_PREFIX)) return null; |
| 342 | const rest = url.slice(SESSIONS_PREFIX.length); |
| 343 | const slash = rest.indexOf("/"); |
| 344 | const queryStart = rest.search(/[?#]/); |
| 345 | const idEnd = |
| 346 | slash === -1 ? (queryStart === -1 ? rest.length : queryStart) : slash; |
| 347 | let sessionId; |
| 348 | try { |
| 349 | sessionId = decodeURIComponent(rest.slice(0, idEnd)); |
| 350 | } catch { |
| 351 | // A malformed escape must be a 400, not an exception out of the |
| 352 | // request handler that takes the whole server down. |
| 353 | throw new BadSessionPath("malformed session id in path"); |
| 354 | } |
| 355 | if (!sessionId) return null; |
| 356 | const tail = rest.slice(idEnd); |
| 357 | return { sessionId, path: tail.startsWith("/") ? tail : `/${tail}` }; |
| 358 | } |
| 359 | |
| 360 | /** Rewrite the request to what the session host should see. */ |
| 361 | function toUpstreamRequest(req, path) { |
no outgoing calls
no test coverage detected