play.api.http

package play.api.http

Contains standard HTTP constants. For example:

val text = ContentTypes.TEXT
val ok = Status.OK
val accept = HeaderNames.ACCEPT

Attributes

Members list

Packages

Type members

Classlikes

A representation of the Accept-Encoding header

A representation of the Accept-Encoding header

Attributes

Companion
object
Supertypes
class Object
trait Matchable
class Any

Attributes

Companion
trait
Supertypes
class Object
trait Matchable
class Any
Self type
case class ActionCompositionConfiguration(controllerAnnotationsFirst: Boolean, executeActionCreatorActionFirst: Boolean, includeWebSocketActions: Boolean)

Configuration for action composition.

Configuration for action composition.

Value parameters

controllerAnnotationsFirst

If annotations put on controllers should be executed before the ones put on actions.

executeActionCreatorActionFirst

If the action returned by the action creator should be executed before the action composition ones.

includeWebSocketActions

If WebSocket actions should be included in action composition.

Attributes

Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
object ActionCreator

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
case class ContentTypeOf[-A](mimeType: Option[String])

Defines the default content type for type A.

Defines the default content type for type A.

Type parameters

A

the content type

Value parameters

mimeType

the default content type for A, if any

Attributes

Companion
object
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all

Default Content-Type typeclasses.

Default Content-Type typeclasses.

Attributes

Companion
class
Supertypes
trait Product
trait Mirror
class Object
trait Matchable
class Any
Show all
Self type
object ContentTypes extends ContentTypes

Defines common HTTP Content-Type header values, according to the current available Codec.

Defines common HTTP Content-Type header values, according to the current available Codec.

Attributes

Companion
trait
Supertypes
trait ContentTypes
class Object
trait Matchable
class Any
Self type
trait ContentTypes

Defines common HTTP Content-Type header values, according to the current available Codec.

Defines common HTTP Content-Type header values, according to the current available Codec.

Attributes

Companion
object
Supertypes
class Object
trait Matchable
class Any
Known subtypes
case class CookiesConfiguration(strict: Boolean)

The cookies configuration

The cookies configuration

Value parameters

strict

Whether strict cookie parsing should be used. If true, will cause the entire cookie header to be discarded if a single cookie is found to be invalid.

Attributes

Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all

Contains typeclasses for ContentTypeOf.

Contains typeclasses for ContentTypeOf.

Attributes

Supertypes
class Object
trait Matchable
class Any
Known subtypes
object ContentTypeOf.type

Default implementation of FileMimeTypes.

Default implementation of FileMimeTypes.

Attributes

Supertypes
class Object
trait Matchable
class Any
@Singleton
class DefaultFileMimeTypesProvider(fileMimeTypesConfiguration: FileMimeTypesConfiguration) extends Provider[FileMimeTypes]

Attributes

Supertypes
trait Provider[FileMimeTypes]
class Object
trait Matchable
class Any
@Singleton
class DefaultHttpErrorHandler(config: HttpErrorConfig, sourceMapper: Option[SourceMapper], router: => Option[Router]) extends HttpErrorHandler

The default HTTP error handler.

The default HTTP error handler.

This class is intended to be extended, allowing users to reuse some of the functionality provided here.

Value parameters

router

An optional router. If provided, in dev mode, will be used to display more debug information when a handler can't be found. This is a lazy parameter, to avoid circular dependency issues, since the router may well depend on this.

Attributes

Companion
object
Supertypes
class Object
trait Matchable
class Any
Known subtypes

A fallback default HTTP error handler that can be used when there's no application available.

A fallback default HTTP error handler that can be used when there's no application available.

Note: this HttpErrorHandler uses the default HttpErrorConfig, which does not showDevErrors. It is largely here to preserve binary compatibility, but should be overridden with an injected HttpErrorHandler.

Attributes

