play.api.mvc.EssentialFilter Scala Examples
The following examples show how to use play.api.mvc.EssentialFilter.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
Example 1
Source File: AppLoader.scala From OAuth2-mock-play with MIT License | 5 votes |
import models.{AuthorizeStoreCache, PendingContentStoreCache} import play.api.ApplicationLoader.Context import play.api.cache.EhCacheComponents import play.api.mvc.EssentialFilter import play.api.routing.Router import play.api._ import play.filters.gzip.GzipFilter import router.Routes class AppLoader extends ApplicationLoader { override def load(context: Context): Application = { LoggerConfigurator(context.environment.classLoader) .foreach(_.configure(context.environment)) new AppComponents(context).application } } class AppComponents(context: Context) extends BuiltInComponentsFromContext(context) with EhCacheComponents { implicit val executionContext = play.api.libs.concurrent.Execution.Implicits.defaultContext implicit lazy val authorizeStoreCache = AuthorizeStoreCache( cacheApi("authorizeStore")) implicit lazy val pendingConsentStoreCache = PendingContentStoreCache( cacheApi("pendingConsentStore")) implicit val config = configuration.underlying lazy val applicationController = new controllers.Application lazy val assets = new controllers.Assets(httpErrorHandler) // Routes is a generated class override def router: Router = new Routes(httpErrorHandler, applicationController, assets) val gzipFilter = new GzipFilter(shouldGzip = (request, response) => { val contentType = response.header.headers.get("Content-Type") contentType.exists(_.startsWith("text/html")) || request.path.endsWith("jsroutes.js") }) override lazy val httpFilters: Seq[EssentialFilter] = Seq(gzipFilter) }
Example 2
Source File: MyApplicationLoader.scala From get-you-a-license with BSD 3-Clause "New" or "Revised" License | 5 votes |
import controllers.{AssetsComponents, Main} import filters.OnlyHttpsFilter import org.webjars.play.{RequireJS, WebJarAssets, WebJarsUtil} import play.api.{Application, ApplicationLoader, BuiltInComponentsFromContext} import play.api.ApplicationLoader.Context import play.api.libs.concurrent.{DefaultFutures, Futures} import play.api.libs.ws.ahc.AhcWSComponents import play.api.mvc.EssentialFilter import play.api.routing.Router import play.filters.HttpFiltersComponents import play.filters.csrf.CSRFFilter import router.Routes import utils.GitHub class MyApplicationLoader extends ApplicationLoader { def load(context: Context): Application = { new MyComponents(context).application } } class MyComponents(context: Context) extends BuiltInComponentsFromContext(context) with AhcWSComponents with AssetsComponents with HttpFiltersComponents { override def httpFilters: Seq[EssentialFilter] = { super.httpFilters.filterNot(_.isInstanceOf[CSRFFilter]) :+ new OnlyHttpsFilter(environment) } lazy val futures = new DefaultFutures(actorSystem) lazy val webJarsUtil = new WebJarsUtil(context.initialConfiguration, context.environment) lazy val indexView = new views.html.index(webJarsUtil) lazy val setupView = new views.html.setup(webJarsUtil) lazy val orgView = new views.html.org(webJarsUtil) lazy val gitHub = new GitHub(context.initialConfiguration, wsClient, futures) lazy val main = new Main(gitHub, controllerComponents)(indexView, orgView, setupView) lazy val requireJs = new RequireJS(webJarsUtil) lazy val webJarAssets = new WebJarAssets(httpErrorHandler, assetsMetadata) lazy val webJarsRoutes = new webjars.Routes(httpErrorHandler, requireJs, webJarAssets) lazy val router: Router = new Routes(httpErrorHandler, main, assets, webJarsRoutes) }
Example 3
Source File: Filters.scala From theGardener with Apache License 2.0 | 5 votes |
package filters import akka.stream.Materializer import javax.inject.Inject import play.api.http.HttpFilters import play.api.mvc.{EssentialFilter, RequestHeader, Result} import play.api.{Environment, Mode} import play.filters.cors.CORSFilter import play.filters.gzip.GzipFilter class Filters @Inject()(environment: Environment, corsFilter: CORSFilter)(implicit mat: Materializer) extends HttpFilters { private def shouldGzip = (requestHeader: RequestHeader, response: Result) => { val responseIsJavascript = response.body.contentType.exists(_.startsWith("application/javascript")) val requestPathShouldBeGzipped = requestHeader.path.contains("/api/") responseIsJavascript || requestPathShouldBeGzipped } private val gzipFilter = new GzipFilter(shouldGzip = shouldGzip) override val filters: Seq[EssentialFilter] = environment.mode match { case Mode.Dev => // CORSFilter only for DEV mode: allow Angular app to call API on different port Seq(gzipFilter, corsFilter) case _ => Seq(gzipFilter) } }
Example 4
Source File: ClippyApplicationLoader.scala From scala-clippy with Apache License 2.0 | 5 votes |
import api.UiApiImpl import com.softwaremill.id.DefaultIdGenerator import controllers._ import dal.AdvicesRepository import play.api.ApplicationLoader.Context import play.api._ import play.api.i18n.I18nComponents import play.api.mvc.EssentialFilter import router.Routes import util.{DatabaseConfig, SqlDatabase} import util.email.{DummyEmailService, SendgridEmailService} class ClippyApplicationLoader extends ApplicationLoader { def load(context: Context) = { Logger.configure(context.environment) val c = new ClippyComponents(context) c.database.updateSchema() c.application } } class ClippyComponents(context: Context) extends BuiltInComponentsFromContext(context) with I18nComponents { implicit val ec = scala.concurrent.ExecutionContext.Implicits.global lazy val router = new Routes(httpErrorHandler, applicationController, assets, webJarAssets, advicesController, autowireController) lazy val contactEmail = configuration.getString("email.contact").getOrElse("?") lazy val emailService = SendgridEmailService .createFromEnv(contactEmail) .getOrElse(new DummyEmailService) lazy val webJarAssets = new WebJarAssets(httpErrorHandler, configuration, environment) lazy val assets = new controllers.Assets(httpErrorHandler) lazy val idGenerator = new DefaultIdGenerator() lazy val applicationController = new ApplicationController() lazy val database = SqlDatabase.create(new DatabaseConfig { override val rootConfig = configuration.underlying }) lazy val advicesRepository = new AdvicesRepository(database, idGenerator) lazy val uiApiImpl = new UiApiImpl(advicesRepository, emailService, contactEmail) lazy val autowireController = new AutowireController(uiApiImpl) lazy val advicesController = new AdvicesController(advicesRepository) override lazy val httpFilters: Seq[EssentialFilter] = List(new HttpsFilter()) }