Your code seems rather nice.
That said, here are some remarks of a purely stylistic nature :-) :
- You can use foreach instead of for to simplify your loop
statements over arrays and other collections:
auto array = [1, 2, 3];
foreach (item; array) {
writeln (item);
}
foreach can also support indexed iteration of your items:
auto array = [a, b, c];
foreach (index, item; array) {
writefln (%d: %s, index, item);
}
and if you just want to iterate a certain amount of time, you can use
ranges:
foreach (index; 1..100) {
writeln (index);
}
- You don't have to put each class in a different file: you still can do
if you prefer it that way.
- I tend to prefer to have class members of same visibility grouped
together under a public:, protected: or private: block, either
using the colon or the braces instead of always specifying the
visibility - this kind of help me better understand what will be useful
when using the class.
- Associative arrays can be initialized with literals, so instead of
having lots of:
status_message[100] = Continue;
status_message[101] = ...
...
status_message[505] = HTTP Version not supported;
you can use:
status_message = [
100: Continue,
101: ...
505: HTTP Version not supported
];
which I find more concise.
- You can also use unified function calls:
instead of: to!string(port)
you can do: port.to!string
the latter having a more English feel when reading.
Again, these are purely stylistic considerations, D's flexibility allows
you to choose from many styles.
On a design standpoint, I would have preferred a delegate for the
processRequest() method instead of requiring the users to derive from
the WebServer class - on second thought, that may too be a stylistic
issue :-) .
Also related: I have started to write some high level bindings to the
Mongoose embedded webserver library, written in C (using Jacob
Carlsberg's dstep for the low level bindings). The source code is
available here: https://github.com/remy-j-a-moueza/mongooseD .
You may find some stuff to reuse or get inspiration from for your server.
Adam Ruppe also has a lot of interesting tools beyond the basic web
serving that you may get interested in
(https://github.com/adamdruppe/misc-stuff-including-D-programming-language-web-stuff).
On 08/31/2013 06:42 PM, gedaiu wrote:
Hi,
Because I have a personal project based on a custom web server, and I
couldn't find one implemented in D(excepting vibe.d), I started to
implement some web server classes in D with the hope that my work will
be useful to someone else as well. If you are interested in this
project, or if you want to contribute to it, here is the link to the git
repository:
https://github.com/gedaiu/DSWS
Also, I don't have a lot of experience with D and I would apreciate if
someone would like to spare some time for a code review for my work.
Thanks,
Bogdan