zhangnaisong
2023-08-05 24d66c8d82b628a06e93dbb1abfea2049b3d45ab
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
'use strict';
 
var Headers = function() {
  this.clear();
};
 
Headers.prototype.ALLOWED_DUPLICATES = ['set-cookie', 'set-cookie2', 'warning', 'www-authenticate'];
 
Headers.prototype.clear = function() {
  this._sent  = {};
  this._lines = [];
};
 
Headers.prototype.set = function(name, value) {
  if (value === undefined) return;
 
  name = this._strip(name);
  value = this._strip(value);
 
  var key = name.toLowerCase();
  if (!this._sent.hasOwnProperty(key) || this.ALLOWED_DUPLICATES.indexOf(key) >= 0) {
    this._sent[key] = true;
    this._lines.push(name + ': ' + value + '\r\n');
  }
};
 
Headers.prototype.toString = function() {
  return this._lines.join('');
};
 
Headers.prototype._strip = function(string) {
  return string.toString().replace(/^ */, '').replace(/ *$/, '');
};
 
module.exports = Headers;