Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to turn off HTTPS on gRPC server

How can I turn off HTTPS on gRPC server? Is there any option?

like image 222
Silver Origami Avatar asked Nov 17 '22 02:11

Silver Origami


1 Answers

Despite it's an old question, I had to do this by myself recently and here is how I did it, based on the ASP.NET Core template from Visual Studio:

First you'll have to configure the kestrel webserver to use the HTTP2 protocol for HTTP (usually in Program.cs):

public static IHostBuilder CreateHostBuilder(string[] args) =>
    Host.CreateDefaultBuilder(args)
        .ConfigureWebHostDefaults(webBuilder =>
        {
          webBuilder.ConfigureKestrel(options =>
            options.ConfigureEndpointDefaults(defaults =>
              defaults.Protocols = HttpProtocols.Http2));
          webBuilder.UseStartup<Startup>();
        });

Now the server should be able to handle all calls, regardless of using HTTP or HTTPS.

After you did that, you just have to tell the client to allow using HTTP2 without HTTPS before you make your first call to the gRPC server:

AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);
var client = new GrpcTest.GrpcTestClient(GrpcChannel.ForAddress("http://localhost:5000"));

Sources:

  • https://learn.microsoft.com/en-us/aspnet/core/grpc/troubleshoot?view=aspnetcore-5.0#unable-to-start-aspnet-core-grpc-app-on-macos
  • https://learn.microsoft.com/en-us/aspnet/core/grpc/troubleshoot?view=aspnetcore-5.0#call-insecure-grpc-services-with-net-core-client
like image 111
Stefan El Avatar answered Dec 04 '22 14:12

Stefan El