Companion
class
Supertypes
class Object
trait Matchable
class Any
Self type
class DefaultHttpFilters(val filters: EssentialFilter*) extends HttpFilters

A default implementation of HttpFilters that accepts filters as a varargs constructor and exposes them as a filters sequence. This is available for runtime DI users who don't want to do things in configuration using play.filters.enabled, because they need more fine grained control over the injected components.

A default implementation of HttpFilters that accepts filters as a varargs constructor and exposes them as a filters sequence. This is available for runtime DI users who don't want to do things in configuration using play.filters.enabled, because they need more fine grained control over the injected components.

For example:

 class Filters @Inject()(defaultFilters: EnabledFilters, corsFilter: CORSFilter)
   extends DefaultHttpFilters(defaultFilters.filters :+ corsFilter: _*)

Attributes

Supertypes
trait HttpFilters
class Object
trait Matchable
class Any
Known subtypes
class DefaultHttpRequestHandler(webCommands: WebCommands, optDevContext: Option[DevContext], router: Provider[Router], errorHandler: HttpErrorHandler, configuration: HttpConfiguration, filters: Seq[EssentialFilter]) extends HttpRequestHandler

A base implementation of the HttpRequestHandler that handles Scala actions. If you use Java actions in your application, you should override JavaCompatibleHttpRequestHandler; otherwise you can override this for your custom handler.

A base implementation of the HttpRequestHandler that handles Scala actions. If you use Java actions in your application, you should override JavaCompatibleHttpRequestHandler; otherwise you can override this for your custom handler.

Technically, this is not the default request handler that Play uses, rather, the JavaCompatibleHttpRequestHandler is the default one, in order to provide support for Java actions.

Attributes

Supertypes
class Object
trait Matchable
class Any
Known subtypes

Default Writeable.

Default Writeable.

Attributes

Supertypes
class Object
trait Matchable
class Any
Known subtypes
object Writeable.type

A default HTTP error handler that can be used when there's no application available.

A default HTTP error handler that can be used when there's no application available.

Note: this HttpErrorHandler should ONLY be used in DEV or TEST. The way this displays errors to the user is generally not suitable for a production environment.

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
@Singleton
class EnabledFilters(env: Environment, configuration: Configuration, injector: Injector) extends HttpFilters

This class provides filters that are "automatically" enabled through play.filters.enabled. A list of default filters are defined in reference.conf.

This class provides filters that are "automatically" enabled through play.filters.enabled. A list of default filters are defined in reference.conf.

See https://www.playframework.com/documentation/latest/Filters for more information.

Value parameters

configuration

the configuration

env

the environment (classloader is used from here)

injector

finds an instance of filter by the class name

Attributes

Supertypes
trait HttpFilters
class Object
trait Matchable
class Any
case class EncodingPreference(name: String, qValue: Option[BigDecimal])

A representation of an encoding preference as specified in the Accept-Encoding header. This contains an encoding name (or *), and an optional q-value.

A representation of an encoding preference as specified in the Accept-Encoding header. This contains an encoding name (or *), and an optional q-value.

Attributes

Companion
object
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all

Attributes

Companion
class
Supertypes
trait Product
trait Mirror
class Object
trait Matchable
class Any
Self type

Defines behavior for file type mappings.

Defines behavior for file type mappings.

This trait is primarily used with results and assets that send files, for users who want to send a file without having to specify an explicit content type. For example, a user can send a file with ".json":

implicit val fileMimeTypes = ...
val file = new File("test.json")
Ok.sendFile(file) // <-- uses implicit fileMimeTypes

and have a "json" -> "application/json" mapping done implicitly based off the file extension. The Assets controller handles this mapping automatically.

In a controller, an implicit FileMimeTypes object can either be defined explicitly:

class MyController @Inject()(implicit val fileMimeTypes: FileMimeTypes) extends BaseController {
  def sendFile() = ...
}

