Skip to content

Commit

Permalink
リファクタリング
Browse files Browse the repository at this point in the history
  • Loading branch information
wm3 committed Jun 3, 2012
1 parent c9a325e commit 4795044
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions src/main/scala/DispatchingServer.scala
@@ -1,29 +1,31 @@
package jp.w3ch.psm


import java.net.InetSocketAddress

import org.jboss.netty.handler.codec.http._
import org.jboss.netty.handler.codec.http.HttpResponseStatus._

import com.twitter.finagle.Service


object DispatchingServer {
type ProxyHandler = PartialFunction[HostUrl, Service[HttpRequest, HttpResponse]]
}

class DispatchingServer(proxy: DispatchingServer.ProxyHandler) extends Service[HttpRequest, HttpResponse] {
class DispatchingServer(dispatch: DispatchingServer.ProxyHandler) extends Service[HttpRequest, HttpResponse] {

val defaultServer = new service.TextResponse("hello")
val getDefaultServer: DispatchingServer.ProxyHandler = { case _ => defaultServer }
val defaultService = new service.TextResponse("hello")

override def apply(request: HttpRequest) = {
val host = Option(request.getHeader("Host"))

val server = (proxy orElse getDefaultServer)(HostUrl(host))
val service = doDispatch(HostUrl(host))

server(request)
service(request)
}


private[this] val doDispatch: DispatchingServer.ProxyHandler = dispatch orElse {
case _ => defaultService
}

}

object DispatchingServer {
type ProxyHandler = PartialFunction[HostUrl, Service[HttpRequest, HttpResponse]]
}

// vim: set shiftwidth=2 expandtab :

0 comments on commit 4795044

Please sign in to comment.