-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_req_obj.js
More file actions
52 lines (40 loc) · 1.13 KB
/
create_req_obj.js
File metadata and controls
52 lines (40 loc) · 1.13 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
function create_requ_obj(data)
{
var request = {body: "", qstring: {}, header: {},
params: {}, method: "", path: "", message: ""};
request.toString = function() {
return `
===========================================
${data}
-------------------------------------------
${request.method} ${request.path}`
}
var parts;
var header_lines;
var first_line;
var data_sent;
var i;
var j;
j = 0;
i = 1;
parts = data.toString().split('\r\n\r\n');
request.body = parts[1] || "";
header_lines = parts[0].toString().split('\n');
first_line = header_lines[0].toString().split(' ');
request.method = first_line[0];
request.path = first_line[1];
if (request.path.indexOf("?") != -1)
{
var sp = request.path.split('?', 1)
request.path = sp.shift()
request.qstring = sp.shift()
}
while (header_lines[i] != null)
{
request.header[header_lines[i].substring(0, header_lines[i].indexOf(":")).toLowerCase()] =
header_lines[i].substring(header_lines[i].indexOf(" ") + 1, header_lines[i].length);
i++;
}
return (request)
}
module.exports = create_requ_obj;