or, if play.api.mvc.BaseController is extended, then an implicit fileMimeTypes instance is already made available from play.api.mvc.ControllerComponents, meaning that no explicit import is required:

class MyController @Inject()(val controllerComponents: ControllerComponents) extends BaseController {
 def sendFile() = ...
}

Attributes

Supertypes
class Object
trait Matchable
class Any
Known subtypes
case class FileMimeTypesConfiguration(mimeTypes: Map[String, String])

Configuration for file MIME types, mapping from extension to content type.

Configuration for file MIME types, mapping from extension to content type.

Value parameters

mimeTypes

the extension to mime type mapping.

Attributes

Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
case class FlashConfiguration(cookieName: String, secure: Boolean, httpOnly: Boolean, domain: Option[String], path: String, sameSite: Option[SameSite], jwt: JWTConfiguration)

The flash configuration

The flash configuration

Value parameters

cookieName

The name of the cookie used to store the session

domain

The domain to set for the session cookie, if defined

httpOnly

Whether the HTTP only attribute of the cookie should be set

jwt

The JWT specific information

path

The path for which this cookie is valid

sameSite

The cookie's SameSite attribute

secure

Whether the flash cookie should set the secure flag or not

Attributes

Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
object HeaderNames extends HeaderNames

Defines all standard HTTP headers.

Defines all standard HTTP headers.

Attributes

Companion
trait
Supertypes
trait HeaderNames
class Object
trait Matchable
class Any
Self type
trait HeaderNames

Defines all standard HTTP headers.

Defines all standard HTTP headers.

Attributes

Companion
object
Supertypes
class Object
trait Matchable
class Any
Known subtypes

An HttpErrorHandler that uses either HTML or JSON in the response depending on the client's preference.

An HttpErrorHandler that uses either HTML or JSON in the response depending on the client's preference.

Attributes

Supertypes
class Object
trait Matchable
class Any
sealed trait HttpChunk

An HTTP chunk.

An HTTP chunk.

May either be a HttpChunk.Chunk containing data, or a HttpChunk.LastChunk, signifying the last chunk in a stream, optionally with trailing headers.

Attributes

Companion
object
Supertypes
class Object
trait Matchable
class Any
Known subtypes
class Chunk
class LastChunk
object HttpChunk

Attributes

Companion
trait
Supertypes
trait Sum
trait Mirror
class Object
trait Matchable
class Any
Self type
HttpChunk.type

HTTP related configuration of a Play application

HTTP related configuration of a Play application

Value parameters

context

The HTTP context

fileMimeTypes

The fileMimeTypes configuration

flash

The flash configuration

parser

The parser configuration

session

The session configuration

Attributes

Companion
object
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all

Attributes

Companion
class
Supertypes
trait Product
trait Mirror
class Object
trait Matchable
class Any
Self type
sealed trait HttpEntity

An HTTP entity.

An HTTP entity.

HTTP entities come in three flavors, HttpEntity.Strict, HttpEntity.Streamed and HttpEntity.Chunked.

Attributes

Companion
object
Supertypes
class Object
trait Matchable
class Any
Known subtypes
class Chunked
class Streamed
class Strict
object HttpEntity

Attributes

Companion
trait
Supertypes
trait Sum
trait Mirror
class Object
trait Matchable
class Any
Self type
HttpEntity.type
case class HttpErrorConfig(showDevErrors: Boolean, playEditor: Option[String])

Attributes

Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all

Component for handling HTTP errors in Play.

Component for handling HTTP errors in Play.

Attributes

Since

2.4.0

Companion
object
Supertypes
class Object
trait Matchable
class Any
Known subtypes

Attributes

Companion
trait
Supertypes
class Object
trait Matchable
class Any
Self type

Extracted so the Java default error handler can reuse this functionality

Extracted so the Java default error handler can reuse this functionality

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
case class HttpErrorInfo(origin: String) extends HttpErrorInfo

Used as request attribute which gets attached to the request that gets passed to an error handler. Contains additional information useful for handling an error.

