Skip to content
This repository has been archived by the owner on Dec 18, 2018. It is now read-only.

Enable Http/2 by default #2743

Merged
merged 1 commit into from
Jul 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions src/Kestrel.Core/CoreStrings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -354,9 +354,6 @@
<data name="EndPointRequiresAtLeastOneProtocol" xml:space="preserve">
<value>An endpoint must be configured to serve at least one protocol.</value>
</data>
<data name="EndPointRequiresTlsForHttp1AndHttp2" xml:space="preserve">
<value>Using both HTTP/1.x and HTTP/2 on the same endpoint requires the use of TLS.</value>
</data>
<data name="EndPointHttp2NotNegotiated" xml:space="preserve">
<value>HTTP/2 over TLS was not negotiated on an HTTP/2-only endpoint.</value>
</data>
Expand Down
11 changes: 6 additions & 5 deletions src/Kestrel.Core/Internal/HttpConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -363,11 +363,6 @@ private HttpProtocols SelectProtocol()
error = CoreStrings.EndPointRequiresAtLeastOneProtocol;
}

if (!hasTls && http1Enabled && http2Enabled)
{
error = CoreStrings.EndPointRequiresTlsForHttp1AndHttp2;
}

if (!http1Enabled && http2Enabled && hasTls && !Http2Id.Span.SequenceEqual(applicationProtocol.Span))
{
error = CoreStrings.EndPointHttp2NotNegotiated;
Expand All @@ -379,6 +374,12 @@ private HttpProtocols SelectProtocol()
return HttpProtocols.None;
}

if (!hasTls && http1Enabled)
{
// Even if Http2 was enabled, default to Http1 because it's ambiguous without ALPN.
return HttpProtocols.Http1;
}

return http2Enabled && (!hasTls || Http2Id.Span.SequenceEqual(applicationProtocol.Span)) ? HttpProtocols.Http2 : HttpProtocols.Http1;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Kestrel.Core/ListenOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ public FileHandleType HandleType
/// <summary>
/// The protocols enabled on this endpoint.
/// </summary>
/// <remarks>Defaults to HTTP/1.x only.</remarks>
public HttpProtocols Protocols { get; set; } = HttpProtocols.Http1;
/// <remarks>Defaults to HTTP/1.x and HTTP/2.</remarks>
public HttpProtocols Protocols { get; set; } = HttpProtocols.Http1AndHttp2;

/// <summary>
/// Gets the <see cref="List{IConnectionAdapter}"/> that allows each connection <see cref="System.IO.Stream"/>
Expand Down
14 changes: 0 additions & 14 deletions src/Kestrel.Core/Properties/CoreStrings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion test/Kestrel.Core.Tests/ListenOptionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class ListenOptionsTests
public void ProtocolsDefault()
{
var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0));
Assert.Equal(HttpProtocols.Http1, listenOptions.Protocols);
Assert.Equal(HttpProtocols.Http1AndHttp2, listenOptions.Protocols);
}

[Fact]
Expand Down
4 changes: 2 additions & 2 deletions test/Kestrel.FunctionalTests/HttpProtocolSelectionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ public Task Server_NoProtocols_Error()
}

[Fact]
public Task Server_Http1AndHttp2_Cleartext_Error()
public Task Server_Http1AndHttp2_Cleartext_Http1Default()
{
return TestError<InvalidOperationException>(HttpProtocols.Http1AndHttp2, CoreStrings.EndPointRequiresTlsForHttp1AndHttp2);
return TestSuccess(HttpProtocols.Http1AndHttp2, "GET / HTTP/1.1\r\nHost:\r\n\r\n", "HTTP/1.1 200 OK");
}

[Fact]
Expand Down