MCPcopy Index your code
hub / github.com/socketio/socket.io / serve

Method serve

lib/index.ts:571–601  ·  view source on GitHub ↗

* Handles a request serving of client source and map * * @param req * @param res * @private

(req: http.IncomingMessage, res: http.ServerResponse)

Source from the content-addressed store, hash-verified

569 * @private
570 */
571 private serve(req: http.IncomingMessage, res: http.ServerResponse): void {
572 const filename = req.url!.replace(this._path, "").replace(/\?.*$/, "");
573 const isMap = dotMapRegex.test(filename);
574 const type = isMap ? "map" : "source";
575
576 // Per the standard, ETags must be quoted:
577 // https://tools.ietf.org/html/rfc7232#section-2.3
578 const expectedEtag = '"' + clientVersion + '"';
579 const weakEtag = "W/" + expectedEtag;
580
581 const etag = req.headers["if-none-match"];
582 if (etag) {
583 if (expectedEtag === etag || weakEtag === etag) {
584 debug("serve client %s 304", type);
585 res.writeHead(304);
586 res.end();
587 return;
588 }
589 }
590
591 debug("serve client %s", type);
592
593 res.setHeader("Cache-Control", "public, max-age=0");
594 res.setHeader(
595 "Content-Type",
596 "application/" + (isMap ? "json" : "javascript") + "; charset=utf-8"
597 );
598 res.setHeader("ETag", expectedEtag);
599
600 Server.sendFile(filename, req, res);
601 }
602
603 /**
604 * @param filename

Callers 1

attachServeMethod · 0.95

Calls 1

sendFileMethod · 0.80

Tested by

no test coverage detected