Used as request attribute which gets attached to the request that gets passed to an error handler. Contains additional information useful for handling an error.

Attributes

Supertypes
trait Serializable
trait Product
trait Equals
class HttpErrorInfo
class Object
trait Matchable
class Any
Show all
trait HttpFilters

Provides filters to the play.api.http.HttpRequestHandler.

Provides filters to the play.api.http.HttpRequestHandler.

Attributes

Companion
object
Supertypes
class Object
trait Matchable
class Any
Known subtypes
object HttpFilters

Attributes

Companion
trait
Supertypes
class Object
trait Matchable
class Any
Self type
object HttpProtocol extends HttpProtocol

Defines HTTP protocol constants

Defines HTTP protocol constants

Attributes

Companion
trait
Supertypes
trait HttpProtocol
class Object
trait Matchable
class Any
Self type
trait HttpProtocol

Defines HTTP protocol constants

Defines HTTP protocol constants

Attributes

Companion
object
Supertypes
class Object
trait Matchable
class Any
Known subtypes

Primary entry point for all HTTP requests on Play applications.

Primary entry point for all HTTP requests on Play applications.

Attributes

Companion
object
Supertypes
class Object
trait Matchable
class Any
Known subtypes

Attributes

Companion
trait
Supertypes
class Object
trait Matchable
class Any
Self type
object HttpVerbs extends HttpVerbs

Standard HTTP Verbs

Standard HTTP Verbs

Attributes

Companion
trait
Supertypes
trait HttpVerbs
class Object
trait Matchable
class Any
Self type
HttpVerbs.type
trait HttpVerbs

Standard HTTP Verbs

Standard HTTP Verbs

Attributes

Companion
object
Supertypes
class Object
trait Matchable
class Any
Known subtypes
object HttpVerbs.type
case class JWTConfiguration(signatureAlgorithm: String, expiresAfter: Option[FiniteDuration], clockSkew: FiniteDuration, dataClaim: String)

The JSON Web Token configuration

The JSON Web Token configuration

Value parameters

clockSkew

The amount of clock skew to permit for expiration / not before checks

dataClaim

The claim key corresponding to the data map passed in by the user

expiresAfter

The period of time after which the JWT expires, if any.

signatureAlgorithm

The signature algorithm used to sign the JWT

Attributes

Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
class JavaCompatibleHttpRequestHandler(webCommands: WebCommands, optDevContext: Option[DevContext], router: Provider[Router], errorHandler: HttpErrorHandler, configuration: HttpConfiguration, filters: Seq[EssentialFilter], handlerComponents: JavaHandlerComponents) extends DefaultHttpRequestHandler

A Java compatible HTTP request handler.

A Java compatible HTTP request handler.

If a router routes to Java actions, it will return instances of play.core.j.JavaHandler. This takes an instance of play.core.j.JavaHandlerComponents to supply the necessary infrastructure to invoke a Java action, and returns a new play.api.mvc.Handler that the core of Play knows how to handle.

If your application routes to Java actions, then you must use this request handler as the base class as is or as the base class for your custom HttpRequestHandler.

Attributes

Supertypes
class Object
trait Matchable
class Any
class JavaHttpFiltersAdapter(underlying: HttpFilters) extends DefaultHttpFilters

Adapter from the Java HttpFilters to the Scala HttpFilters interface.

Adapter from the Java HttpFilters to the Scala HttpFilters interface.

Attributes

Supertypes
trait HttpFilters
class Object
trait Matchable
class Any
class JavaHttpFiltersDelegate(delegate: HttpFilters) extends DefaultHttpFilters

Attributes

Supertypes
class DefaultHttpFilters
trait HttpFilters
class Object
trait Matchable
class Any
class JsonHttpErrorHandler(environment: Environment, sourceMapper: Option[SourceMapper]) extends HttpErrorHandler

