MCPcopy Index your code
hub / github.com/coder/code-server / requestResponse

Method requestResponse

src/node/update.ts:100–136  ·  view source on GitHub ↗
(uri: string)

Source from the content-addressed store, hash-verified

98 }
99
100 private async requestResponse(uri: string): Promise<http.IncomingMessage> {
101 let redirects = 0
102 const maxRedirects = 10
103 return new Promise((resolve, reject) => {
104 const request = (uri: string): void => {
105 logger.debug("Making request", field("uri", uri))
106 const isHttps = uri.startsWith("https")
107 const agent = new ProxyAgent({
108 keepAlive: true,
109 getProxyForUrl: () => httpProxyUri || "",
110 })
111 const httpx = isHttps ? https : http
112 const client = httpx.get(uri, { headers: { "User-Agent": "code-server" }, agent }, (response) => {
113 if (!response.statusCode || response.statusCode < 200 || response.statusCode >= 400) {
114 response.destroy()
115 return reject(new Error(`${uri}: ${response.statusCode || "500"}`))
116 }
117
118 if (response.statusCode >= 300) {
119 response.destroy()
120 ++redirects
121 if (redirects > maxRedirects) {
122 return reject(new Error("reached max redirects"))
123 }
124 if (!response.headers.location) {
125 return reject(new Error("received redirect with no location header"))
126 }
127 return request(url.resolve(uri, response.headers.location))
128 }
129
130 resolve(response)
131 })
132 client.on("error", reject)
133 }
134 request(uri)
135 })
136 }
137}

Callers 1

requestMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected