| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -40,7 +40,7 @@ trait AdminServices extends I18nComponents { | |||
| 40 | 40 | lazy val emailService = wire[EmailService] | |
| 41 | 41 | lazy val fastlyStatisticService = wire[FastlyStatisticService] | |
| 42 | 42 | lazy val fastlyCloudwatchLoadJob = wire[FastlyCloudwatchLoadJob] | |
| 43 | - lazy val redirects = wire[Redirects] | ||
| 43 | + lazy val redirects = wire[RedirectService] | ||
| 44 | 44 | lazy val r2PagePressJob = wire[R2PagePressJob] | |
| 45 | 45 | lazy val videoEncodingsJob = wire[VideoEncodingsJob] | |
| 46 | 46 | lazy val matchDayRecorder = wire[MatchDayRecorder] | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -9,15 +9,15 @@ import jobs.VideoEncodingsJob | |||
| 9 | 9 | import play.api.Environment | |
| 10 | 10 | import play.api.libs.ws.WSClient | |
| 11 | 11 | import play.api.i18n.Messages | |
| 12 | - import services.{OphanApi, Redirects} | ||
| 12 | + import services.{OphanApi, RedirectService} | ||
| 13 | 13 | ||
| 14 | 14 | trait AdminControllers { | |
| 15 | 15 | def akkaAsync: AkkaAsync | |
| 16 | 16 | def wsClient: WSClient | |
| 17 | 17 | def videoEncodingsJob: VideoEncodingsJob | |
| 18 | 18 | def ophanApi: OphanApi | |
| 19 | 19 | def environment: Environment | |
| 20 | - def redirects: Redirects | ||
| 20 | + def redirects: RedirectService | ||
| 21 | 21 | implicit val messages: Messages | |
| 22 | 22 | lazy val oAuthLoginController = wire[OAuthLoginAdminController] | |
| 23 | 23 | lazy val uncachedWebAssets = wire[UncachedWebAssets] | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,14 +6,14 @@ import play.api.mvc.{Action, Controller} | |||
| 6 | 6 | import common.Logging | |
| 7 | 7 | import play.api.data._ | |
| 8 | 8 | import play.api.data.Forms._ | |
| 9 | - import services.Redirects | ||
| 10 | - import services.Redirects.External | ||
| 9 | + import services.RedirectService.External | ||
| 10 | + import services.RedirectService | ||
| 11 | 11 | ||
| 12 | 12 | ||
| 13 | 13 | case class PageRedirect(from: String, to: String) { | |
| 14 | 14 | lazy val trim = this.copy(from = from.trim, to = to.trim) | |
| 15 | 15 | } | |
| 16 | - class RedirectController(redirects: Redirects) extends Controller with Logging { | ||
| 16 | + class RedirectController(redirects: RedirectService) extends Controller with Logging { | ||
| 17 | 17 | ||
| 18 | 18 | ||
| 19 | 19 | val redirectForm = Form(mapping("from" -> text, "to" -> text)(PageRedirect.apply)(PageRedirect.unapply)) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,15 +10,15 @@ import org.jsoup.Jsoup | |||
| 10 | 10 | import pagepresser.{InteractiveHtmlCleaner, NextGenInteractiveHtmlCleaner, PollsHtmlCleaner, SimpleHtmlCleaner} | |
| 11 | 11 | import play.api.libs.json._ | |
| 12 | 12 | import play.api.libs.ws.WSClient | |
| 13 | - import services.{Redirects, S3Archive, S3ArchiveOriginals} | ||
| 13 | + import services.{RedirectService, S3Archive, S3ArchiveOriginals} | ||
| 14 | 14 | import model.R2PressMessage | |
| 15 | 15 | import implicits.R2PressNotification.pressMessageFormatter | |
| 16 | 16 | import org.jsoup.nodes.Document | |
| 17 | - import services.Redirects.Archive | ||
| 17 | + import services.RedirectService.Archive | ||
| 18 | 18 | ||
| 19 | 19 | import scala.concurrent.Future | |
| 20 | 20 | ||
| 21 | - class R2PagePressJob(wsClient: WSClient, redirects: Redirects) extends ExecutionContexts with Logging { | ||
| 21 | + class R2PagePressJob(wsClient: WSClient, redirects: RedirectService) extends ExecutionContexts with Logging { | ||
| 22 | 22 | private val waitTimeSeconds = Configuration.r2Press.pressQueueWaitTimeInSeconds | |
| 23 | 23 | private val maxMessages = Configuration.r2Press.pressQueueMaxMessages | |
| 24 | 24 | private val credentials = Configuration.aws.mandatoryCredentials | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -13,7 +13,7 @@ import play.api.http.{HttpErrorHandler, HttpRequestHandler} | |||
| 13 | 13 | import play.api.mvc.EssentialFilter | |
| 14 | 14 | import play.api.routing.Router | |
| 15 | 15 | import play.api._ | |
| 16 | - import services.{ArchiveMetrics, Redirects} | ||
| 16 | + import services.{ArchiveMetrics, RedirectService} | ||
| 17 | 17 | import router.Routes | |
| 18 | 18 | ||
| 19 | 19 | class AppLoader extends FrontendApplicationLoader { | |
@@ -22,7 +22,7 @@ class AppLoader extends FrontendApplicationLoader { | |||
| 22 | 22 | ||
| 23 | 23 | trait AppComponents extends FrontendComponents { | |
| 24 | 24 | ||
| 25 | - lazy val redirects = wire[Redirects] | ||
| 25 | + lazy val redirects = wire[RedirectService] | ||
| 26 | 26 | ||
| 27 | 27 | lazy val healthCheck = wire[HealthCheck] | |
| 28 | 28 | lazy val archiveController = wire[ArchiveController] | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,16 +4,17 @@ import campaigns.ShortCampaignCodes | |||
| 4 | 4 | import common._ | |
| 5 | 5 | import model.Cached.{CacheableResult, WithoutRevalidationResult} | |
| 6 | 6 | import play.api.mvc._ | |
| 7 | - import services.{Redirects, GoogleBotMetric} | ||
| 7 | + import services.{GoogleBotMetric, RedirectService} | ||
| 8 | 8 | import java.net.URLDecoder | |
| 9 | 9 | import javax.ws.rs.core.UriBuilder | |
| 10 | 10 | ||
| 11 | 11 | import model.{CacheTime, Cached} | |
| 12 | 12 | import org.apache.http.HttpStatus | |
| 13 | + import services.RedirectService.{Archive, Destination, External} | ||
| 13 | 14 | ||
| 14 | 15 | import scala.concurrent.Future | |
| 15 | 16 | ||
| 16 | - class ArchiveController(redirects: Redirects) extends Controller with Logging with ExecutionContexts { | ||
| 17 | + class ArchiveController(redirects: RedirectService) extends Controller with Logging with ExecutionContexts { | ||
| 17 | 18 | ||
| 18 | 19 | private val R1ArtifactUrl = """www.theguardian.com/(.*)/[0|1]?,[\d]*,(-?\d+),[\d]*(.*)""".r | |
| 19 | 20 | private val ShortUrl = """^(www\.theguardian\.com/p/[\w\d]+).*$""".r | |
@@ -92,7 +93,7 @@ class ArchiveController(redirects: Redirects) extends Controller with Logging wi | |||
| 92 | 93 | } | |
| 93 | 94 | } | |
| 94 | 95 | ||
| 95 | - private def destinationFor(path: String): Future[Option[Redirects.Destination]] = redirects.destinationFor(normalise(path)) | ||
| 96 | + private def destinationFor(path: String): Future[Option[Destination]] = redirects.destinationFor(normalise(path)) | ||
| 96 | 97 | ||
| 97 | 98 | private object Combiner { | |
| 98 | 99 | def unapply(path: String): Option[String] = { | |
@@ -144,11 +145,11 @@ class ArchiveController(redirects: Redirects) extends Controller with Logging wi | |||
| 144 | 145 | ||
| 145 | 146 | private def lookupPath(path: String) = destinationFor(path).map{ _.flatMap(processLookupDestination(path).lift) } | |
| 146 | 147 | ||
| 147 | - def processLookupDestination(path: String) : PartialFunction[Redirects.Destination, CacheableResult] = { | ||
| 148 | - case Redirects.External(_, location) if !linksToItself(path, location) => | ||
| 148 | + def processLookupDestination(path: String) : PartialFunction[Destination, CacheableResult] = { | ||
| 149 | + case External(_, location) if !linksToItself(path, location) => | ||
| 149 | 150 | val locationWithCampaign = retainShortUrlCampaign(path, location) | |
| 150 | 151 | WithoutRevalidationResult(Redirect(locationWithCampaign, redirectHttpStatus)) | |
| 151 | - case Redirects.Archive(_, archivePath) => | ||
| 152 | + case Archive(_, archivePath) => | ||
| 152 | 153 | // http://wiki.nginx.org/X-accel | |
| 153 | 154 | WithoutRevalidationResult(Ok.withHeaders("X-Accel-Redirect" -> s"/s3-archive/$archivePath")) | |
| 154 | 155 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,7 +6,8 @@ import play.api.test.Helpers._ | |||
| 6 | 6 | import org.scalatest.{BeforeAndAfterAll, DoNotDiscover, FlatSpec, Matchers} | |
| 7 | 7 | ||
| 8 | 8 | import scala.concurrent.Future | |
| 9 | - import services.Redirects | ||
| 9 | + import services.RedirectService | ||
| 10 | + import services.RedirectService.{Archive, External} | ||
| 10 | 11 | ||
| 11 | 12 | @DoNotDiscover class ArchiveControllerTest | |
| 12 | 13 | extends FlatSpec | |
@@ -15,7 +16,7 @@ import services.Redirects | |||
| 15 | 16 | with BeforeAndAfterAll { | |
| 16 | 17 | ||
| 17 | 18 | lazy val archiveController = new ArchiveController(mockRedirects) | |
| 18 | - lazy val mockRedirects = new Redirects { | ||
| 19 | + lazy val mockRedirects = new RedirectService { | ||
| 19 | 20 | override def destinationFor(source: String) = Future.successful(None) | |
| 20 | 21 | } | |
| 21 | 22 | ||
@@ -206,15 +207,15 @@ import services.Redirects | |||
| 206 | 207 | ||
| 207 | 208 | it should "redirect short urls with campaign codes and allow for overrides" in { | |
| 208 | 209 | val path = "http://www.theguardian.com/p/old/stw" | |
| 209 | - val shortRedirectWithCMP = Redirects.External(path, "http://www.theguardian.com/p/new?CMP=existing-cmp") | ||
| 210 | + val shortRedirectWithCMP = External(path, "http://www.theguardian.com/p/new?CMP=existing-cmp") | ||
| 210 | 211 | val result = archiveController.retainShortUrlCampaign(path, shortRedirectWithCMP.location) | |
| 211 | 212 | result should be (shortRedirectWithCMP.location) | |
| 212 | 213 | } | |
| 213 | 214 | ||
| 214 | 215 | it should "not perform a redirect loop check on Archive objects" in { | |
| 215 | 216 | // The archive x-accel goes to s3. So it is irrelevant whether the original path looks like the s3 archive path. | |
| 216 | 217 | val path = "http://www.theguardian.com/redirect/path-to-content" | |
| 217 | - val databaseSaysArchive = Redirects.Archive("any", path) | ||
| 218 | + val databaseSaysArchive = Archive("any", path) | ||
| 218 | 219 | val result = archiveController.processLookupDestination(path).lift(databaseSaysArchive) | |
| 219 | 220 | result.map(_.toString).getOrElse("") should include (s"""X-Accel-Redirect -> /s3-archive/$path""") | |
| 220 | 221 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -9,7 +9,7 @@ import conf.Configuration | |||
| 9 | 9 | import scala.concurrent.Future | |
| 10 | 10 | ||
| 11 | 11 | ||
| 12 | - object Redirects { | ||
| 12 | + object RedirectService { | ||
| 13 | 13 | sealed trait Destination { | |
| 14 | 14 | def source: String | |
| 15 | 15 | def location: String | |
@@ -33,8 +33,8 @@ object Redirects { | |||
| 33 | 33 | } | |
| 34 | 34 | ||
| 35 | 35 | ||
| 36 | - class Redirects extends Logging with ExecutionContexts { | ||
| 37 | - import Redirects._ | ||
| 36 | + class RedirectService extends Logging with ExecutionContexts { | ||
| 37 | + import RedirectService._ | ||
| 38 | 38 | ||
| 39 | 39 | // protocol fixed to http so that lookups to dynamo find existing redirects | |
| 40 | 40 | private val expectedSourceProtocol = "http://" | |
| Back | FazBrowse Home | New Git URL |
0 commit comments