aboutsummaryrefslogtreecommitdiff
path: root/context.d
diff options
context:
space:
mode:
authorNathan Lasseter <nathan@4574.co.uk>2013-10-24 21:08:50 +0100
committerNathan Lasseter <nathan@4574.co.uk>2013-10-24 21:08:50 +0100
commitf3ee7526e1f04ccee1f1a4d3a775e2ce75169926 (patch)
treec49717071752e759ec7e63f002bbbdccc7d3338d /context.d
parent8480e8287fdf3aa933ad7b82457b3e67ab0bfa0b (diff)
Initial implementation of client context, headers not working.
Diffstat (limited to 'context.d')
-rw-r--r--context.d65
1 files changed, 65 insertions, 0 deletions
diff --git a/context.d b/context.d
new file mode 100644
index 0000000..965fe72
--- /dev/null
+++ b/context.d
@@ -0,0 +1,65 @@
+import
+ std.socket,
+ std.file,
+ std.string,
+ std.format,
+ std.stdio;
+import
+ serverutils;
+
+enum ClientState {
+ START,
+ REQUEST_LINE,
+ HEADER_LINES,
+ DONE,
+ ERROR
+};
+
+class Request {
+ string method;
+ string path;
+ string vers;
+ char[][] header_lines;
+ auto this(char[] line) {
+ line = strip(line);
+ formattedRead(line, "%s %s %s", &method, &path, &vers);
+ }
+}
+
+class ClientContext {
+ ClientState state;
+ Socket pair;
+ Request request;
+ auto this(Socket p) {
+ pair = p;
+ state = ClientState.START;
+ }
+ void handle() {
+ while(true) {
+ switch(state) {
+ case ClientState.START:
+ char[255] line;
+ auto len = pair.receive(line);
+ auto request_line = line[0 .. len];
+ request = new Request(request_line);
+ state = ClientState.REQUEST_LINE;
+ break;
+ case ClientState.REQUEST_LINE:
+ state
+ break;
+ case ClientState.HEADER_LINES:
+ if (inRoot(request.path))
+ pair.send(readText(request.path));
+ else
+ pair.send("ERROR: Client left root!\n");
+ state = ClientState.DONE;
+ break;
+ case ClientState.DONE:
+ return;
+ break;
+ default:
+ break;
+ }
+ }
+ }
+}