-
Notifications
You must be signed in to change notification settings - Fork 284
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 #2352 from tchaloupka/processing
HTTPServer - add support for HTTP informational status message sending
- Loading branch information
Showing
5 changed files
with
71 additions
and
1 deletion.
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 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,3 @@ | ||
name "tests" | ||
description "informational status response handling test" | ||
dependency "vibe-d:http" path="../../" |
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,49 @@ | ||
import core.time; | ||
import vibe.core.log; | ||
import vibe.core.core : exitEventLoop, runApplication, runTask, sleep; | ||
import vibe.http.client; | ||
import vibe.http.server; | ||
import vibe.stream.operations : readAllUTF8; | ||
|
||
void handleRequest(scope HTTPServerRequest req, scope HTTPServerResponse res) | ||
{ | ||
res.statusCode = HTTPStatus.processing; | ||
res.writeVoidBody(); | ||
|
||
sleep(100.msecs); | ||
res.statusCode = HTTPStatus.ok; | ||
res.writeBody("Hello, World!", "text/plain"); | ||
} | ||
|
||
void main() | ||
{ | ||
auto settings = new HTTPServerSettings; | ||
settings.port = 8099; | ||
settings.bindAddresses = ["::1", "127.0.0.1"]; | ||
|
||
auto l = listenHTTP(settings, &handleRequest); | ||
scope (exit) l.stopListening(); | ||
|
||
runTask({ | ||
bool got102, got200; | ||
scope (exit) exitEventLoop(); | ||
|
||
requestHTTP("http://127.0.0.1:8099/", null, | ||
(scope res) { | ||
if (res.statusCode == HTTPStatus.processing) { | ||
assert(!got200, "Status 200 received first"); | ||
got102 = true; | ||
} | ||
else if (res.statusCode == HTTPStatus.ok) { | ||
got200 = true; | ||
assert(res.bodyReader.readAllUTF8() == "Hello, World!"); | ||
} | ||
} | ||
); | ||
assert(got102, "Status 102 wasn't received"); | ||
assert(got200, "Status 200 wasn't received"); | ||
logInfo("All web tests succeeded."); | ||
}); | ||
|
||
runApplication(); | ||
} |