Skip to content

Commit

Permalink
Generify all locations where request used to be constrained to HttpRe…
Browse files Browse the repository at this point in the history
…quest but no longer is with finch 0.4.0
  • Loading branch information
BenWhitehead committed Feb 3, 2015
1 parent 9771424 commit a24e0de
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 13 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ Compiled for scala 2.10 and 2.11
resolvers += "BenWhitehead" at "http://storage.googleapis.com/benwhitehead_me/maven/public"
libraryDependencies ++= Seq(
"io.github.benwhitehead.finch" %% "finch-server" % "0.7.0"
"io.github.benwhitehead.finch" %% "finch-server" % "0.7.1"
)
```
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ organization := "io.github.benwhitehead.finch"

name := "finch-server"

version := "0.7.0"
version := "0.7.1"

crossScalaVersions := Seq("2.10.3", "2.11.4")

Expand Down
16 changes: 9 additions & 7 deletions src/main/scala/io/github/benwhitehead/finch/FinchServer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,20 @@ package io.github.benwhitehead.finch
import com.twitter.app.App
import com.twitter.conversions.storage.intToStorageUnitableWholeNumber
import com.twitter.finagle._
import com.twitter.finagle.httpx.service.NotFoundService
import com.twitter.finagle.netty3.Netty3ListenerTLSConfig
import com.twitter.finagle.ssl.Ssl
import com.twitter.server.Lifecycle.Warmup
import com.twitter.server.{Admin, AdminHttpServer, Lifecycle, Stats}
import com.twitter.util.Await
import io.finch._
import io.github.benwhitehead.finch.filters._
import io.github.benwhitehead.finch.request.DelegateService

import java.io.{File, FileNotFoundException, FileOutputStream}
import java.lang.management.ManagementFactory
import java.net.{InetSocketAddress, SocketAddress}

trait FinchServer[Request <: HttpRequest] extends App
trait FinchServer[Request] extends App
with SLF4JLogging
with AdminHttpServer
with Admin
Expand Down Expand Up @@ -134,10 +134,10 @@ trait FinchServer[Request <: HttpRequest] extends App
}

def getService(serviceName: String): Service[HttpRequest, HttpResponse] = {
new StatsFilter(serviceName) andThen
AccessLog andThen
errorHandler andThen
filter andThen
new StatsFilter(serviceName) !
AccessLog !
errorHandler !
filter !
(endpoint orElse NotFound)
}

Expand All @@ -148,7 +148,9 @@ trait FinchServer[Request <: HttpRequest] extends App
}

val NotFound = new Endpoint[Request, HttpResponse] {
lazy val underlying = new NotFoundService[Request]
lazy val underlying = DelegateService {
io.finch.response.NotFound()
}
def route = { case _ => underlying }
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/io/github/benwhitehead/finch/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import io.finch.response.BadRequest

package object finch {

trait TypedEndpoint[Request <: HttpRequest] extends Endpoint[Request, HttpResponse]
trait TypedEndpoint[Request] extends Endpoint[Request, HttpResponse]
trait HttpEndpoint extends TypedEndpoint[HttpRequest]

class BadRequest extends Exception // 400
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ import io.finch.request.RequestReader

package object request {

class ReaderService[Req <: HttpRequest, T](reader: RequestReader[T]) extends Service[Req, T] {
class ReaderService[Req, T](reader: RequestReader[T])(implicit view: (Req) => HttpRequest) extends Service[Req, T] {
final def apply(request: Req): Future[T] = reader(request)
}
object ReaderService {
/* TODO: See if it's possible to improve the type info here so that SimpleReaderService isn't needed */
def apply[Req <: HttpRequest, T](f: => RequestReader[T]) = new ReaderService[Req, T](f)
def apply[Req, T](f: => RequestReader[T])(implicit view: (Req) => HttpRequest) = new ReaderService[Req, T](f)
}
object SimpleReaderService {
def apply[T](f: => RequestReader[T]) = new ReaderService[HttpRequest, T](f)
}

object DelegateService {
def apply[Req <: HttpRequest, T](f: => T) = new Service[Req, T] {
def apply[Req, T](f: => T) = new Service[Req, T] {
def apply(req: Req): Future[T] = {
f.toFuture
}
Expand Down

0 comments on commit a24e0de

Please sign in to comment.