Skip to content

Add CORS support - fixes #501#507

Merged
PetarKirov merged 1 commit intodlang-tour:masterfrom
wilzbach:add-cors
Jun 29, 2017
Merged

Add CORS support - fixes #501#507
PetarKirov merged 1 commit intodlang-tour:masterfrom
wilzbach:add-cors

Conversation

@wilzbach
Copy link
Member

@wilzbach wilzbach commented May 7, 2017

Trying to get CORS support to work for dlang.org

@wilzbach wilzbach changed the title Add CORS support - fixes #501 [DO NOT MERGE] Add CORS support - fixes #501 May 7, 2017
@wilzbach
Copy link
Member Author

wilzbach commented May 7, 2017

Temporarily suspended, see also: dlang/dlang.org#1647

@wilzbach wilzbach changed the title [DO NOT MERGE] Add CORS support - fixes #501 Add CORS support - fixes #501 Jun 28, 2017
@wilzbach
Copy link
Member Author

Okay, this is back from the dead & it would be great to have for dlang/dlang.org#1647 (avoids the additional preflight OPTIONS request).

{
req.contentType = "application/json; charset=UTF-8";
auto bodyStr = () @trusted { return cast(string)req.bodyReader.readAll(); } ();
if (!bodyStr.empty) req.json = parseJson(bodyStr);
Copy link
Member Author

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.

Copy link
Member

@PetarKirov PetarKirov left a 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(); } ();
Copy link
Member

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[]).

Copy link
Member

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.

@wilzbach
Copy link
Member Author

I think there would be no need for @trusted escape hatch, if you do cast(const char[]).

Hehe I just copied this from Vibe.d
-> vibe-d/vibe.d#1799 (let's fix it upstream)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants