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

Function proxyServerInfoRequest

scripts/proxy-utils.mjs:70–186  ·  view source on GitHub ↗
(
  req,
  res,
  backendUrl,
  runtimeServicesInfo,
)

Source from the content-addressed store, hash-verified

68}
69
70export function proxyServerInfoRequest(
71 req,
72 res,
73 backendUrl,
74 runtimeServicesInfo,
75) {
76 let backend;
77 try {
78 backend = parseBackendUrl(backendUrl);
79 } catch {
80 writeInvalidBackendUrlResponse(req, res);
81 return;
82 }
83
84 const request = backend.protocol === "https:" ? httpsRequest : httpRequest;
85 const proxyReq = request(
86 {
87 hostname: backend.hostname,
88 port: backend.port,
89 path: req.url,
90 method: req.method,
91 headers: {
92 ...req.headers,
93 host: `${backend.hostname}:${backend.port}`,
94 },
95 },
96 (proxyRes) => {
97 const chunks = [];
98
99 proxyRes.on("data", (chunk) => {
100 chunks.push(Buffer.from(chunk));
101 });
102
103 proxyRes.on("error", (err) => {
104 if (!isBenignSocketError(err)) {
105 console.error(`Upstream response error for ${req.url}:`, err.message);
106 }
107 if (!res.headersSent) {
108 res.writeHead(502);
109 res.end(`Bad Gateway: ${err.message}`);
110 } else {
111 res.destroy();
112 }
113 });
114
115 proxyRes.on("end", () => {
116 const statusCode = proxyRes.statusCode ?? 502;
117 const headers = { ...proxyRes.headers };
118 const originalBody = Buffer.concat(chunks);
119
120 if (statusCode < 200 || statusCode >= 300 || req.method === "HEAD") {
121 res.writeHead(statusCode, headers);
122 res.end(req.method === "HEAD" ? "" : originalBody);
123 return;
124 }
125
126 try {
127 const serverInfo = JSON.parse(originalBody.toString("utf8"));

Callers 2

startStaticServerFunction · 0.90
startIngressFunction · 0.90

Calls 5

parseBackendUrlFunction · 0.85
isBenignSocketErrorFunction · 0.85
errorMethod · 0.80
requestFunction · 0.70

Tested by

no test coverage detected