(url)
| 307 | class BadSessionPath extends Error {} |
| 308 | |
| 309 | function parseSessionPath(url) { |
| 310 | if (!url.startsWith(SESSIONS_PREFIX)) return null; |
| 311 | const rest = url.slice(SESSIONS_PREFIX.length); |
| 312 | const slash = rest.indexOf("/"); |
| 313 | const queryStart = rest.search(/[?#]/); |
| 314 | const idEnd = |
| 315 | slash === -1 ? (queryStart === -1 ? rest.length : queryStart) : slash; |
| 316 | let sessionId; |
| 317 | try { |
| 318 | sessionId = decodeURIComponent(rest.slice(0, idEnd)); |
| 319 | } catch { |
| 320 | // A malformed escape must be a 400, not an exception out of the |
| 321 | // request handler that takes the whole server down. |
| 322 | throw new BadSessionPath("malformed session id in path"); |
| 323 | } |
| 324 | if (!sessionId) return null; |
| 325 | const tail = rest.slice(idEnd); |
| 326 | return { sessionId, path: tail.startsWith("/") ? tail : `/${tail}` }; |
| 327 | } |
| 328 | |
| 329 | /** Rewrite the request to what the session host should see. */ |
| 330 | function toUpstreamRequest(req, path) { |
no outgoing calls
no test coverage detected