Skip to content

Commit

Permalink
Merge pull request #2797 from vibe-d/webrpc
Browse files Browse the repository at this point in the history
Implement a bi-directional WebSocket based RPC system
  • Loading branch information
l-kramer authored Apr 12, 2024
2 parents 992a638 + 35b3567 commit 471ab85
Show file tree
Hide file tree
Showing 4 changed files with 850 additions and 22 deletions.
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

0 comments on commit 471ab85

Please sign in to comment.