current position:Home>. net 6 new feature, supporting http / 3 endpoint Publishing

. net 6 new feature, supporting http / 3 endpoint Publishing

2021-08-26 05:04:43 webmote33

This is my participation 8 The fourth of the yuegengwen challenge 22 God , Check out the activity details :8 Yuegengwen challenge

  • Welcome to thumb up : Collection Leaving a message. Please correct any mistakes , Give roses , Fragrance in hand !
  • The author of this article : from webmote original , First appeared in 【 Nuggets 】
  • The author's motto : Life is about tossing , When you don't toss about life , Life begins to toss you , Let's go !


Http3 The protocol is built on UDP On the basis of , Yes , It's amazing , Formerly known as the great God of instability UDP, Now assume the underlying protocol of reliable communication protocol . In order to eliminate UDP uncertainty , stay UDP The agreement above , Added QUIC agreement .

Use QUIC Agreement in place of TCP The agreement is about reliable 、 Part of flow control , So it makes HTTP3 It can reliably carry out communication transmission .

stay .net 6 Preview version of core On , Microsoft added a pair of HTTP/3 Support for , This is Web It brought a lot of improvement .HTTP3 Brings faster connection settings and improved performance on low-quality networks .

From this, we can also see that Microsoft is interested in .net 6 High hopes given .

Microsoft Now add a pair of HTTP/3 Support and for HTTP/3 To configure TLS (https) Support for .

1. HTTP/3 TLS To configure

Let's see how to use the following command in small MVC Configure... In the application HTTP/3:

dotnet new mvc -o Http3Tls -n Http3Tls
cd Http3Tls
code .
 Copy code 

This command creates a MVC Applications , Switch to the project folder and open VSCode.

We need to be in Program.cs Middle configuration HTTP/3, As shown in the following code :

public class Program
    public static void Main(string[] args)

    public static IHostBuilder CreateHostBuilder(string[] args) =>
            .ConfigureWebHostDefaults(webBuilder =>
                    .ConfigureKestrel((context, options) =>
                        options.EnableAltSvc = true;
                        options.Listen(IPAddress.Any, 5001, listenOptions =>
							// Enables HTTP/3
                            listenOptions.Protocols = HttpProtocols.Http3;
                            // Adds a TLS certificate to the endpoint
                            listenOptions.UseHttps(httpsOptions =>
                                httpsOptions.ServerCertificate = LoadCertificate();
 Copy code 

Sign here EnableAltSvc Set a... For the browser Alt-Svc header .

To tell you that this is an existing HTTP/1 or HTTP/2 Alternative services . This needs to tell the browser , Alternative services - In this case it is HTTP/3 - Should be treated like existing services .

It needs a https Connect to ensure security and trust .

Use listenOptions.UseHttps To configure ssl Certificate .

Use listenOptions.Protocols = HttpProtocols.Http3; Activate Http3 service .

Yes , It's that simple , An adaptation http3 The service of the agreement has been set up .

2 http/3 Summary of advantages

because Http/3 agreement , be based on UDP, It avoids TCP、Http/1、HTTP/2 The classic question of , A safe, efficient and reliable HTTP Communication protocol .

with 0 RTT Establishing a connection 、 Smooth connection migration 、 Basically eliminated the team head blocking , And enhance the flow control and other characteristics , In the vast majority of scenarios, we get more than HTTP/2 Better results .

therefore Http /3 It must be http The future of the agreement .

3. Summary

Routine summary , rationality !

What's the knot , The result is the loneliness that I want you to praise but can't get .

You see this , Do you still care about a compliment ?

It's all great , Still care about a collection ?

All collected , Do you still care about a comment ?

copyright notice
author[webmote33],Please bring the original link to reprint, thank you.

Random recommended