protected override async Task <HttpResponseMessage> SendAsync(HttpRequestMessage httpRequest, CancellationToken cancellationToken) { var metadata = new Metadata(); foreach (var(key, value) in httpRequest.Headers) { metadata.Add(key, string.Join(",", value.ToArray())); } var context = TestServerCallContext.Create( method: httpRequest.Method.Method, host: httpRequest.RequestUri.Host, deadline: DateTime.UtcNow.AddHours(1), requestHeaders: metadata, cancellationToken: cancellationToken, peer: "127.0.0.1", authContext: null, contextPropagationToken: null, writeHeadersFunc: _ => TaskUtils.CompletedTask, writeOptionsGetter: () => new WriteOptions(), writeOptionsSetter: writeOptions => {}); var grpcRequest = await GrpcUtils.GetRequestFromRequestMessageAsync <InvokeServiceRequest>(httpRequest); var grpcResponse = await this.callbackService.OnInvoke(grpcRequest.Message, context); var streamContent = await GrpcUtils.CreateResponseContent(grpcResponse); var httpResponse = GrpcUtils.CreateResponse(HttpStatusCode.OK, streamContent); return(httpResponse); }
public async Task CompleteWithMessageAsync <TResponseEnvelope>(TResponseEnvelope value) where TResponseEnvelope : IMessage <TResponseEnvelope> { var content = await GrpcUtils.CreateResponseContent <TResponseEnvelope>(value); var response = GrpcUtils.CreateResponse(HttpStatusCode.OK, content); await CompleteAsync(response); }
public async Task <TRequestEnvelope> GetRequestEnvelopeAsync <TRequestEnvelope>() where TRequestEnvelope : IMessage <TRequestEnvelope>, new() { return(await GrpcUtils.GetRequestFromRequestMessageAsync <TRequestEnvelope>(this.Request)); }