private void ValidateRequestFormat([NotNull] HttpContextPipelineHandlerContext context, [NotNull] out JsonRpcRequestBase payload) { var c = RpcSessionContext.Wrap(context); foreach (var validator in _validators) { validator.Validate(c); } var body = context.HttpContext.Request.Body.ReadAllBytes(); var o = Utilities.Serializer.Deserialize <JObject>(body); Trace.Assert(o != null, nameof(o) + " != null"); // TODO: check object properties // e.g.: o.ContainsKey("method") if (o.ContainsKey("id")) { payload = o.ToObject <JsonRpcRequest>(); } else { payload = o.ToObject <JsonRpcNotification>(); } }
public Task ProcessRequestAsync(HttpContextPipelineHandlerContext context) { ValidateRequestFormat(context, out var payload); var c = RpcSessionContext.Wrap(context); c.SaveRequestBody(payload); return(Task.FromResult(0)); }
Task IHttpContextPipelineHandler.ProcessRequestAsync(HttpContextPipelineHandlerContext context) { var c = RpcSessionContext.Wrap(context); var skeleton = c.GetRequestBodyAsJsonRpc(); Trace.Assert(skeleton != null, nameof(skeleton) + " != null"); var methodName = skeleton.Method; if (_routes.TryGetValue(methodName, out var handler)) { Debug.Print("Found route: {0}", methodName); handler.Invoke(c); context.BreakPipeline = true; return(Task.FromResult(0)); } Debug.Print("Registered route not found for method '{0}'", methodName); return(Task.FromException(new InvalidRpcRequestException($"Route not found for method '{methodName}'"))); }