public void Parse(HttpListenerContext httpContext) { var httpRequest = httpContext.Request; var encoding = Encoding.UTF8; var rpcResultHandler = new AsyncCallback( callback => { var asyncData = ((JsonRpcStateAsync) callback); var result = asyncData.Result; var data = Encoding.UTF8.GetBytes(result); var request = ((HttpRpcResponse) asyncData.AsyncState); request.Response.ContentType = "application/json"; request.Response.ContentEncoding = encoding; request.Response.ContentLength64 = data.Length; request.Response.OutputStream.Write(data,0,data.Length); }); using (var reader = new StreamReader(httpRequest.InputStream, encoding)) { var line = reader.ReadToEnd(); Log.Verbose(line.PretifyJson()); var response = httpContext.Response; var rpcResponse = new HttpRpcResponse(line, response); var rpcContext = new HttpRpcContext(this, rpcResponse); var async = new JsonRpcStateAsync(rpcResultHandler, rpcResponse) { JsonRpc = line }; JsonRpcProcessor.Process(async, rpcContext); } }
public HttpRpcContext(IMiner miner, HttpRpcResponse response) { this.Miner = miner; this.Response = response; }