-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from andrewlalis/use-multivalue-map
Breaking Change: Version 8.0.0
- Loading branch information
Showing
42 changed files
with
1,361 additions
and
1,606 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
single-file-server/hello | ||
static-content-server/content_server | ||
*.log | ||
# Ignore all artifacts that might be generated. | ||
* | ||
|
||
# Except D source files and other stuff that's not auto-generated. | ||
!*.d | ||
!*.md | ||
!*.sh | ||
!*.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#!/usr/bin/env dub | ||
/+ dub.sdl: | ||
dependency "handy-httpd" path="../" | ||
+/ | ||
|
||
/** | ||
* This example shows how you can manage basic file-upload mechanics using | ||
* an HTML form and multipart/form-data encoding. In this example, we show a | ||
* simple form, and when the user uploads some files, a summary of the files | ||
* is shown. | ||
*/ | ||
module examples.file_upload; | ||
|
||
import handy_httpd; | ||
import slf4d; | ||
import handy_httpd.handlers.path_handler; | ||
|
||
const indexContent = ` | ||
<html> | ||
<body> | ||
<h4>Upload a file!</h4> | ||
<form action="/upload" method="post" enctype="multipart/form-data"> | ||
<input type="file" name="file1"> | ||
<input type="file" name="file2"> | ||
<input type="file" multiple name="other files"> | ||
<input type="submit" value="Submit"/> | ||
</form> | ||
</body> | ||
</html> | ||
`; | ||
|
||
void main(string[] args) { | ||
ServerConfig cfg = ServerConfig.defaultValues; | ||
if (args.length > 1) { | ||
import std.conv; | ||
cfg.port = args[1].to!ushort; | ||
} | ||
new HttpServer(new PathHandler() | ||
.addMapping(Method.GET, "/**", &serveIndex) // Show the index content to any request. | ||
.addMapping(Method.POST, "/upload", &handleUpload), // And handle uploads only on POST requests to /upload. | ||
cfg | ||
).start(); | ||
} | ||
|
||
void serveIndex(ref HttpRequestContext ctx) { | ||
ctx.response.writeBodyString(indexContent, "text/html; charset=utf-8"); | ||
} | ||
|
||
void handleUpload(ref HttpRequestContext ctx) { | ||
MultipartFormData data = readBodyAsMultipartFormData(ctx.request); | ||
string response = "File Upload Summary:\n\n"; | ||
foreach (i, MultipartElement element; data.elements) { | ||
import std.format; | ||
string filename = element.filename.isNull ? "NULL" : element.filename.get(); | ||
response ~= format! | ||
"Multipart Element %d of %d:\n\tFilename: %s\n\tSize: %d\n" | ||
( | ||
i + 1, | ||
data.elements.length, | ||
filename, | ||
element.content.length | ||
); | ||
foreach (string header, string value; element.headers) { | ||
response ~= format!"\t\tHeader \"%s\": \"%s\"\n"(header, value); | ||
} | ||
} | ||
ctx.response.writeBodyString(response); | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
9 changes: 7 additions & 2 deletions
9
examples/handler-testing/handler.d → examples/handler-testing.d
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.