forked from whiteblock/hobbits
-
Notifications
You must be signed in to change notification settings - Fork 7
/
ewp.d
48 lines (41 loc) · 1.12 KB
/
ewp.d
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
import std.stdio;
import std.string;
import std.array;
import std.conv;
//module ewp;
class request{
string _proto;
string _version;
string _command;
string _header;
string _body;
this(string input)
{
this.parse(input);
}
void parse(string input)
{
ptrdiff_t index = indexOf(input,'\n');
string request_line = input[0 .. index];
auto request = split(request_line,' ');
if(request.length < 5){
writeln("Not enough parameters");
}
_proto = request[0];
_version = request[1];
_command = request[2];
if(index != -1){
string request_body = input[index+1 .. $];
_header = request_body[0 .. to!int(request[3])];
_body = request_body[to!int(request[3]) .. to!int(request[3]) + to!int(request[4])];
}
}
string marshal()
{
string ret = _proto ~ " " ~ _version ~ " ";
ret = ret ~ _command;
ret = ret ~ " " ~ to!string(_header.length) ~ " " ~ to!string(_body.length);
ret = ret ~ "\n" ~ _header ~ _body;
return ret;
}
}