HeaderHostTransformer.js 716 B

12345678910111213141516171819
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. const stream_1 = require("stream");
  4. class HeaderHostTransformer extends stream_1.Transform {
  5. constructor(opts = {}) {
  6. super(opts);
  7. this.host = opts.host || 'localhost';
  8. this.replaced = false;
  9. }
  10. _transform(data, encoding, callback) {
  11. callback(null, this.replaced // after replacing the first instance of the Host header we just become a regular passthrough
  12. ? data
  13. : data.toString().replace(/(\r\n[Hh]ost: )\S+/, (match, $1) => {
  14. this.replaced = true;
  15. return $1 + this.host;
  16. }));
  17. }
  18. }
  19. exports.default = HeaderHostTransformer;