-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
55 lines (47 loc) · 1.01 KB
/
index.js
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
function Headers (headers) {
for (var key in headers || {}) {
this[key] = headers[key]
}
}
Headers.prototype.get = function (header) {
return this._value(header)
}
Headers.prototype.set = function (header, value) {
var name = this._name(header)
if (name) {
this[name] = value
}
else {
this[header] = value
}
}
Headers.prototype.remove = function (header) {
var name = this._name(header)
if (name) {
delete this[name]
}
}
Headers.prototype.toObject = function () {
var headers = {}
for (var key in this) {
if (this[key] !== undefined && typeof this[key] !== 'function') {
headers[key] = this[key]
}
}
return headers
}
Headers.prototype._name = function (header) {
for (var name in this) {
if (name.toLowerCase() === header.toLowerCase()) {
return name
}
}
}
Headers.prototype._value = function (header) {
for (var name in this) {
if (name.toLowerCase() === header.toLowerCase()) {
return this[name]
}
}
}
module.exports = Headers