Last change
on this file was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
815 bytes
|
Rev | Line | |
---|
[6a3a178] | 1 | 'use strict';
|
---|
| 2 |
|
---|
| 3 | var Headers = function() {
|
---|
| 4 | this.clear();
|
---|
| 5 | };
|
---|
| 6 |
|
---|
| 7 | Headers.prototype.ALLOWED_DUPLICATES = ['set-cookie', 'set-cookie2', 'warning', 'www-authenticate'];
|
---|
| 8 |
|
---|
| 9 | Headers.prototype.clear = function() {
|
---|
| 10 | this._sent = {};
|
---|
| 11 | this._lines = [];
|
---|
| 12 | };
|
---|
| 13 |
|
---|
| 14 | Headers.prototype.set = function(name, value) {
|
---|
| 15 | if (value === undefined) return;
|
---|
| 16 |
|
---|
| 17 | name = this._strip(name);
|
---|
| 18 | value = this._strip(value);
|
---|
| 19 |
|
---|
| 20 | var key = name.toLowerCase();
|
---|
| 21 | if (!this._sent.hasOwnProperty(key) || this.ALLOWED_DUPLICATES.indexOf(key) >= 0) {
|
---|
| 22 | this._sent[key] = true;
|
---|
| 23 | this._lines.push(name + ': ' + value + '\r\n');
|
---|
| 24 | }
|
---|
| 25 | };
|
---|
| 26 |
|
---|
| 27 | Headers.prototype.toString = function() {
|
---|
| 28 | return this._lines.join('');
|
---|
| 29 | };
|
---|
| 30 |
|
---|
| 31 | Headers.prototype._strip = function(string) {
|
---|
| 32 | return string.toString().replace(/^ */, '').replace(/ *$/, '');
|
---|
| 33 | };
|
---|
| 34 |
|
---|
| 35 | module.exports = Headers;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.