-
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.
Output the HTTPStatusException message as the response status phrase.
This has been the intent for the message parameter the whole time, but just now attracted attention, because in the HTTP/1.x server the status phrase has actually never been set appropriately.
- Loading branch information
Showing
4 changed files
with
51 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
name "tests" | ||
description "Wrong host header tests" | ||
dependency "vibe-http" path="../../" | ||
versions "VibeDefaultMain" |
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,36 @@ | ||
import vibe.core.core; | ||
import vibe.core.log : logInfo; | ||
import vibe.core.net; | ||
import vibe.http.server; | ||
import vibe.stream.operations; | ||
import core.time : msecs, seconds; | ||
import std.datetime : Clock, UTC; | ||
|
||
shared static this() | ||
{ | ||
auto s1 = new HTTPServerSettings; | ||
s1.options &= ~HTTPServerOption.errorStackTraces; | ||
s1.port = 0; | ||
s1.bindAddresses = ["127.0.0.1"]; | ||
immutable serverAddr = listenHTTP(s1, &handler).bindAddresses[0]; | ||
|
||
runTask({ | ||
try { | ||
auto conn = connectTCP(serverAddr); | ||
conn.write("GET / HTTP/1.1\r\nHost: 127.0.0.1\r\nConnection: close\r\n\r\n"); | ||
string res = cast(string)conn.readLine(); | ||
assert(res == "HTTP/1.1 403 This is not accessible!", res); | ||
while (conn.readLine().length > 0) {} | ||
assert(cast(string)conn.readAllUTF8() == "403 - Forbidden\n\nThis is not accessible!"); | ||
} catch (Exception e) { | ||
assert(false, e.msg); | ||
} | ||
|
||
scope (exit) exitEventLoop(); | ||
}); | ||
} | ||
|
||
void handler(scope HTTPServerRequest req, scope HTTPServerResponse res) | ||
{ | ||
throw new HTTPStatusException(HTTPStatus.forbidden, "This is not accessible!"); | ||
} |