-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add CORS support - fixes #501 #507
Conversation
Temporarily suspended, see also: dlang/dlang.org#1647 |
Okay, this is back from the dead & it would be great to have for dlang/dlang.org#1647 (avoids the additional preflight |
source/app.d
Outdated
{ | ||
req.contentType = "application/json; charset=UTF-8"; | ||
auto bodyStr = () @trusted { return cast(string)req.bodyReader.readAll(); } (); | ||
if (!bodyStr.empty) req.json = parseJson(bodyStr); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Basically what https://github.com/rejectedsoftware/vibe.d/blob/67ac2cf81f73854e00304c24aca5c889a627d6f4/http/vibe/http/server.d#L2016 does.
After the 0.8.0 release, I hope that my PR for lazy initialization hopefully gets accepted (vibe-d/vibe.d#1677), s.t. the manual parsing won't needed anymore.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, modulo the cast.
source/app.d
Outdated
if (req.contentType == "text/plain") | ||
{ | ||
req.contentType = "application/json; charset=UTF-8"; | ||
auto bodyStr = () @trusted { return cast(string)req.bodyReader.readAll(); } (); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there would be no need for @trusted
escape hatch, if you do cast(const char[])
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Additionally, it's better to avoid casting to immutable, because we may run into very surprising behavior due to compiler optimizations.
Hehe I just copied this from Vibe.d |
Trying to get CORS support to work for dlang.org