An alternative default HTTP error handler which will render errors as JSON messages instead of HTML pages.

An alternative default HTTP error handler which will render errors as JSON messages instead of HTML pages.

In Dev mode, exceptions thrown by the server code will be rendered in JSON messages. In Prod mode, they will not be rendered.

You could override how exceptions are rendered in Dev mode by extending this class and overriding the formatDevServerErrorException method.

Attributes

Supertypes
class Object
trait Matchable
class Any

Default Writeable with lower priority.

Default Writeable with lower priority.

Attributes

Supertypes
class Object
trait Matchable
class Any
Known subtypes
object Writeable.type
class MediaRange(mediaType: String, mediaSubType: String, parameters: Seq[(String, Option[String])], val qValue: Option[BigDecimal], val acceptExtensions: Seq[(String, Option[String])]) extends MediaType

A media range as defined by RFC 2616 14.1

A media range as defined by RFC 2616 14.1

Value parameters

acceptExtensions

The accept extensions

mediaSubType

The media sub type

mediaType

The media type

parameters

The parameters

qValue

The Q value

Attributes

Companion
object
Supertypes
class MediaType
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
object MediaRange

Attributes

Companion
class
Supertypes
class Object
trait Matchable
class Any
Self type
MediaRange.type
case class MediaType(mediaType: String, mediaSubType: String, parameters: Seq[(String, Option[String])])

A media type as defined by RFC 2616 3.7.

A media type as defined by RFC 2616 3.7.

Value parameters

mediaSubType

The media sub type

mediaType

The media type

parameters

The parameters

Attributes

Companion
object
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
Known subtypes
class MediaRange
object MediaType

Attributes

Companion
class
Supertypes
trait Product
trait Mirror
class Object
trait Matchable
class Any
Self type
MediaType.type
object MimeTypes extends MimeTypes

Common HTTP MIME types

Common HTTP MIME types

Attributes

Companion
trait
Supertypes
trait MimeTypes
class Object
trait Matchable
class Any
Self type
MimeTypes.type
trait MimeTypes

Common HTTP MIME types

Common HTTP MIME types

Attributes

Companion
object
Supertypes
class Object
trait Matchable
class Any
Known subtypes
object MimeTypes.type
class NoHttpFilters extends HttpFilters

A filters provider that provides no filters.

A filters provider that provides no filters.

Attributes

Companion
object
Supertypes
trait HttpFilters
class Object
trait Matchable
class Any
Known subtypes
object NoHttpFilters.type
object NoHttpFilters extends NoHttpFilters

Attributes

Companion
class
Supertypes
trait HttpFilters
class Object
trait Matchable
class Any
Self type

Implementation of a [HttpRequestHandler] that always returns NotImplemented results

Implementation of a [HttpRequestHandler] that always returns NotImplemented results

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
case class ParserConfiguration(maxMemoryBuffer: Long, maxDiskBuffer: Long, allowEmptyFiles: Boolean)

Configuration for body parsers.

Configuration for body parsers.

Value parameters

allowEmptyFiles

If empty file uploads are allowed (no matter if filename or file is empty)

maxDiskBuffer

The maximum size that a request body should be buffered on disk.

maxMemoryBuffer

The maximum size that a request body that should be buffered in memory.

Attributes

Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
final class Port(val value: Int) extends AnyVal

A port. This class is defined so that ports can be passed around implicitly.

A port. This class is defined so that ports can be passed around implicitly.

Attributes

Supertypes
class AnyVal
trait Matchable
class Any

An HttpErrorHandler that delegates to one of several HttpErrorHandlers based on media type preferences.

An HttpErrorHandler that delegates to one of several HttpErrorHandlers based on media type preferences.

For example, to create an error handler that handles JSON and HTML, with JSON preferred by the app as default:

 override lazy val httpErrorHandler = PreferredMediaTypeHttpErrorHandler(
   "application/json" -> new JsonHttpErrorHandler()
   "text/html" -> new HtmlHttpErrorHandler(),
 )

