Skip to content
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

vibe.web.web: Allow to return strings #1854

Merged
merged 2 commits into from
Apr 3, 2018
Merged

Conversation

wilzbach
Copy link
Member

Split-off from #1697

@@ -964,6 +964,8 @@ private void handleRequest(string M, alias overload, C, ERROR...)(HTTPServerRequ
} else {
res.writeBody(ret);
}
} else static if (is(RET : string)) {
res.writeBody(ret);
} else {
static assert(is(RET == void), M~": Only InputStream, Json and void are supported as return types for route methods.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't forget to include string in the error message

@wilzbach
Copy link
Member Author

Don't forget to include string in the error message

Thanks. Added!

@wilzbach
Copy link
Member Author

@s-ludwig anything blocking this? Returning a string happens often enough, s.t. imho it justifies the convenience and also this is just an added bonus as a couple of return types (InputStream and Json are already accepted).

@wilzbach
Copy link
Member Author

wilzbach commented Apr 2, 2018

Ping @s-ludwig - I think this is a trivial, non-controversial addition and helps a lot of people as returning string is a frequent use case.

@WebFreak001
Copy link
Contributor

@s-ludwig merge pls, this is really useful and further changes can be done afterwards

@@ -1020,8 +1029,10 @@ private void handleRequest(string M, alias overload, C, ERROR...)(HTTPServerRequ
} else {
res.writeBody(ret);
}
} else static if (is(RET : string)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const(char)[] is sufficient here.

} else {
static assert(is(RET == void), M~": Only InputStream, Json and void are supported as return types for route methods.");
static assert(is(RET == void), M~": Only InputStream, Json, string and void are supported as return types for route methods.");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice to add const(ubyte)[] here, too (and change to const(char)[] if adjusted).

@s-ludwig
Copy link
Member

s-ludwig commented Apr 2, 2018

Couldn't find a compelling argument against this, especially considering that ubyte[] and char[] are already supported by writeBody in a similar way. Would just be nice to loosen this up to const(char)[] instead of string.

@wilzbach
Copy link
Member Author

wilzbach commented Apr 2, 2018

Would just be nice to loosen this up to const(char)[] instead of string.

Good idea. Done.

@dlang-bot dlang-bot merged commit e42f30b into vibe-d:master Apr 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants