beamable / BeamableProduct

The beamable product suite including com.beamable, com.beamable.server, microservice base image, portal, the installer, and build scripts
Other
5 stars 0 forks source link

C#MS Clients should allow sending custom HTTP headers #3546

Open allister-beamable opened 1 month ago

allister-beamable commented 1 month ago

Describe the Impetus for Your Feature Request

As a Game Maker implementing complex C#MS logic, In order to have a "side channel" for additional metadata, I want to supply custom HTTP request headers to C#MS calls.

In some patterns of C#MS usage, it may be useful to distinguish between data that should be passed as method arguments and data that is effectively in a different domain such as tagging categories of activity. As such, it would be useful to have HTTP headers as an alternative channel for request data going to C# Microservices. C#MS code is already set up to receive the request headers that come in, but the client-side code is not set up to add custom headers to a given request.

Describe the Solution You Would Like

Make the general Requester class capable of sending custom headers in addition to the headers that it normally sends. This ought to make the custom header stuff accessible anywhere that Requester is used. In addition, it would be nice to have convenience methods or parameters in C#MS generated client calls that allow insertion of custom HTTP request headers.

Maybe something like:

var client = new MyMicroserviceClient();
var response = await client.MyCall(123, "hello", extraHeaders: new HttpHeaders { ["X-EXAMPLE"] = "hello world" });

or possibly something like:

var client = new MyMicroserviceClient();
client.AddCustomHeader("X-EXAMPLE", "hello world");
var response = await client.MyCall(123, "hello");

Describe Alternatives You Have Considered

At present, the only reasonable alternative is to use an implementation of IHttpClient to make a HTTP request directly, replicating all of the HTTP method, X-BEAM-SCOPE header, Authorization header, and so on that Requester implicitly does.

cdhanna commented 1 month ago

Lets use a config object that will start by having a single headers field; but may extend to use hooks, or serialization callback settings.

We'd need to modify the ClientCodeGenerator class.

cdhanna commented 1 month ago

More convo needed for milestone and stuff. Outta time.

AminSojoudi commented 1 month ago

I can help if you want.

cdhanna commented 1 month ago

I can help if you want.

@AminSojoudi , thank you for your interest, but unfortunately we are not accepting contributions from outside Beamable. This is something we would love to do eventually, but we haven't setup the framework yet. We need to create a set of guidelines, best practices, and acceptance criteria before we can responsibly accept work from outside collaborators. You can of course open issues, comment on our existing issues, and upvote issues.

cdhanna commented 1 month ago

The ClientCodeGenerator.AddCallableMethod function needs to add an optional parameter. The new parameter should be an instance of a type that has yet to be created, called ClientRequestSettings (or something). The AddCallableMethod should also include that new parameter when it calls the MicroserviceClient.Request function (that function should accept this new paramater), and then it should get pipped into the RequestHelper function.

Once there, the implementation uses an IBeamableRequester, which also doesn't support headers, so we'd need to add support for sending headers at that level, or change the IRequester's SDKRequesterOptions<T> to include a headers dictionary.