-
Notifications
You must be signed in to change notification settings - Fork 100
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
Rework RpcServer.ProcessAsync to be non-terminal ASP.NET Middleware #687
Conversation
protected and extend the class? |
If we're going to do this, we should provide a mechanism to inject steps into the http pipeline that StartRpcServer creates. Maybe we should separate out the pipeline host code from the rest of RpcServer and make RpcServer a standard ASP.NET Middleware class? Should be pretty straightfoward since RpcServer already plugs into the http pipeline via app.run. WOuldn't take much to make it work with App.use |
It sounds good. |
I'll work on this later this week. |
OK, here's what I did:
These changes will allow neo-express to use |
Ping @erikzhang @shargon |
I don't understand why it should be modified like this. |
FYI, with 3.2 release on the horizon, I will get this PR updated shortly |
So that .Configure(app =>
{
app.UseResponseCompression();
app.Use(next => context => rpcServer.ProcessAsync(context, next));
app.Run(NeoExpressFunctionality);
}) This way, rpcServer always gets first crack at the request so that anything it considers worthy of a response is processed immediately and never gets passed down the pipeline. |
Never mind, just realized that the original code is also filtering. |
cc @erikzhang @shargon I am trying to get this merged for 3.2 |
app.Use(ProcessAsync); | ||
app.Run(InvalidRequestAsync); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should use InvalidRequestAsync
first and then run ProcessAsync
as the terminal middleware. Then InvalidRequestAsync
can catch the exceptions in ProcessAsync
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we're going to make ProcessAsync
the terminal middleware, then I think we should simply go back to the original commit in this PR and make ProcessAsync
public.
I split InvalidRequestAsync
out from ProcessAsync
so Express could insert its middleware in the ASP.NET Pipeline after ProcessAsync
. If ProcessAsync
is terminal middleware, then Express has no choice but to put its middleware before ProcessAsync
. Compatibility with RpcServer
is a high priority for Express, so I wanted to give ProcessAsync
the highest priority position in the ASP.NET pipeline. But that doesn't work if ProcessAsync
can only be used as terminal middleware.
Honestly, I don't care which approach we take. Simply making ProcessAsync
public is smaller and has no logic changes. Changing ProcessAsync
to be non-terminal means for less code for Express. Either approach works for me.
This will allow neo express to use RpcServer in an HTTP pipeline that RpcServer doesn't create