MCPcopy Create free account
hub / github.com/OpenHands/OpenHands / parseSessionPath

Function parseSessionPath

scripts/mars-web-bridge.mjs:340–358  ·  view source on GitHub ↗
(url)

Source from the content-addressed store, hash-verified

338class BadSessionPath extends Error {}
339
340function 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. */
361function toUpstreamRequest(req, path) {

Callers 2

handleHttpFunction · 0.85
handleUpgradeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected