Skip to content
Open
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
4 changes: 3 additions & 1 deletion docs/src/main/paradox/server-side/http2.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

## Enable HTTP/2 support

HTTP/2 can then be enabled through configuration:
HTTP/2 is enabled through configuration:

```
pekko.http.server.enable-http2 = on
```

Since Pekko HTTP 2.0.0, this defaults to `on`.

## Use `newServerAt(...).bind()` and HTTPS

HTTP/2 is primarily used over a secure HTTPS connection which takes care of protocol negotiation and falling back to HTTP/1.1 over TLS when the client does not support HTTP/2.
Expand Down
8 changes: 5 additions & 3 deletions http-core/src/main/resources/reference.conf
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ pekko.http {
#
# Note that this setting is intended to replace `pekko.http.server.preview.enable-http2`
# but that setting is still supported for compatibility reasons.
enable-http2 = off
# The default value changed to `on` in Pekko HTTP 2.0.0.
enable-http2 = on

# "PREVIEW" features that are not yet fully production ready.
# These flags can change or be removed between patch releases.
Expand All @@ -37,8 +38,9 @@ pekko.http {
#
# `Http().newServerAt(...).bindFlow` and `connectionSource()` are not supported.
#
# Note that this setting is ignored if `pekko.http.server.enable-http2` is set to `on`.
enable-http2 = ${pekko.http.server.enable-http2}
# Note that this setting is expected to be null or a boolean or `on`/`off`.
# It is ignored if `pekko.http.server.enable-http2` is set to `on`.
enable-http2 = null
}

# The time after which an idle connection will be automatically closed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ private[http] object ServerSettingsImpl extends SettingsCompanionImpl[ServerSett
terminationDeadlineExceededResponseFrom(c),
c.getString("parsing.error-handler"),
c.getFiniteDuration("stream-cancellation-delay"),
c.getBoolean("enable-http2") || c.getBoolean("preview.enable-http2"))
c.getBoolean("enable-http2") || (c.hasPath("preview.enable-http2") && c.getBoolean("preview.enable-http2")))
}

