MCPcopy Create free account
hub / github.com/protomaps/PMTiles / constructor

Method constructor

js/test/utils.ts:18–92  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

16 }
17
18 constructor() {
19 this.numRequests = 0;
20 this.etag = undefined;
21 this.lastRequestHeaders = null;
22 const serverBuffer = fs.readFileSync("test/data/test_fixture_1.pmtiles");
23 const serverBufferMlt = fs.readFileSync(
24 "test/data/test_fixture_mlt.pmtiles"
25 );
26 const server = setupServer(
27 http.get(
28 "http://localhost:1337/example.pmtiles",
29 ({ request, params }) => {
30 this.lastCache = request.cache;
31 this.lastRequestHeaders = request.headers;
32 this.lastCredentials = request.credentials;
33 this.numRequests++;
34 const range = request.headers.get("range")?.substr(6).split("-");
35 if (!range) {
36 throw new Error("invalid range");
37 }
38 const offset = +range[0];
39 const length = +range[1];
40 const body = serverBuffer.slice(offset, offset + length - 1);
41 return new HttpResponse(body, {
42 status: 206,
43 statusText: "OK",
44 headers: { etag: this.etag } as HeadersInit,
45 });
46 }
47 ),
48 http.get("http://localhost:1337/small.pmtiles", ({ request }) => {
49 this.lastRequestHeaders = request.headers;
50 this.lastCredentials = request.credentials;
51 this.numRequests++;
52 const range = request.headers.get("range")?.substr(6).split("-");
53 if (!range) {
54 throw new Error("invalid range");
55 }
56 const rangeEnd = +range[1];
57 if (rangeEnd >= serverBuffer.length) {
58 return new HttpResponse(null, {
59 status: 416,
60 headers: {
61 "Content-Range": `bytes */${serverBuffer.length}`,
62 },
63 });
64 }
65 const rangeStart = +range[0];
66 const body = serverBuffer.slice(rangeStart, rangeEnd + 1);
67 return new HttpResponse(body, {
68 status: 206,
69 headers: { etag: this.etag } as HeadersInit,
70 });
71 }),
72 http.get("http://localhost:1337/mlt.pmtiles", ({ request, params }) => {
73 this.lastCache = request.cache;
74 this.lastRequestHeaders = request.headers;
75 this.lastCredentials = request.credentials;

Callers

nothing calls this directly

Calls 1

getMethod · 0.45

Tested by

no test coverage detected