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

Function handleHttp

scripts/mars-web-bridge.mjs:546–585  ·  view source on GitHub ↗

@returns {boolean} true when the request was a MARS request and handled

(req, res)

Source from the content-addressed store, hash-verified

544
545 /** @returns {boolean} true when the request was a MARS request and handled */
546 handleHttp(req, res) {
547 const url = req.url ?? "/";
548 if (!url.startsWith(`${MARS_WEB_PREFIX}/`)) return false;
549 if (isCrossOrigin(req) || isForeignHost(req, host)) {
550 writeJson(res, 403, {
551 error: { message: "cross-origin request refused" },
552 });
553 return true;
554 }
555 const pathOnly = url.split(/[?#]/)[0];
556 if (pathOnly === HEALTH_PATH) {
557 // Unauthenticated on purpose: it only says the bridge is here.
558 writeJson(res, 200, { ok: true, authRequired: key !== null });
559 return true;
560 }
561 const auth = authorize(req);
562 if (auth === "deny") {
563 writeJson(res, 401, { error: { message: "session key required" } });
564 return true;
565 }
566 if (auth === "issue") res.setHeader("Set-Cookie", cookieHeader());
567 if (pathOnly.startsWith(RPC_PREFIX)) {
568 void handleRpc(req, res, pathOnly.slice(RPC_PREFIX.length));
569 return true;
570 }
571 let session;
572 try {
573 session = parseSessionPath(url);
574 } catch (error) {
575 if (!(error instanceof BadSessionPath)) throw error;
576 writeJson(res, 400, { error: { message: error.message } });
577 return true;
578 }
579 if (session) {
580 proxyHttp(req, res, session);
581 return true;
582 }
583 writeJson(res, 404, { error: { message: "not found" } });
584 return true;
585 },
586
587 /** @returns {boolean} true when the upgrade was a MARS request and handled */
588 handleUpgrade(req, socket, head) {

Callers

nothing calls this directly

Calls 8

isCrossOriginFunction · 0.85
isForeignHostFunction · 0.85
writeJsonFunction · 0.85
authorizeFunction · 0.85
cookieHeaderFunction · 0.85
handleRpcFunction · 0.85
parseSessionPathFunction · 0.85
proxyHttpFunction · 0.70

Tested by

no test coverage detected