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

Implement a bi-directional WebSocket based RPC system #2797

Merged
merged 3 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions web/vibe/web/auth.d
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ struct Role {
static @property R!(Op.ident, name, void, void) opDispatch(string name)() { return R!(Op.ident, name, void, void).init; }
}

package auto handleAuthentication(alias fun, C)(C c, HTTPServerRequest req, HTTPServerResponse res)
package auto handleAuthentication(alias fun, C, AUTH_ARGS...)(C c, AUTH_ARGS auth_args)
{
import std.traits : MemberFunctionsTuple;

Expand All @@ -161,9 +161,9 @@ package auto handleAuthentication(alias fun, C)(C c, HTTPServerRequest req, HTTP
} else {
static assert(!is(AR == void), "Missing @auth(...)/@anyAuth attribute for method "~funname~".");

static if (!__traits(compiles, () @safe { c.authenticate(req, res); } ()))
static if (!__traits(compiles, () @safe { c.authenticate(auth_args); } ()))
pragma(msg, "Non-@safe .authenticate() methods are deprecated - annotate "~C.stringof~".authenticate() with @safe or @trusted.");
return () @trusted { return c.authenticate(req, res); } ();
return () @trusted { return c.authenticate(auth_args); } ();
}
} else {
// make sure that there are no @auth/@noAuth annotations for non-authorizing classes
Expand Down
4 changes: 2 additions & 2 deletions web/vibe/web/internal/rest/common.d
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import std.traits : hasUDA;

The given `TImpl` must be an `interface` or a `class` deriving from one.
*/
/*package(vibe.web.web)*/ struct RestInterface(TImpl)
/*package(vibe.web.web)*/ struct RestInterface(TImpl, bool support_webparam_attributes = true)
if (is(TImpl == class) || is(TImpl == interface))
{
@safe:
Expand Down Expand Up @@ -56,7 +56,7 @@ import std.traits : hasUDA;
alias I = TImpl;
else
alias I = BaseInterfaces[0];
static assert(getInterfaceValidationError!I is null, getInterfaceValidationError!(I));
static assert(getInterfaceValidationError!(I, support_webparam_attributes) is null, getInterfaceValidationError!(I, support_webparam_attributes));

/// The name of each interface member
enum memberNames = [__traits(allMembers, I)];
Expand Down
36 changes: 19 additions & 17 deletions web/vibe/web/rest.d
Original file line number Diff line number Diff line change
Expand Up @@ -1006,7 +1006,7 @@ struct Collection(I)
alias ParentIDs = AllIDs[0 .. $-1];
alias ParentIDNames = AllIDNames[0 .. $-1];

private {
package {
I m_interface;
ParentIDs m_parentIDs;
}
Expand Down Expand Up @@ -2359,7 +2359,7 @@ unittest
// Check that the interface is valid. Every checks on the correctness of the
// interface should be put in checkRestInterface, which allows to have consistent
// errors in the server and client.
package string getInterfaceValidationError(I)()
package string getInterfaceValidationError(I, bool support_webparam_attributes = true)()
out (result) { assert((result is null) == !result.length); }
do {
import vibe.web.internal.rest.common : ParameterKind, WebParamUDATuple;
Expand Down Expand Up @@ -2416,21 +2416,23 @@ do {
}

// Check for misplaced out and non-const ref
alias PSC = ParameterStorageClass;
foreach (i, SC; ParameterStorageClassTuple!Func) {
static if (SC & PSC.out_ || (SC & PSC.ref_ && !is(ConstOf!(PT[i]) == PT[i])) ) {
mixin(GenCmp!("Loop", i, PN[i]).Decl);
alias Attr = AliasSeq!(
WebParamUDATuple!(Func, i),
Filter!(mixin(GenCmp!("Loop", i, PN[i]).Name), WPAT),
);
static if (Attr.length != 1) {
if (hack) return "%s: Parameter '%s' cannot be %s"
.format(FuncId, PN[i], SC & PSC.out_ ? "out" : "ref");
} else static if (Attr[0].origin != ParameterKind.header) {
if (hack) return "%s: %s parameter '%s' cannot be %s"
.format(FuncId, Attr[0].origin, PN[i],
SC & PSC.out_ ? "out" : "ref");
static if (support_webparam_attributes) {
alias PSC = ParameterStorageClass;
foreach (i, SC; ParameterStorageClassTuple!Func) {
static if (SC & PSC.out_ || (SC & PSC.ref_ && !is(ConstOf!(PT[i]) == PT[i])) ) {
mixin(GenCmp!("Loop", i, PN[i]).Decl);
alias Attr = AliasSeq!(
WebParamUDATuple!(Func, i),
Filter!(mixin(GenCmp!("Loop", i, PN[i]).Name), WPAT),
);
static if (Attr.length != 1) {
if (hack) return "%s: Parameter '%s' cannot be %s"
.format(FuncId, PN[i], SC & PSC.out_ ? "out" : "ref");
} else static if (Attr[0].origin != ParameterKind.header) {
if (hack) return "%s: %s parameter '%s' cannot be %s"
.format(FuncId, Attr[0].origin, PN[i],
SC & PSC.out_ ? "out" : "ref");
}
}
}
}
Expand Down
Loading
Loading