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 |
| { | ||
| 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.
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.
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.
I think there would be no need for @trusted escape hatch, if you do cast(const char[]).
There was a problem hiding this comment.
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