!htt #19514 Update RouterSettings to be non case class
This commit is contained in:
parent
379a3a85b4
commit
61b375cec8
26 changed files with 188 additions and 64 deletions
|
|
@ -132,3 +132,15 @@ Please consult the :class:`GraphStage` documentation (:ref:`graphstage-java`) an
|
|||
on migrating from :class:`AsyncStage` to :class:`GraphStage`.
|
||||
|
||||
.. _`previous migration guide`: http://doc.akka.io/docs/akka-stream-and-http-experimental/2.0.2/java/migration-guide-1.0-2.x-java.html#AsyncStage_has_been_replaced_by_GraphStage
|
||||
|
||||
|
||||
Changes in Akka HTTP
|
||||
====================
|
||||
|
||||
Routing settings parameter name
|
||||
-------------------------------
|
||||
|
||||
``RoutingSettings`` were previously the only setting available on ``RequestContext``,
|
||||
and were accessible via ``settings``. We now made it possible to configure the parsers
|
||||
settings as well, so ``RoutingSettings`` is now ``routingSettings`` and ``ParserSettings`` is
|
||||
now accessible via ``parserSettings``.
|
||||
|
|
@ -12,6 +12,7 @@ import akka.http.scaladsl.model._
|
|||
import akka.http.scaladsl.model.headers.{ Server, RawHeader }
|
||||
import akka.http.scaladsl.server.RouteResult.{ Complete, Rejected }
|
||||
import akka.http.scaladsl.server._
|
||||
import akka.http.scaladsl.settings.RoutingSettings
|
||||
import akka.stream.ActorMaterializer
|
||||
import akka.stream.scaladsl.{ FileIO, Sink, Source }
|
||||
import akka.util.ByteString
|
||||
|
|
@ -183,7 +184,7 @@ class BasicDirectivesExamplesSpec extends RoutingSpec {
|
|||
}
|
||||
"withSettings-0" in compileOnlySpec {
|
||||
//#withSettings-0
|
||||
val special = RoutingSettingsImpl(system).copy(fileIODispatcher = "special-io-dispatcher")
|
||||
val special = RoutingSettings(system).withFileIODispatcher("special-io-dispatcher")
|
||||
|
||||
def sample() =
|
||||
path("sample") {
|
||||
|
|
@ -687,7 +688,7 @@ class BasicDirectivesExamplesSpec extends RoutingSpec {
|
|||
"extractSettings-examples" in {
|
||||
//#extractSettings-examples
|
||||
val route =
|
||||
extractSettings { settings: RoutingSettingsImpl =>
|
||||
extractSettings { settings: RoutingSettings =>
|
||||
complete(s"RoutingSettings.renderVanityFooter = ${settings.renderVanityFooter}")
|
||||
}
|
||||
|
||||
|
|
@ -700,12 +701,12 @@ class BasicDirectivesExamplesSpec extends RoutingSpec {
|
|||
"mapSettings-examples" in {
|
||||
//#mapSettings-examples
|
||||
val tunedSettings = mapSettings { settings =>
|
||||
settings.copy(fileGetConditional = false)
|
||||
settings.withFileGetConditional(false)
|
||||
}
|
||||
|
||||
val route =
|
||||
tunedSettings {
|
||||
extractSettings { settings: RoutingSettingsImpl =>
|
||||
extractSettings { settings: RoutingSettings =>
|
||||
complete(s"RoutingSettings.fileGetConditional = ${settings.fileGetConditional}")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -87,7 +87,7 @@ Routing settings parameter name
|
|||
|
||||
``RoutingSettings`` were previously the only setting available on ``RequestContext``,
|
||||
and were accessible via ``settings``. We now made it possible to configure the parsers
|
||||
settings as well, so ``RoutingSettings`` is now ``routingSettings`` and ``ParserSetttings`` is
|
||||
settings as well, so ``RoutingSettings`` is now ``routingSettings`` and ``ParserSettings`` is
|
||||
now accessible via ``parserSettings``.
|
||||
|
||||
Changed Sources / Sinks
|
||||
|
|
|
|||
|
|
@ -2,11 +2,10 @@
|
|||
* Copyright (C) 2009-2014 Typesafe Inc. <http://www.typesafe.com>
|
||||
*/
|
||||
|
||||
package akka.http.scaladsl.server
|
||||
package akka.http.impl.settings
|
||||
|
||||
import com.typesafe.config.Config
|
||||
import akka.actor.ActorRefFactory
|
||||
import akka.http.impl.util._
|
||||
import com.typesafe.config.Config
|
||||
|
||||
/** INTERNAL API */
|
||||
final case class RoutingSettingsImpl(
|
||||
|
|
@ -16,7 +15,7 @@ final case class RoutingSettingsImpl(
|
|||
rangeCountLimit: Int,
|
||||
rangeCoalescingThreshold: Long,
|
||||
decodeMaxBytesPerChunk: Int,
|
||||
fileIODispatcher: String)
|
||||
fileIODispatcher: String) extends akka.http.scaladsl.settings.RoutingSettings
|
||||
|
||||
object RoutingSettingsImpl extends SettingsCompanion[RoutingSettingsImpl]("akka.http.routing") {
|
||||
def fromSubConfig(root: Config, c: Config) = new RoutingSettingsImpl(
|
||||
|
|
@ -15,7 +15,10 @@ import scala.collection.JavaConverters._
|
|||
import scala.compat.java8.OptionConverters._
|
||||
import scala.concurrent.duration.{ Duration, FiniteDuration }
|
||||
|
||||
abstract class ClientConnectionSettings {
|
||||
/**
|
||||
* Public API but not intended for subclassing
|
||||
*/
|
||||
abstract class ClientConnectionSettings private[akka] () { self: ClientConnectionSettingsImpl ⇒
|
||||
def getUserAgentHeader: Optional[UserAgent]
|
||||
def getConnectingTimeout: FiniteDuration
|
||||
def getIdleTimeout: Duration
|
||||
|
|
@ -34,8 +37,6 @@ abstract class ClientConnectionSettings {
|
|||
def withSocketOptions(newValue: java.lang.Iterable[SocketOption]): ClientConnectionSettings = self.copy(socketOptions = newValue.asScala.toList)
|
||||
def withParserSettings(newValue: ParserSettings): ClientConnectionSettings = self.copy(parserSettings = newValue.asScala)
|
||||
|
||||
/** INTERNAL API: safe by construction */
|
||||
protected val self = this.asInstanceOf[ClientConnectionSettingsImpl]
|
||||
}
|
||||
|
||||
object ClientConnectionSettings extends SettingsCompanion[ClientConnectionSettings] {
|
||||
|
|
|
|||
|
|
@ -9,7 +9,10 @@ import com.typesafe.config.Config
|
|||
import scala.concurrent.duration.Duration
|
||||
import akka.http.impl.util.JavaMapping.Implicits._
|
||||
|
||||
abstract class ConnectionPoolSettings {
|
||||
/**
|
||||
* Public API but not intended for subclassing
|
||||
*/
|
||||
abstract class ConnectionPoolSettings private[akka] () { self: ConnectionPoolSettingsImpl ⇒
|
||||
def getMaxConnections: Int
|
||||
def getMaxRetries: Int
|
||||
def getMaxOpenRequests: Int
|
||||
|
|
@ -25,9 +28,6 @@ abstract class ConnectionPoolSettings {
|
|||
def withPipeliningLimit(newValue: Int): ConnectionPoolSettings = self.copy(pipeliningLimit = newValue)
|
||||
def withIdleTimeout(newValue: Duration): ConnectionPoolSettings = self.copy(idleTimeout = newValue)
|
||||
def withConnectionSettings(newValue: ClientConnectionSettings): ConnectionPoolSettings = self.copy(connectionSettings = newValue.asScala)
|
||||
|
||||
/** INTERNAL API */
|
||||
protected def self = this.asInstanceOf[ConnectionPoolSettingsImpl]
|
||||
}
|
||||
|
||||
object ConnectionPoolSettings extends SettingsCompanion[ConnectionPoolSettings] {
|
||||
|
|
|
|||
|
|
@ -16,7 +16,10 @@ import scala.compat.java8.OptionConverters
|
|||
import akka.http.javadsl.model.{ HttpMethod, StatusCode, Uri }
|
||||
import com.typesafe.config.Config
|
||||
|
||||
abstract class ParserSettings extends BodyPartParser.Settings {
|
||||
/**
|
||||
* Public API but not intended for subclassing
|
||||
*/
|
||||
abstract class ParserSettings private[akka] () extends BodyPartParser.Settings { self: ParserSettingsImpl ⇒
|
||||
def getMaxUriLength: Int
|
||||
def getMaxMethodLength: Int
|
||||
def getMaxResponseReasonLength: Int
|
||||
|
|
@ -56,17 +59,17 @@ abstract class ParserSettings extends BodyPartParser.Settings {
|
|||
|
||||
// special ---
|
||||
|
||||
@varargs
|
||||
def withCustomMethods(methods: HttpMethod*): ParserSettings = {
|
||||
val map = methods.map(m ⇒ m.name -> m.asScala).toMap
|
||||
self.copy(customMethods = map.get)
|
||||
}
|
||||
@varargs
|
||||
def withCustomStatusCodes(codes: StatusCode*): ParserSettings = {
|
||||
val map = codes.map(c ⇒ c.intValue -> c.asScala).toMap
|
||||
self.copy(customStatusCodes = map.get)
|
||||
}
|
||||
|
||||
/** INTERNAL API */
|
||||
protected def self = this.asInstanceOf[ParserSettingsImpl]
|
||||
}
|
||||
|
||||
object ParserSettings extends SettingsCompanion[ParserSettings] {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* Copyright (C) 2016 Typesafe Inc. <http://www.typesafe.com>
|
||||
*/
|
||||
package akka.http.javadsl.settings
|
||||
|
||||
import akka.http.impl.settings.RoutingSettingsImpl
|
||||
import com.typesafe.config.Config
|
||||
|
||||
/**
|
||||
* Public API but not intended for subclassing
|
||||
*/
|
||||
abstract class RoutingSettings private[akka] () { self: RoutingSettingsImpl ⇒
|
||||
def getVerboseErrorMessages: Boolean
|
||||
def getFileGetConditional: Boolean
|
||||
def getRenderVanityFooter: Boolean
|
||||
def getRangeCountLimit: Int
|
||||
def getRangeCoalescingThreshold: Long
|
||||
def getDecodeMaxBytesPerChunk: Int
|
||||
def getFileIODispatcher: String
|
||||
|
||||
def withVerboseErrorMessages(verboseErrorMessages: Boolean): RoutingSettings = self.copy(verboseErrorMessages = verboseErrorMessages)
|
||||
def withFileGetConditional(fileGetConditional: Boolean): RoutingSettings = self.copy(fileGetConditional = fileGetConditional)
|
||||
def withRenderVanityFooter(renderVanityFooter: Boolean): RoutingSettings = self.copy(renderVanityFooter = renderVanityFooter)
|
||||
def withRangeCountLimit(rangeCountLimit: Int): RoutingSettings = self.copy(rangeCountLimit = rangeCountLimit)
|
||||
def withRangeCoalescingThreshold(rangeCoalescingThreshold: Long): RoutingSettings = self.copy(rangeCoalescingThreshold = rangeCoalescingThreshold)
|
||||
def withDecodeMaxBytesPerChunk(decodeMaxBytesPerChunk: Int): RoutingSettings = self.copy(decodeMaxBytesPerChunk = decodeMaxBytesPerChunk)
|
||||
def withFileIODispatcher(fileIODispatcher: String): RoutingSettings = self.copy(fileIODispatcher = fileIODispatcher)
|
||||
}
|
||||
|
||||
object RoutingSettings extends SettingsCompanion[RoutingSettings] {
|
||||
override def create(config: Config): RoutingSettings = RoutingSettingsImpl(config)
|
||||
override def create(configOverrides: String): RoutingSettings = RoutingSettingsImpl(configOverrides)
|
||||
}
|
||||
|
|
@ -15,7 +15,10 @@ import scala.compat.java8.OptionConverters._
|
|||
|
||||
import scala.concurrent.duration.{ Duration, FiniteDuration }
|
||||
|
||||
abstract class ServerSettings {
|
||||
/**
|
||||
* Public API but not intended for subclassing
|
||||
*/
|
||||
abstract class ServerSettings { self: ServerSettingsImpl ⇒
|
||||
def getServerHeader: Optional[Server]
|
||||
def getTimeouts: ServerSettings.Timeouts
|
||||
def getMaxConnections: Int
|
||||
|
|
@ -48,8 +51,6 @@ abstract class ServerSettings {
|
|||
def withParserSettings(newValue: ParserSettings): ServerSettings = self.copy(parserSettings = newValue.asScala)
|
||||
def withWebsocketRandomFactory(newValue: java.util.function.Supplier[Random]): ServerSettings = self.copy(websocketRandomFactory = () ⇒ newValue.get())
|
||||
|
||||
/** INTERNAL API */
|
||||
protected def self = this.asInstanceOf[ServerSettingsImpl]
|
||||
}
|
||||
|
||||
object ServerSettings {
|
||||
|
|
|
|||
|
|
@ -20,7 +20,10 @@ import scala.compat.java8.OptionConverters
|
|||
import scala.concurrent.duration.{ FiniteDuration, Duration }
|
||||
import scala.collection.JavaConverters._
|
||||
|
||||
abstract class ClientConnectionSettings extends akka.http.javadsl.settings.ClientConnectionSettings {
|
||||
/**
|
||||
* Public API but not intended for subclassing
|
||||
*/
|
||||
abstract class ClientConnectionSettings private[akka] () extends akka.http.javadsl.settings.ClientConnectionSettings { self: ClientConnectionSettingsImpl ⇒
|
||||
def userAgentHeader: Option[`User-Agent`]
|
||||
def connectingTimeout: FiniteDuration
|
||||
def idleTimeout: Duration
|
||||
|
|
|
|||
|
|
@ -3,14 +3,16 @@
|
|||
*/
|
||||
package akka.http.scaladsl.settings
|
||||
|
||||
import akka.actor.ActorSystem
|
||||
import akka.http.impl.settings.ConnectionPoolSettingsImpl
|
||||
import akka.http.javadsl.{ settings ⇒ js }
|
||||
import com.typesafe.config.Config
|
||||
|
||||
import scala.concurrent.duration.Duration
|
||||
|
||||
abstract class ConnectionPoolSettings extends js.ConnectionPoolSettings {
|
||||
/**
|
||||
* Public API but not intended for subclassing
|
||||
*/
|
||||
abstract class ConnectionPoolSettings extends js.ConnectionPoolSettings { self: ConnectionPoolSettingsImpl ⇒
|
||||
def maxConnections: Int
|
||||
def maxRetries: Int
|
||||
def maxOpenRequests: Int
|
||||
|
|
|
|||
|
|
@ -19,7 +19,10 @@ import scala.annotation.varargs
|
|||
import scala.collection.JavaConverters._
|
||||
import scala.compat.java8.OptionConverters
|
||||
|
||||
abstract class ParserSettings extends akka.http.javadsl.settings.ParserSettings {
|
||||
/**
|
||||
* Public API but not intended for subclassing
|
||||
*/
|
||||
abstract class ParserSettings private[akka] () extends akka.http.javadsl.settings.ParserSettings { self: ParserSettingsImpl ⇒
|
||||
def maxUriLength: Int
|
||||
def maxMethodLength: Int
|
||||
def maxResponseReasonLength: Int
|
||||
|
|
|
|||
|
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
* Copyright (C) 2016 Typesafe Inc. <http://www.typesafe.com>
|
||||
*/
|
||||
package akka.http.scaladsl.settings
|
||||
|
||||
import akka.http.impl.settings.RoutingSettingsImpl
|
||||
import com.typesafe.config.Config
|
||||
|
||||
/**
|
||||
* Public API but not intended for subclassing
|
||||
*/
|
||||
abstract class RoutingSettings private[akka] () extends akka.http.javadsl.settings.RoutingSettings { self: RoutingSettingsImpl ⇒
|
||||
def verboseErrorMessages: Boolean
|
||||
def fileGetConditional: Boolean
|
||||
def renderVanityFooter: Boolean
|
||||
def rangeCountLimit: Int
|
||||
def rangeCoalescingThreshold: Long
|
||||
def decodeMaxBytesPerChunk: Int
|
||||
def fileIODispatcher: String
|
||||
|
||||
/* Java APIs */
|
||||
def getVerboseErrorMessages: Boolean = verboseErrorMessages
|
||||
def getFileGetConditional: Boolean = fileGetConditional
|
||||
def getRenderVanityFooter: Boolean = renderVanityFooter
|
||||
def getRangeCountLimit: Int = rangeCountLimit
|
||||
def getRangeCoalescingThreshold: Long = rangeCoalescingThreshold
|
||||
def getDecodeMaxBytesPerChunk: Int = decodeMaxBytesPerChunk
|
||||
def getFileIODispatcher: String = fileIODispatcher
|
||||
|
||||
override def withVerboseErrorMessages(verboseErrorMessages: Boolean): RoutingSettings = self.copy(verboseErrorMessages = verboseErrorMessages)
|
||||
override def withFileGetConditional(fileGetConditional: Boolean): RoutingSettings = self.copy(fileGetConditional = fileGetConditional)
|
||||
override def withRenderVanityFooter(renderVanityFooter: Boolean): RoutingSettings = self.copy(renderVanityFooter = renderVanityFooter)
|
||||
override def withRangeCountLimit(rangeCountLimit: Int): RoutingSettings = self.copy(rangeCountLimit = rangeCountLimit)
|
||||
override def withRangeCoalescingThreshold(rangeCoalescingThreshold: Long): RoutingSettings = self.copy(rangeCoalescingThreshold = rangeCoalescingThreshold)
|
||||
override def withDecodeMaxBytesPerChunk(decodeMaxBytesPerChunk: Int): RoutingSettings = self.copy(decodeMaxBytesPerChunk = decodeMaxBytesPerChunk)
|
||||
override def withFileIODispatcher(fileIODispatcher: String): RoutingSettings = self.copy(fileIODispatcher = fileIODispatcher)
|
||||
|
||||
}
|
||||
|
||||
object RoutingSettings extends SettingsCompanion[RoutingSettings] {
|
||||
override def apply(config: Config): RoutingSettings = RoutingSettingsImpl(config)
|
||||
override def apply(configOverrides: String): RoutingSettings = RoutingSettingsImpl(configOverrides)
|
||||
}
|
||||
|
|
@ -20,7 +20,10 @@ import scala.compat.java8.OptionConverters
|
|||
import scala.concurrent.duration.{ FiniteDuration, Duration }
|
||||
import scala.language.implicitConversions
|
||||
|
||||
abstract class ServerSettings extends akka.http.javadsl.settings.ServerSettings {
|
||||
/**
|
||||
* Public API but not intended for subclassing
|
||||
*/
|
||||
abstract class ServerSettings private[akka] () extends akka.http.javadsl.settings.ServerSettings { self: ServerSettingsImpl ⇒
|
||||
def serverHeader: Option[Server]
|
||||
def timeouts: ServerSettings.Timeouts
|
||||
def maxConnections: Int
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@
|
|||
|
||||
package akka.http.javadsl.testkit
|
||||
|
||||
import akka.http.scaladsl.settings.RoutingSettings
|
||||
|
||||
import scala.annotation.varargs
|
||||
import scala.concurrent.ExecutionContextExecutor
|
||||
import scala.concurrent.duration._
|
||||
|
|
@ -15,14 +17,14 @@ import akka.http.javadsl.server.{ HttpApp, AllDirectives, Route, Directives }
|
|||
import akka.http.impl.util.JavaMapping.Implicits._
|
||||
import akka.http.impl.server.RouteImplementation
|
||||
import akka.http.scaladsl.model.HttpResponse
|
||||
import akka.http.scaladsl.server.{ RouteResult, RoutingSettingsImpl, Route ⇒ ScalaRoute }
|
||||
import akka.http.scaladsl.server.{ RouteResult, Route ⇒ ScalaRoute }
|
||||
import akka.actor.ActorSystem
|
||||
import akka.event.NoLogging
|
||||
import akka.http.impl.util._
|
||||
|
||||
/**
|
||||
* A base class to create route tests for testing libraries. An implementation needs to provide
|
||||
* code to provide and shutdown an [[ActorSystem]], [[Materializer]], and [[ExecutionContext]].
|
||||
* code to provide and shutdown an [[ActorSystem]], [[Materializer]], and [[ExecutionContextExecutor]].
|
||||
* Also an implementation should provide instances of [[TestResponse]] to define the assertion
|
||||
* facilities of the testing library.
|
||||
*
|
||||
|
|
@ -55,7 +57,7 @@ abstract class RouteTest extends AllDirectives {
|
|||
securedConnection = defaultHostInfo.isSecuredConnection(),
|
||||
defaultHostHeader = defaultHostInfo.getHost().asScala)
|
||||
|
||||
val result = scalaRoute(new server.RequestContextImpl(effectiveRequest, NoLogging, RoutingSettingsImpl(system)))
|
||||
val result = scalaRoute(new server.RequestContextImpl(effectiveRequest, NoLogging, RoutingSettings(system)))
|
||||
|
||||
result.awaitResult(awaitDuration) match {
|
||||
case RouteResult.Complete(response) ⇒ createTestResponse(response)
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
package akka.http.scaladsl.testkit
|
||||
|
||||
import akka.http.scaladsl.settings.RoutingSettings
|
||||
import com.typesafe.config.{ ConfigFactory, Config }
|
||||
import scala.collection.immutable
|
||||
import scala.concurrent.{ ExecutionContext, Await, Future }
|
||||
|
|
@ -134,7 +135,7 @@ trait RouteTest extends RequestBuilding with WSTestRequestBuilding with RouteTes
|
|||
}
|
||||
implicit def injectIntoRoute(implicit timeout: RouteTestTimeout,
|
||||
defaultHostInfo: DefaultHostInfo,
|
||||
routingSettings: RoutingSettingsImpl,
|
||||
routingSettings: RoutingSettings,
|
||||
executionContext: ExecutionContext,
|
||||
materializer: Materializer,
|
||||
routingLog: RoutingLog,
|
||||
|
|
|
|||
|
|
@ -6,6 +6,9 @@ package akka.http.scaladsl.server
|
|||
package directives
|
||||
|
||||
import java.io.File
|
||||
|
||||
import akka.http.scaladsl.settings.RoutingSettings
|
||||
|
||||
import scala.concurrent.duration._
|
||||
import scala.concurrent.{ ExecutionContext, Future }
|
||||
import scala.util.Properties
|
||||
|
|
@ -229,7 +232,7 @@ class FileAndResourceDirectivesSpec extends RoutingSpec with Inspectors with Ins
|
|||
val base = new File(getClass.getClassLoader.getResource("").toURI).getPath
|
||||
new File(base, "subDirectory/emptySub").mkdir()
|
||||
def eraseDateTime(s: String) = s.replaceAll("""\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d""", "xxxx-xx-xx xx:xx:xx")
|
||||
implicit val settings = RoutingSettingsImpl.default.copy(renderVanityFooter = false)
|
||||
implicit val settings = RoutingSettings.default.withRenderVanityFooter(false)
|
||||
|
||||
"properly render a simple directory" in {
|
||||
Get() ~> listDirectoryContents(base + "/someDir") ~> check {
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ import org.scalatest.{ Inside, Inspectors }
|
|||
|
||||
class RangeDirectivesSpec extends RoutingSpec with Inspectors with Inside {
|
||||
lazy val wrs =
|
||||
mapSettings(_.copy(rangeCountLimit = 10, rangeCoalescingThreshold = 1L)) &
|
||||
mapSettings(_.withRangeCountLimit(10).withRangeCoalescingThreshold(1L)) &
|
||||
withRangeSupport
|
||||
|
||||
def bytes(length: Byte) = Array.tabulate[Byte](length)(_.toByte)
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
package akka.http.impl.server
|
||||
|
||||
import akka.http.javadsl.model.ContentType
|
||||
import akka.http.javadsl.settings.{ RoutingSettings, ParserSettings }
|
||||
import akka.http.scaladsl.model.HttpEntity
|
||||
import akka.stream.Materializer
|
||||
import scala.concurrent.{ ExecutionContextExecutor, Future }
|
||||
|
|
@ -52,4 +53,7 @@ private[http] final case class RequestContextImpl(underlying: ScalaRequestContex
|
|||
|
||||
def executionContext(): ExecutionContextExecutor = underlying.executionContext
|
||||
def materializer(): Materializer = underlying.materializer
|
||||
|
||||
override def settings: RoutingSettings = underlying.settings
|
||||
override def parserSettings: ParserSettings = underlying.parserSettings
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ package akka.http.javadsl.server
|
|||
|
||||
import scala.concurrent.ExecutionContextExecutor
|
||||
import akka.http.javadsl.model._
|
||||
import akka.http.javadsl.settings.{ RoutingSettings, ParserSettings }
|
||||
import akka.stream.Materializer
|
||||
import java.util.concurrent.CompletionStage
|
||||
|
||||
|
|
@ -30,6 +31,16 @@ trait RequestContext {
|
|||
/** Returns the Materializer of this RequestContext */
|
||||
def materializer(): Materializer
|
||||
|
||||
/**
|
||||
* The default RoutingSettings to be used for configuring directives.
|
||||
*/
|
||||
def settings: RoutingSettings
|
||||
|
||||
/**
|
||||
* The default ParserSettings to be used for configuring directives.
|
||||
*/
|
||||
def parserSettings: ParserSettings
|
||||
|
||||
/**
|
||||
* Completes the request with a value of type T and marshals it using the given
|
||||
* marshaller.
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
package akka.http.scaladsl.server
|
||||
|
||||
import scala.util.control.NonFatal
|
||||
import akka.http.scaladsl.settings.RoutingSettings
|
||||
import akka.http.scaladsl.model._
|
||||
import StatusCodes._
|
||||
|
||||
|
|
@ -18,7 +19,7 @@ trait ExceptionHandler extends ExceptionHandler.PF {
|
|||
/**
|
||||
* "Seals" this handler by attaching a default handler as fallback if necessary.
|
||||
*/
|
||||
def seal(settings: RoutingSettingsImpl): ExceptionHandler
|
||||
def seal(settings: RoutingSettings): ExceptionHandler
|
||||
}
|
||||
|
||||
object ExceptionHandler {
|
||||
|
|
@ -32,11 +33,11 @@ object ExceptionHandler {
|
|||
def apply(error: Throwable) = pf(error)
|
||||
def withFallback(that: ExceptionHandler): ExceptionHandler =
|
||||
if (!knownToBeSealed) ExceptionHandler(knownToBeSealed = false)(this orElse that) else this
|
||||
def seal(settings: RoutingSettingsImpl): ExceptionHandler =
|
||||
def seal(settings: RoutingSettings): ExceptionHandler =
|
||||
if (!knownToBeSealed) ExceptionHandler(knownToBeSealed = true)(this orElse default(settings)) else this
|
||||
}
|
||||
|
||||
def default(settings: RoutingSettingsImpl): ExceptionHandler =
|
||||
def default(settings: RoutingSettings): ExceptionHandler =
|
||||
apply(knownToBeSealed = true) {
|
||||
case IllegalRequestException(info, status) ⇒ ctx ⇒ {
|
||||
ctx.log.warning("Illegal request {}\n\t{}\n\tCompleting with '{}' response",
|
||||
|
|
@ -53,6 +54,6 @@ object ExceptionHandler {
|
|||
* Creates a sealed ExceptionHandler from the given one. Returns the default handler if the given one
|
||||
* is `null`.
|
||||
*/
|
||||
def seal(handler: ExceptionHandler)(implicit settings: RoutingSettingsImpl): ExceptionHandler =
|
||||
def seal(handler: ExceptionHandler)(implicit settings: RoutingSettings): ExceptionHandler =
|
||||
if (handler ne null) handler.seal(settings) else ExceptionHandler.default(settings)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import akka.stream.Materializer
|
|||
import akka.event.LoggingAdapter
|
||||
import akka.http.scaladsl.marshalling.ToResponseMarshallable
|
||||
import akka.http.scaladsl.model._
|
||||
import akka.http.scaladsl.settings.ParserSettings
|
||||
import akka.http.scaladsl.settings.{ RoutingSettings, ParserSettings }
|
||||
|
||||
/**
|
||||
* Immutable object encapsulating the context of an [[akka.http.scaladsl.model.HttpRequest]]
|
||||
|
|
@ -41,7 +41,7 @@ trait RequestContext {
|
|||
/**
|
||||
* The default RoutingSettings to be used for configuring directives.
|
||||
*/
|
||||
def settings: RoutingSettingsImpl
|
||||
def settings: RoutingSettings
|
||||
|
||||
/**
|
||||
* The default ParserSettings to be used for configuring directives.
|
||||
|
|
@ -55,7 +55,7 @@ trait RequestContext {
|
|||
executionContext: ExecutionContextExecutor = executionContext,
|
||||
materializer: Materializer = materializer,
|
||||
log: LoggingAdapter = log,
|
||||
settings: RoutingSettingsImpl = settings): RequestContext
|
||||
settings: RoutingSettings = settings): RequestContext
|
||||
|
||||
/**
|
||||
* Completes the request with the given ToResponseMarshallable.
|
||||
|
|
@ -97,7 +97,7 @@ trait RequestContext {
|
|||
/**
|
||||
* Returns a copy of this context with the new RoutingSettings.
|
||||
*/
|
||||
def withRoutingSettings(settings: RoutingSettingsImpl): RequestContext
|
||||
def withRoutingSettings(settings: RoutingSettings): RequestContext
|
||||
|
||||
/**
|
||||
* Returns a copy of this context with the new [[ParserSettings]].
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ package akka.http.scaladsl.server
|
|||
import scala.concurrent.{ Future, ExecutionContextExecutor }
|
||||
import akka.stream.{ ActorMaterializer, Materializer }
|
||||
import akka.event.LoggingAdapter
|
||||
import akka.http.scaladsl.settings.ParserSettings
|
||||
import akka.http.scaladsl.settings.{ RoutingSettings, ParserSettings }
|
||||
import akka.http.scaladsl.marshalling.{ Marshal, ToResponseMarshallable }
|
||||
import akka.http.scaladsl.model._
|
||||
import akka.http.scaladsl.util.FastFuture
|
||||
|
|
@ -22,16 +22,16 @@ private[http] class RequestContextImpl(
|
|||
val executionContext: ExecutionContextExecutor,
|
||||
val materializer: Materializer,
|
||||
val log: LoggingAdapter,
|
||||
val settings: RoutingSettingsImpl,
|
||||
val settings: RoutingSettings,
|
||||
val parserSettings: ParserSettings) extends RequestContext {
|
||||
|
||||
def this(request: HttpRequest, log: LoggingAdapter, settings: RoutingSettingsImpl, parserSettings: ParserSettings)(implicit ec: ExecutionContextExecutor, materializer: Materializer) =
|
||||
def this(request: HttpRequest, log: LoggingAdapter, settings: RoutingSettings, parserSettings: ParserSettings)(implicit ec: ExecutionContextExecutor, materializer: Materializer) =
|
||||
this(request, request.uri.path, ec, materializer, log, settings, parserSettings)
|
||||
|
||||
def this(request: HttpRequest, log: LoggingAdapter, settings: RoutingSettingsImpl)(implicit ec: ExecutionContextExecutor, materializer: Materializer) =
|
||||
def this(request: HttpRequest, log: LoggingAdapter, settings: RoutingSettings)(implicit ec: ExecutionContextExecutor, materializer: Materializer) =
|
||||
this(request, request.uri.path, ec, materializer, log, settings, ParserSettings(ActorMaterializer.downcast(materializer).system))
|
||||
|
||||
def reconfigure(executionContext: ExecutionContextExecutor, materializer: Materializer, log: LoggingAdapter, settings: RoutingSettingsImpl): RequestContext =
|
||||
def reconfigure(executionContext: ExecutionContextExecutor, materializer: Materializer, log: LoggingAdapter, settings: RoutingSettings): RequestContext =
|
||||
copy(executionContext = executionContext, materializer = materializer, log = log, routingSettings = settings)
|
||||
|
||||
override def complete(trm: ToResponseMarshallable): Future[RouteResult] =
|
||||
|
|
@ -61,7 +61,7 @@ private[http] class RequestContextImpl(
|
|||
override def withLog(log: LoggingAdapter): RequestContext =
|
||||
if (log != this.log) copy(log = log) else this
|
||||
|
||||
override def withRoutingSettings(routingSettings: RoutingSettingsImpl): RequestContext =
|
||||
override def withRoutingSettings(routingSettings: RoutingSettings): RequestContext =
|
||||
if (routingSettings != this.settings) copy(routingSettings = routingSettings) else this
|
||||
|
||||
override def withParserSettings(parserSettings: ParserSettings): RequestContext =
|
||||
|
|
@ -94,7 +94,7 @@ private[http] class RequestContextImpl(
|
|||
executionContext: ExecutionContextExecutor = executionContext,
|
||||
materializer: Materializer = materializer,
|
||||
log: LoggingAdapter = log,
|
||||
routingSettings: RoutingSettingsImpl = settings,
|
||||
routingSettings: RoutingSettings = settings,
|
||||
parserSettings: ParserSettings = parserSettings) =
|
||||
new RequestContextImpl(request, unmatchedPath, executionContext, materializer, log, routingSettings, parserSettings)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,8 +5,7 @@
|
|||
package akka.http.scaladsl.server
|
||||
|
||||
import akka.NotUsed
|
||||
import akka.actor.ActorSystem
|
||||
import akka.http.scaladsl.settings.ParserSettings
|
||||
import akka.http.scaladsl.settings.{ RoutingSettings, ParserSettings }
|
||||
import akka.stream.{ ActorMaterializer, Materializer }
|
||||
|
||||
import scala.concurrent.{ ExecutionContextExecutor, Future }
|
||||
|
|
@ -24,7 +23,7 @@ object Route {
|
|||
/**
|
||||
* "Seals" a route by wrapping it with exception handling and rejection conversion.
|
||||
*/
|
||||
def seal(route: Route)(implicit routingSettings: RoutingSettingsImpl,
|
||||
def seal(route: Route)(implicit routingSettings: RoutingSettings,
|
||||
parserSettings: ParserSettings = null,
|
||||
rejectionHandler: RejectionHandler = RejectionHandler.default,
|
||||
exceptionHandler: ExceptionHandler = null): Route = {
|
||||
|
|
@ -41,7 +40,7 @@ object Route {
|
|||
*
|
||||
* This conversion is also implicitly available through [[RouteResult.route2HandlerFlow]].
|
||||
*/
|
||||
def handlerFlow(route: Route)(implicit routingSettings: RoutingSettingsImpl,
|
||||
def handlerFlow(route: Route)(implicit routingSettings: RoutingSettings,
|
||||
parserSettings: ParserSettings,
|
||||
materializer: Materializer,
|
||||
routingLog: RoutingLog,
|
||||
|
|
@ -53,7 +52,7 @@ object Route {
|
|||
/**
|
||||
* Turns a `Route` into an async handler function.
|
||||
*/
|
||||
def asyncHandler(route: Route)(implicit routingSettings: RoutingSettingsImpl,
|
||||
def asyncHandler(route: Route)(implicit routingSettings: RoutingSettings,
|
||||
parserSettings: ParserSettings,
|
||||
materializer: Materializer,
|
||||
routingLog: RoutingLog,
|
||||
|
|
|
|||
|
|
@ -4,11 +4,10 @@
|
|||
|
||||
package akka.http.scaladsl.server
|
||||
|
||||
import akka.NotUsed
|
||||
import akka.http.scaladsl.settings.ParserSettings
|
||||
|
||||
import scala.collection.immutable
|
||||
import scala.concurrent.ExecutionContext
|
||||
import akka.NotUsed
|
||||
import akka.http.scaladsl.settings.{ RoutingSettings, ParserSettings }
|
||||
import akka.stream.Materializer
|
||||
import akka.stream.scaladsl.Flow
|
||||
import akka.http.scaladsl.model.{ HttpRequest, HttpResponse }
|
||||
|
|
@ -25,7 +24,7 @@ object RouteResult {
|
|||
final case class Complete(response: HttpResponse) extends RouteResult
|
||||
final case class Rejected(rejections: immutable.Seq[Rejection]) extends RouteResult
|
||||
|
||||
implicit def route2HandlerFlow(route: Route)(implicit routingSettings: RoutingSettingsImpl,
|
||||
implicit def route2HandlerFlow(route: Route)(implicit routingSettings: RoutingSettings,
|
||||
parserSettings: ParserSettings,
|
||||
materializer: Materializer,
|
||||
routingLog: RoutingLog,
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import scala.concurrent.{ Future, ExecutionContextExecutor }
|
|||
import scala.collection.immutable
|
||||
import akka.event.LoggingAdapter
|
||||
import akka.stream.Materializer
|
||||
import akka.http.scaladsl.settings.ParserSettings
|
||||
import akka.http.scaladsl.settings.{ RoutingSettings, ParserSettings }
|
||||
import akka.http.scaladsl.server.util.Tuple
|
||||
import akka.http.scaladsl.util.FastFuture
|
||||
import akka.http.scaladsl.model._
|
||||
|
|
@ -165,21 +165,21 @@ trait BasicDirectives {
|
|||
BasicDirectives._extractLog
|
||||
|
||||
/**
|
||||
* Runs its inner route with the given alternative [[RoutingSettingsImpl]].
|
||||
* Runs its inner route with the given alternative [[RoutingSettings]].
|
||||
*/
|
||||
def withSettings(settings: RoutingSettingsImpl): Directive0 =
|
||||
def withSettings(settings: RoutingSettings): Directive0 =
|
||||
mapRequestContext(_ withRoutingSettings settings)
|
||||
|
||||
/**
|
||||
* Runs the inner route with settings mapped by the given function.
|
||||
*/
|
||||
def mapSettings(f: RoutingSettingsImpl ⇒ RoutingSettingsImpl): Directive0 =
|
||||
def mapSettings(f: RoutingSettings ⇒ RoutingSettings): Directive0 =
|
||||
mapRequestContext(ctx ⇒ ctx.withRoutingSettings(f(ctx.settings)))
|
||||
|
||||
/**
|
||||
* Extracts the [[RoutingSettingsImpl]] from the [[RequestContext]].
|
||||
* Extracts the [[RoutingSettings]] from the [[RequestContext]].
|
||||
*/
|
||||
def extractSettings: Directive1[RoutingSettingsImpl] =
|
||||
def extractSettings: Directive1[RoutingSettings] =
|
||||
BasicDirectives._extractSettings
|
||||
|
||||
/**
|
||||
|
|
@ -201,7 +201,7 @@ object BasicDirectives extends BasicDirectives {
|
|||
private val _extractExecutionContext: Directive1[ExecutionContextExecutor] = extract(_.executionContext)
|
||||
private val _extractMaterializer: Directive1[Materializer] = extract(_.materializer)
|
||||
private val _extractLog: Directive1[LoggingAdapter] = extract(_.log)
|
||||
private val _extractSettings: Directive1[RoutingSettingsImpl] = extract(_.settings)
|
||||
private val _extractSettings: Directive1[RoutingSettings] = extract(_.settings)
|
||||
private val _extractParserSettings: Directive1[ParserSettings] = extract(_.parserSettings)
|
||||
private val _extractRequestContext: Directive1[RequestContext] = extract(conforms)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue