From 3d9b8f40fc220a2568447059e129df88150257b8 Mon Sep 17 00:00:00 2001 From: Pavel Maltsev Date: Tue, 8 Jun 2021 19:14:31 +0300 Subject: [PATCH] Add HTTP/0.9 to Microsoft.AspNetCore.Http.HttpProtocol (#33280) --- .../Http.Abstractions/src/HttpProtocol.cs | 21 ++++++++++++++++++ .../src/PublicAPI.Unshipped.txt | 2 ++ .../test/HttpProtocolTests.cs | 22 ++++++++++++++++++- 3 files changed, 44 insertions(+), 1 deletion(-) diff --git a/src/Http/Http.Abstractions/src/HttpProtocol.cs b/src/Http/Http.Abstractions/src/HttpProtocol.cs index 229cb4396cf1..941bd6bce75e 100644 --- a/src/Http/Http.Abstractions/src/HttpProtocol.cs +++ b/src/Http/Http.Abstractions/src/HttpProtocol.cs @@ -19,23 +19,43 @@ public static class HttpProtocol // Please do NOT change these to 'const' + /// + /// HTTP protocol version 0.9. + /// + public static readonly string Http09 = "HTTP/0.9"; + /// /// HTTP protocol version 1.0. /// public static readonly string Http10 = "HTTP/1.0"; + /// /// HTTP protocol version 1.1. /// public static readonly string Http11 = "HTTP/1.1"; + /// /// HTTP protocol version 2. /// public static readonly string Http2 = "HTTP/2"; + /// /// HTTP protcol version 3. /// public static readonly string Http3 = "HTTP/3"; + /// + /// Returns a value that indicates if the HTTP request protocol is HTTP/0.9. + /// + /// The HTTP request protocol. + /// + /// if the protocol is HTTP/0.9; otherwise, . + /// + public static bool IsHttp09(string protocol) + { + return object.ReferenceEquals(Http09, protocol) || StringComparer.OrdinalIgnoreCase.Equals(Http09, protocol); + } + /// /// Returns a value that indicates if the HTTP request protocol is HTTP/1.0. /// @@ -102,6 +122,7 @@ public static string GetHttpProtocol(Version version) { Major: 2, Minor: 0 } => Http2, { Major: 1, Minor: 1 } => Http11, { Major: 1, Minor: 0 } => Http10, + { Major: 0, Minor: 9 } => Http09, _ => throw new ArgumentOutOfRangeException(nameof(version), "Version doesn't map to a known HTTP protocol.") }; } diff --git a/src/Http/Http.Abstractions/src/PublicAPI.Unshipped.txt b/src/Http/Http.Abstractions/src/PublicAPI.Unshipped.txt index 0d6ad2ae7320..6d5d01bfdbe3 100644 --- a/src/Http/Http.Abstractions/src/PublicAPI.Unshipped.txt +++ b/src/Http/Http.Abstractions/src/PublicAPI.Unshipped.txt @@ -19,6 +19,8 @@ Microsoft.AspNetCore.Http.Metadata.IFromServiceMetadata Microsoft.AspNetCore.Http.Endpoint.Endpoint(Microsoft.AspNetCore.Http.RequestDelegate? requestDelegate, Microsoft.AspNetCore.Http.EndpointMetadataCollection? metadata, string? displayName) -> void Microsoft.AspNetCore.Http.Endpoint.RequestDelegate.get -> Microsoft.AspNetCore.Http.RequestDelegate? Microsoft.AspNetCore.Routing.RouteValueDictionary.TryAdd(string! key, object? value) -> bool +static readonly Microsoft.AspNetCore.Http.HttpProtocol.Http09 -> string! +static Microsoft.AspNetCore.Http.HttpProtocol.IsHttp09(string! protocol) -> bool abstract Microsoft.AspNetCore.Http.HttpRequest.ContentType.get -> string? static Microsoft.AspNetCore.Builder.UseExtensions.Use(this Microsoft.AspNetCore.Builder.IApplicationBuilder! app, System.Func! middleware) -> Microsoft.AspNetCore.Builder.IApplicationBuilder! static Microsoft.AspNetCore.Builder.UseMiddlewareExtensions.UseMiddleware(this Microsoft.AspNetCore.Builder.IApplicationBuilder! app, System.Type! middleware, params object?[]! args) -> Microsoft.AspNetCore.Builder.IApplicationBuilder! diff --git a/src/Http/Http.Abstractions/test/HttpProtocolTests.cs b/src/Http/Http.Abstractions/test/HttpProtocolTests.cs index 640106a002b0..a3fd96299997 100644 --- a/src/Http/Http.Abstractions/test/HttpProtocolTests.cs +++ b/src/Http/Http.Abstractions/test/HttpProtocolTests.cs @@ -84,12 +84,32 @@ public void IsHttp10_Success(string protocol, bool match) Assert.Equal(match, HttpProtocol.IsHttp10(protocol)); } + [Fact] + public void Http09_Success() + { + Assert.Equal("HTTP/0.9", HttpProtocol.Http09); + } + + [Theory] + [InlineData("HTTP/0.9", true)] + [InlineData("http/0.9", true)] + [InlineData("HTTP/2", false)] + [InlineData("HTTP/1", false)] + [InlineData("HTTP/09", false)] + [InlineData(" HTTP/0.9", false)] + [InlineData("HTTP/0.9 ", false)] + public void IsHttp09_Success(string protocol, bool match) + { + Assert.Equal(match, HttpProtocol.IsHttp09(protocol)); + } + public static TheoryData s_ValidData = new TheoryData { { new Version(3, 0), "HTTP/3" }, { new Version(2, 0), "HTTP/2" }, { new Version(1, 1), "HTTP/1.1" }, - { new Version(1, 0), "HTTP/1.0" } + { new Version(1, 0), "HTTP/1.0" }, + { new Version(0, 9), "HTTP/0.9" } }; [Theory]