-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrequestData.js
More file actions
85 lines (68 loc) · 1.65 KB
/
requestData.js
File metadata and controls
85 lines (68 loc) · 1.65 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
function ReqData(nodeReq, urlForm, pathInfo) {
this.req = nodeReq;
this.url = urlForm;
this.pathInfo = pathInfo;
this.method = nodeReq.method;
this.dispPath = null;
}
ReqData.prototype.baseUri = function() {
return "" + this.url.protocol + "//" + this.url.host;
};
ReqData.prototype.version = function() {
return '1.1';
};
ReqData.prototype.peer = function() {
return '0.0.0.0';
};
ReqData.prototype.dispPath = function() {
return this.url.pathname;
};
ReqData.prototype.path = function() {
return this.url.pathname;
};
ReqData.prototype.rawPath = function() {
return this.url.path;
};
ReqData.prototype.pathInfo = function(field) {
if (field) {
return this.pathInfo[field];
} else {
return this.pathInfo;
}
};
ReqData.prototype.pathTokens = function() {
return this.dispPath().split('/');
};
ReqData.prototype.getReqHeader = function(field) {
return this.reqHeaders()[field];
};
ReqData.prototype.reqHeaders = function() {
return this.req.headers;
};
ReqData.prototype.reqBody = function(cb) {
var body = "";
this.req.on("data", function(chunk) {
body += chunk.toString();
});
this.req.on("end", function() {
cb(body);
});
};
ReqData.prototype.getCookieValue = function(string) {};
ReqData.prototype.reqCookie = function() {
return this.getReqHeader('cookie');
};
ReqData.prototype.getQsValue = function(string, defaultValue) {
if (defaultValue) {
return this.url.query[string] || defaultValue;
} else {
return this.url.query[string];
}
};
ReqData.prototype.reqQs = function() {
return this.url.query;
};
ReqData.prototype.appRoot = function() {
return ".";
};
module.exports = ReqData;