@@ -5,39 +5,57 @@ import api.danode;
5
5
6
6
void main (string [] args){
7
7
setGET(args);
8
- writeln(" HTTP/1.1 200 OK" );
9
- writeln(" Content-Type: text/html; charset=utf-8" );
10
- writeln(" Connection: Keep-Alive" ); // This is wrong, to test if the server handles it correctly
11
- writefln(" Server: %s" , SERVER [" SERVER_SOFTWARE" ]); // Keep-Alive MUST be specified with a Content-Length
12
- writefln(" X-Powered-By: %s %s.%s\n " , std.compiler.name , version_major, version_minor);
8
+ if (SERVER [" REQUEST_URI" ] == " /dmd.d" || SERVER [" REQUEST_URI" ] == " /" ) {
9
+ writeln(" HTTP/1.1 200 OK" );
10
+ writeln(" Content-Type: text/html; charset=utf-8" );
11
+ writeln(" Connection: Keep-Alive" ); // This is wrong, (Keep-Alive MUST be specified with a Content-Length) to test if the server handles it correctly
12
+ writefln(" Server: %s" , SERVER [" SERVER_SOFTWARE" ]);
13
+ writefln(" X-Powered-By: %s %s.%s\n " , std.compiler.name , version_major, version_minor);
13
14
14
- writeln(" <html>" );
15
- writeln(" <head>" );
16
- writeln(" <title>DaNode 'user defined' CGI (D) test script</title>" );
17
- writeln(" <meta name='author' content='Danny Arends'>" );
18
- writeln(" </head>" );
19
- writeln(" <body>" );
20
- writeln(" DaNode 'user defined' CGI (D) test script<br/>" );
21
- writefln(" Server: <small>%s</small><br/>" , SERVER );
22
- writefln(" Config: <small>%s</small><br/>" , CONFIG );
23
- writeln(" <form action='dmd.d' method='post' enctype='multipart/form-data'>" );
24
- writeln(" <table>" );
25
- writefln(" <tr><td><a href='dmd.d?test=GET&do'>GET</a>: </td><td> %s</td></tr>" , GET );
26
- writefln(" <tr><td>POST: </td><td> %s</td></tr>" , POST );
27
- writefln(" <tr><td>FILES: </td><td> %s</td></tr>" , FILES );
28
- writeln(" <tr><td>Test: </td><td> <input name='test' type='text'></td></tr>" );
29
- writeln(" <tr><td>File: </td><td> <input name='file' type='file'></td></tr>" );
30
- writeln(" <tr><td> </td><td> <input type='submit' value='POST'></td></tr>" );
31
- writeln(" </table>" );
32
- writeln(" </form>" );
15
+ writeln(" <html>" );
16
+ writeln(" <head>" );
17
+ writeln(" <title>DaNode 'user defined' CGI (D) test script</title>" );
18
+ writeln(" <meta name='author' content='Danny Arends'>" );
19
+ writeln(" </head>" );
20
+ writeln(" <body>" );
21
+ writeln(" DaNode 'user defined' CGI (D) test script<br/>" );
22
+ writefln(" Server: <small>%s</small><br/>" , SERVER );
23
+ writefln(" Config: <small>%s</small><br/>" , CONFIG );
24
+ writeln(" <form action='dmd.d' method='post' enctype='multipart/form-data'>" );
25
+ writeln(" <table>" );
26
+ writefln(" <tr><td><a href='dmd.d?test=GET&do'>GET</a>: </td><td> %s</td></tr>" , GET );
27
+ writefln(" <tr><td>POST: </td><td> %s</td></tr>" , POST );
28
+ writefln(" <tr><td>FILES: </td><td> %s</td></tr>" , FILES );
29
+ writeln(" <tr><td>Test: </td><td> <input name='test' type='text'></td></tr>" );
30
+ writeln(" <tr><td>File: </td><td> <input name='file' type='file'></td></tr>" );
31
+ writeln(" <tr><td> </td><td> <input type='submit' value='POST'></td></tr>" );
32
+ writeln(" </table>" );
33
+ writeln(" </form>" );
33
34
34
- foreach (file; FILES ){ // Handle any files that being uploaded
35
- string to = format(" %s/%s" , SERVER [" DOCUMENT_ROOT" ], file.name); // Choose a folder (here: root of the web folder) to save the uploads
36
- move_upload_file(file.loc, to); // Move the uploaded file to somewhere
37
- writefln(" Uploaded: %s to %s" , file.loc, to); // Add a message to the HTML
38
- }
35
+ foreach (file; FILES ){ // Handle any files that being uploaded
36
+ string to = format(" %s/%s" , SERVER [" DOCUMENT_ROOT" ], file.name); // Choose a folder (here: root of the web folder) to save the uploads
37
+ move_upload_file(file.loc, to); // Move the uploaded file to somewhere
38
+ writefln(" Uploaded: %s to %s" , file.loc, to); // Add a message to the HTML
39
+ }
40
+
41
+ writeln(" </body>" );
42
+ writeln(" </html>" );
43
+ } else {
44
+ writeln(" HTTP/1.1 404 Page Not Found" );
45
+ writeln(" Content-Type: text/html; charset=utf-8" );
46
+ writeln(" Connection: Close" );
47
+ writefln(" Server: %s" , SERVER [" SERVER_SOFTWARE" ]);
48
+ writefln(" X-Powered-By: %s %s.%s\n " , std.compiler.name , version_major, version_minor);
39
49
40
- writeln(" </body>" );
41
- writeln(" </html>" );
50
+ writeln(" <html>" );
51
+ writeln(" <head>" );
52
+ writeln(" <title>404 Page Not Found</title>" );
53
+ writeln(" <meta name='author' content='Danny Arends'>" );
54
+ writeln(" </head>" );
55
+ writeln(" <body>" );
56
+ writeln(" 404 - Page Not Found !" );
57
+ writeln(" </body>" );
58
+ writeln(" </html>" );
59
+ }
42
60
}
43
61
0 commit comments