If the client's preferred media range matches multiple media types in the list, then the first match is chosen.

Attributes

Companion
object
Supertypes
class Object
trait Matchable
class Any
Known subtypes

Attributes

Companion
class
Supertypes
class Object
trait Matchable
class Any
Self type
case class SecretConfiguration(secret: String, provider: Option[String])

The application secret. Must be set. A value of "changeme" will cause the application to fail to start in production.

The application secret. Must be set. A value of "changeme" will cause the application to fail to start in production.

With the Play secret we want to:

  1. Encourage the practice of not using the same secret in dev and prod.
  2. Make it obvious that the secret should be changed.
  3. Ensure that in dev mode, the secret stays stable across restarts.
  4. Ensure that in dev mode, sessions do not interfere with other applications that may be or have been running on localhost. Eg, if I start Play app 1, and it stores a PLAY_SESSION cookie for localhost:9000, then I stop it, and start Play app 2, when it reads the PLAY_SESSION cookie for localhost:9000, it should not see the session set by Play app 1. This can be achieved by using different secrets for the two, since if they are different, they will simply ignore the session cookie set by the other.

To achieve 1 and 2, we will, in Activator templates, set the default secret to be "changeme". This should make it obvious that the secret needs to be changed and discourage using the same secret in dev and prod.

For safety, if the secret is not set, or if it's changeme, and we are in prod mode, then we will fail fatally. This will further enforce both 1 and 2.

To achieve 3, if in dev or test mode, if the secret is either changeme or not set, we will generate a secret based on the location of application.conf. This should be stable across restarts for a given application.

To achieve 4, using the location of application.conf to generate the secret should ensure this.

Play secret is checked for a minimum length, dependent on the algorithm used to sign the session and flash cookie. If the key has fewer bits then required by the algorithm, then an error is thrown and the configuration is invalid.

Value parameters

provider

the JCE provider to use. If null, uses the platform default

secret

the application secret

Attributes

Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
case class SessionConfiguration(cookieName: String, secure: Boolean, maxAge: Option[FiniteDuration], httpOnly: Boolean, domain: Option[String], path: String, sameSite: Option[SameSite], jwt: JWTConfiguration)

The session configuration

The session configuration

Value parameters

cookieName

The name of the cookie used to store the session

domain

The domain to set for the session cookie, if defined

httpOnly

Whether the HTTP only attribute of the cookie should be set

jwt

The JWT specific information

maxAge

The max age of the session, none, use "session" sessions

path

The path for which this cookie is valid

sameSite

The cookie's SameSite attribute

secure

Whether the session cookie should set the secure flag or not

Attributes

Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
object Status extends Status

Defines all standard HTTP status codes, with additional helpers for determining the type of status.

Defines all standard HTTP status codes, with additional helpers for determining the type of status.

Attributes

Companion
trait
Supertypes
trait Status
class Object
trait Matchable
class Any
Self type
Status.type
trait Status

Defines all standard HTTP status codes.

Defines all standard HTTP status codes.

See RFC 7231 and RFC 6585.

Attributes

Companion
object
Supertypes
class Object
trait Matchable
class Any
Known subtypes
class Writeable[-A](val transform: A => ByteString, val contentType: Option[String])

Transform a value of type A to a Byte Array.

Transform a value of type A to a Byte Array.

Type parameters

A

the content type

Attributes

Companion
object
Supertypes
class Object
trait Matchable
class Any
object Writeable extends DefaultWriteables

Helper utilities for Writeable.

Helper utilities for Writeable.

Attributes

Companion
class
Supertypes
class Object
trait Matchable
class Any
Self type
Writeable.type

Value members

Concrete fields

val dateFormat: DateTimeFormatter

HTTP date formatter, compliant to RFC 1123

HTTP date formatter, compliant to RFC 1123

Attributes