MCPcopy Create free account
hub / github.com/devcontainers/cli / headRequest

Function headRequest

src/spec-utils/httpRequest.ts:53–80  ·  view source on GitHub ↗
(options: { url: string; headers: Record<string, string> }, output: Log)

Source from the content-addressed store, hash-verified

51
52// HTTP HEAD request that returns status code.
53export async function headRequest(options: { url: string; headers: Record<string, string> }, output: Log) {
54 const secureContext = await secureContextWithExtraCerts(output);
55 return new Promise<number>((resolve, reject) => {
56 const parsed = new url.URL(options.url);
57 const reqOptions: RequestOptions & tls.CommonConnectionOptions = {
58 hostname: parsed.hostname,
59 port: parsed.port,
60 path: parsed.pathname + parsed.search,
61 method: 'HEAD',
62 headers: options.headers,
63 agent: new ProxyAgent(),
64 secureContext,
65 };
66
67 const plainHTTP = parsed.protocol === 'http:' || parsed.hostname === 'localhost';
68 if (plainHTTP) {
69 output.write('Sending as plain HTTP request', LogLevel.Warning);
70 }
71
72 const req = (plainHTTP ? http : https).request(reqOptions, res => {
73 res.on('error', reject);
74 output.write(`HEAD ${options.url} -> ${res.statusCode}`, LogLevel.Trace);
75 resolve(res.statusCode!);
76 });
77 req.on('error', reject);
78 req.end();
79 });
80}
81
82// Send HTTP Request.
83// Does not throw on status code, but rather always returns 'statusCode', 'resHeaders', and 'resBody'.

Callers

nothing calls this directly

Calls 4

resolveFunction · 0.85
onMethod · 0.80
writeMethod · 0.65

Tested by

no test coverage detected