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

Function proxyServerInfoRequest

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

Source from the content-addressed store, hash-verified

100}
101
102export function proxyServerInfoRequest(
103 req,
104 res,
105 backendUrl,
106 runtimeServicesInfo,
107) {
108 let backend;
109 try {
110 backend = parseBackendUrl(backendUrl);
111 } catch {
112 writeInvalidBackendUrlResponse(req, res);
113 return;
114 }
115
116 const request = backend.protocol === "https:" ? httpsRequest : httpRequest;
117 const proxyReq = request(
118 {
119 hostname: backend.hostname,
120 port: backend.port,
121 path: req.url,
122 method: req.method,
123 headers: {
124 ...req.headers,
125 host: `${backend.hostname}:${backend.port}`,
126 },
127 },
128 (proxyRes) => {
129 const chunks = [];
130
131 proxyRes.on("data", (chunk) => {
132 chunks.push(Buffer.from(chunk));
133 });
134
135 proxyRes.on("error", (err) => {
136 if (!isBenignSocketError(err)) {
137 console.error(`Upstream response error for ${req.url}:`, err.message);
138 }
139 if (!res.headersSent) {
140 res.writeHead(502);
141 res.end(`Bad Gateway: ${err.message}`);
142 } else {
143 res.destroy();
144 }
145 });
146
147 proxyRes.on("end", () => {
148 const statusCode = proxyRes.statusCode ?? 502;
149 const headers = { ...proxyRes.headers };
150 const originalBody = Buffer.concat(chunks);
151
152 if (statusCode < 200 || statusCode >= 300 || req.method === "HEAD") {
153 res.writeHead(statusCode, headers);
154 res.end(req.method === "HEAD" ? "" : originalBody);
155 return;
156 }
157
158 try {
159 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