private def terminationDeadlineExceededResponseFrom(c: Config): HttpResponse = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,36 +33,47 @@ class ServerSettingsSpec extends PekkoSpec {
}
e.getMessage should include("does not contain the server-specific settings")
}
"default enableHttp2 to false" in {
"default enableHttp2 to true" in {
val serverSettings = ServerSettings(system)
serverSettings.enableHttp2 should ===(false)
serverSettings.enableHttp2 should ===(true)
}
"set enableHttp2 to true if preview.enable-http2 is on" in {
"set enableHttp2 to false if enable-http2 is off" in {
val cfg = ConfigFactory.parseString("""
pekko.http.server {
preview.enable-http2 = on
enable-http2 = off
}
""").withFallback(system.settings.config)
val serverSettings = ServerSettings(cfg)
serverSettings.enableHttp2 should ===(true)
serverSettings.enableHttp2 should ===(false)
}
"set enableHttp2 to true if enable-http2 is on" in {
"set enableHttp2 to true if enable-http2 is on and preview.enable-http2 is off" in {
val cfg = ConfigFactory.parseString("""
pekko.http.server {
enable-http2 = on
preview.enable-http2 = off
}
""").withFallback(system.settings.config)
val serverSettings = ServerSettings(cfg)
serverSettings.enableHttp2 should ===(true)
}
"set enableHttp2 to true if enable-http2 is on and preview.enable-http2 is off" in {
"set enableHttp2 to false if enable-http2 is off and preview.enable-http2 is off" in {
val cfg = ConfigFactory.parseString("""
pekko.http.server {
enable-http2 = on
enable-http2 = off
preview.enable-http2 = off
}
""").withFallback(system.settings.config)
val serverSettings = ServerSettings(cfg)
serverSettings.enableHttp2 should ===(false)
}
"set enableHttp2 to true if enable-http2 is off and preview.enable-http2 is on" in {
val cfg = ConfigFactory.parseString("""
pekko.http.server {
enable-http2 = off
preview.enable-http2 = on
}
""").withFallback(system.settings.config)
val serverSettings = ServerSettings(cfg)
serverSettings.enableHttp2 should ===(true)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ public static void main(String[] args) {
+ "pekko.actor.serialize-creators = off\n"
+ "pekko.actor.serialize-messages = off\n"
+ "#pekko.actor.default-dispatcher.throughput = 1000\n"
+ "pekko.actor.default-dispatcher.fork-join-executor.parallelism-max=8\n"
+ "pekko.http.server.enable-http2 = on\n");
+ "pekko.actor.default-dispatcher.fork-join-executor.parallelism-max=8\n");
ActorSystem system = ActorSystem.create("ServerTest", testConf);

Function<HttpRequest, CompletionStage<HttpResponse>> handler =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ class H2SpecIntegrationSpec extends PekkoFreeSpec(
loglevel = DEBUG
loggers = ["org.apache.pekko.http.impl.util.SilenceAllTestEventListener"]
http.server.log-unencrypted-network-bytes = 100
http.server.enable-http2 = on
http.server.http2.log-frames = on

actor.serialize-creators = off
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import pekko.stream.scaladsl.{ Source, Tcp }
import pekko.util.ByteString

class H2cUpgradeSpec extends PekkoSpecWithMaterializer("""
pekko.http.server.enable-http2 = on
pekko.http.server.http2.log-frames = on
""") {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ import org.scalatest.concurrent.ScalaFutures
class Http2ClientServerSpec extends PekkoSpecWithMaterializer(
"""pekko.http.server.http2.log-frames = on
pekko.http.server.log-unencrypted-network-bytes = 100
pekko.http.server.enable-http2 = on
pekko.http.client.http2.log-frames = on
pekko.http.client.log-unencrypted-network-bytes = 100
pekko.actor.serialize-messages = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,7 @@ class Http2PersistentClientTlsSpec extends Http2PersistentClientSpec(true)
class Http2PersistentClientPlaintextSpec extends Http2PersistentClientSpec(false)

abstract class Http2PersistentClientSpec(tls: Boolean) extends PekkoSpecWithMaterializer(
// FIXME: would rather use remote-address-attribute, but that doesn't work with HTTP/2
// see https://github.com/akka/akka-http/issues/3707
"""pekko.http.server.remote-address-attribute = on
pekko.http.server.enable-http2 = on
pekko.http.client.http2.log-frames = on
pekko.http.client.http2.max-persistent-attempts = 5
pekko.http.client.log-unencrypted-network-bytes = 100
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ class TelemetrySpiCypherSpec extends TelemetrySpiSpec(true)

abstract class TelemetrySpiSpec(useTls: Boolean) extends PekkoSpecWithMaterializer(
"""
pekko.http.server.enable-http2 = on
pekko.actor.serialize-messages = false
pekko.http.http2-telemetry-class = "org.apache.pekko.http.impl.engine.http2.TestTelemetryImpl"
""") with ScalaFutures with BeforeAndAfterAll {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import pekko.stream.scaladsl.Sink
import pekko.util.ByteString

class WithPriorKnowledgeSpec extends PekkoSpecWithMaterializer("""
pekko.http.server.enable-http2 = on
pekko.http.server.http2.log-frames = on
""") {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ object Http2ServerTest extends App {
pekko.actor.serialize-creators = off
pekko.actor.serialize-messages = off
#pekko.actor.default-dispatcher.throughput = 1000
pekko.actor.default-dispatcher.fork-join-executor.parallelism-max=8
pekko.http.server.enable-http2 = true
""")
pekko.actor.default-dispatcher.fork-join-executor.parallelism-max=8""")
implicit val system: ActorSystem = ActorSystem("ServerTest", testConf)
implicit val ec: ExecutionContext = system.dispatcher

Expand Down