MCPcopy
hub / github.com/socketio/socket.io / serve

Method serve

packages/socket.io/lib/index.ts:646–676  ·  view source on GitHub ↗

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

(req: IncomingMessage, res: ServerResponse)

Source from the content-addressed store, hash-verified

644 * @private
645 */
646 private serve(req: IncomingMessage, res: ServerResponse): void {
647 const filename = req.url!.replace(this._path, "").replace(/\?.*$/, "");
648 const isMap = dotMapRegex.test(filename);
649 const type = isMap ? "map" : "source";
650
651 // Per the standard, ETags must be quoted:
652 // https://tools.ietf.org/html/rfc7232#section-2.3
653 const expectedEtag = '"' + clientVersion + '"';
654 const weakEtag = "W/" + expectedEtag;
655
656 const etag = req.headers["if-none-match"];
657 if (etag) {
658 if (expectedEtag === etag || weakEtag === etag) {
659 debug("serve client %s 304", type);
660 res.writeHead(304);
661 res.end();
662 return;
663 }
664 }
665
666 debug("serve client %s", type);
667
668 res.setHeader("Cache-Control", "public, max-age=0");
669 res.setHeader(
670 "Content-Type",
671 "application/" + (isMap ? "json" : "javascript") + "; charset=utf-8",
672 );
673 res.setHeader("ETag", expectedEtag);
674
675 Server.sendFile(filename, req, res);
676 }
677
678 /**
679 * @param filename

Callers 1

attachServeMethod · 0.95

Calls 5

debugFunction · 0.85
sendFileMethod · 0.80
writeHeadMethod · 0.45
endMethod · 0.45
setHeaderMethod · 0.45

Tested by

no test coverage detected