Skip to content
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

Required changes for 3.0.0 preview3 #112

Merged
merged 14 commits into from
Feb 21, 2019
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ branches:
only:
- master
install:
- curl -o dotnet-sdk.tar.gz -sSL https://download.visualstudio.microsoft.com/download/pr/efa6dde9-a5ee-4322-b13c-a2a02d3980f0/dad445eba341c1d806bae5c8afb47015/dotnet-sdk-3.0.100-preview-010184-linux-x64.tar.gz
- curl -o dotnet-sdk.tar.gz -sSL https://dotnetcli.blob.core.windows.net/dotnet/Sdk/release/3.0.1xx/dotnet-sdk-latest-linux-x64.tar.gz
- mkdir -p $PWD/dotnet
- tar zxf dotnet-sdk.tar.gz -C $PWD/dotnet
- export PATH="$PWD/dotnet:$PATH"
Expand Down
4 changes: 1 addition & 3 deletions examples/Server/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@

#endregion

using Grpc.AspNetCore;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;

namespace GRPCServer
Expand All @@ -34,7 +32,7 @@ public void ConfigureServices(IServiceCollection services)
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
public void Configure(IApplicationBuilder app)
{
app.UseRouting(routes =>
{
Expand Down
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"sdk": {
"version": "3.0.100-preview-010184"
"version": "3.0.100-preview3-010313"
}
}
4 changes: 1 addition & 3 deletions perf/benchmarkapps/BenchmarkServer/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@

#endregion

using Grpc.AspNetCore;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;

namespace BenchmarkServer
Expand All @@ -33,7 +31,7 @@ public void ConfigureServices(IServiceCollection services)
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
public void Configure(IApplicationBuilder app)
{
app.UseRouting(routes =>
{
Expand Down
24 changes: 23 additions & 1 deletion src/Grpc.AspNetCore.Server/Internal/PipeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,28 @@ public static Task WriteMessageAsync(this PipeWriter pipeWriter, byte[] messageD
return Task.FromException(new RpcException(SendingMessageExceedsLimitStatus));
}

// Must call StartAsync before the first pipeWriter.GetSpan() in WriteHeader
var response = serverCallContext.HttpContext.Response;
if (!response.HasStarted)
{
var startAsyncTask = response.StartAsync();
if (!startAsyncTask.IsCompletedSuccessfully)
{
return pipeWriter.WriteMessageCoreAsyncAwaited(messageData, serverCallContext, flush, startAsyncTask);
}
}

return pipeWriter.WriteMessageCoreAsync(messageData, serverCallContext, flush);
}

private static async Task WriteMessageCoreAsyncAwaited(this PipeWriter pipeWriter, byte[] messageData, HttpContextServerCallContext serverCallContext, bool flush, Task startAsyncTask)
{
await startAsyncTask;
await pipeWriter.WriteMessageCoreAsync(messageData, serverCallContext, flush);
}

private static Task WriteMessageCoreAsync(this PipeWriter pipeWriter, byte[] messageData, HttpContextServerCallContext serverCallContext, bool flush)
{
WriteHeader(pipeWriter, messageData.Length);
pipeWriter.Write(messageData);

Expand All @@ -77,7 +99,7 @@ public static Task WriteMessageAsync(this PipeWriter pipeWriter, byte[] messageD

private static void WriteHeader(PipeWriter pipeWriter, int length)
{
Span<byte> headerData = pipeWriter.GetSpan(HeaderSize);
var headerData = pipeWriter.GetSpan(HeaderSize);
// Messages are currently always uncompressed
headerData[0] = 0;
EncodeMessageLength(length, headerData.Slice(1));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@ public void MapGrpcService_CanBind_CreatesEndpoints()

var routeEndpoint1 = (RouteEndpoint)endpoints[0];
Assert.AreEqual("/Greet.Greeter/SayHello", routeEndpoint1.RoutePattern.RawText);
Assert.AreEqual("POST", ((IHttpMethodMetadata)routeEndpoint1.Metadata.Single()).HttpMethods.Single());
Assert.AreEqual("POST", routeEndpoint1.Metadata.GetMetadata<IHttpMethodMetadata>().HttpMethods.Single());

var routeEndpoint2 = (RouteEndpoint)endpoints[1];
Assert.AreEqual("/Greet.Greeter/SayHellos", routeEndpoint2.RoutePattern.RawText);
Assert.AreEqual("POST", ((IHttpMethodMetadata)routeEndpoint2.Metadata.Single()).HttpMethods.Single());
Assert.AreEqual("POST", routeEndpoint2.Metadata.GetMetadata<IHttpMethodMetadata>().HttpMethods.Single());
}

[Test]
Expand Down
8 changes: 1 addition & 7 deletions testassets/InteropTestsWebsite/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,9 @@

#endregion

using Grpc.AspNetCore;
using Grpc.Testing;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Features;
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;

namespace InteropTestsWebsite
{
Expand All @@ -38,7 +32,7 @@ public void ConfigureServices(IServiceCollection services)
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
public void Configure(IApplicationBuilder app)
{
app.UseRouting(builder =>
{
Expand Down