MCPcopy Create free account
hub / github.com/11ty/dev-server / fetchHeadersForRequest

Function fetchHeadersForRequest

test/testServerRequests.js:46–76  ·  view source on GitHub ↗
(t, server, path, extras)

Source from the content-addressed store, hash-verified

44}
45
46async function fetchHeadersForRequest(t, server, path, extras) {
47 let port = await server.getPort();
48
49 return new Promise(resolve => {
50 const options = {
51 hostname: 'localhost',
52 port,
53 path,
54 method: 'GET',
55 ...extras,
56 };
57
58 // Available status codes can be found here: http.STATUS_CODES
59 const successCodes = [
60 200, // OK
61 206, // Partial Content
62 ];
63 http.get(options, (res) => {
64 const { statusCode } = res;
65 if (!successCodes.includes(statusCode)) {
66 throw new Error("Invalid status code " + statusCode);
67 }
68
69 let headers = res.headers;
70 resolve(headers);
71
72 }).on('error', (e) => {
73 console.error(`Got error: ${e.message}`);
74 });
75 })
76}
77
78test("Standard request", async (t) => {
79 let server = new EleventyDevServer("test-server", "./test/stubs/", getOptions());

Callers 1

Calls 2

getPortMethod · 0.80
errorMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…