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

Function parseSessionPath

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

Source from the content-addressed store, hash-verified

307class BadSessionPath extends Error {}
308
309function 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. */
330function toUpstreamRequest(req, path) {

Callers 2

handleHttpFunction · 0.85
handleUpgradeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected