* Handles a request serving of client source and map * * @param req * @param res * @private
(req: http.IncomingMessage, res: http.ServerResponse)
| 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 |