--- a/src/main/scala/Authoritative.scala Mon Jun 04 16:05:57 2012 -0400
+++ b/src/main/scala/Authoritative.scala Mon Jun 04 18:16:34 2012 -0400
@@ -44,6 +44,28 @@
else "" //todo: should perhaps throw an exception here.
}
+ def unapply2[T](req: HttpRequest[T], uriBase:Option[String]) (implicit m: Manifest[T]) : Tuple2[URL, Representation] = {
+
+ // val uriBase: Option[String] = Option(System getProperty "rww.uriBase") // @@ Hack
+
+ val uri = reqURL(m, req)
+ val suffixOpt = uri match {
+ case r(_, suffix) => Some(suffix)
+ case _ if uri endsWith "/" => Some("/")
+ case _ => None
+ }
+
+ uriBase match {
+ case Some(base) => {
+ System.out.println("Base is " + base)
+ System.out.println("req.uri is " + req.uri)
+ (new URL(new URL(base), req.uri), Representation(suffixOpt, Accept(req)))
+ }
+ case None => (new URL(uri), Representation(suffixOpt, Accept(req)))
+ }
+ }
+
+
def unapply[T](req: HttpRequest[T]) (implicit m: Manifest[T]) : Option[(URL, Representation)] = {
val uriBase: Option[String] = Option(System getProperty "rww.uriBase") // @@ Hack
--- a/src/main/scala/ReadWriteWeb.scala Mon Jun 04 16:05:57 2012 -0400
+++ b/src/main/scala/ReadWriteWeb.scala Mon Jun 04 18:16:34 2012 -0400
@@ -39,6 +39,7 @@
*/
trait ReadWriteWeb[Req, Res] {
val rm: ResourceManager
+ val base : Option[String]
implicit def manif: Manifest[Req]
implicit val authz: AuthZ[Req, Res] = new NullAuthZ[Req, Res]
// a few type short cuts to make it easier to reason with the code here
@@ -79,7 +80,8 @@
*/
def rwwIntent = (req: HttpRequest[Req]) => {
- val Authoritative(uri: URL, representation: Representation) = req
+ // val Authoritative(uri: URL, representation: Representation) = req
+ var (uri: URL, representation: Representation) = Authoritative.unapply2(req, base)
val r: Resource = rm.resource(uri)
val res: ResponseFunction[Res] = req match {
case GET(_) if representation == HTMLRepr => {
--- a/src/main/scala/ReadWriteWebArgs.scala Mon Jun 04 16:05:57 2012 -0400
+++ b/src/main/scala/ReadWriteWebArgs.scala Mon Jun 04 18:16:34 2012 -0400
@@ -180,9 +180,7 @@
val httpPort = parser.option[Int]("http", "port","start the http server on port")
val httpsPort = parser.option[Int]("https","port","start the https server on port")
- val uriBase = parser.option[String]("base","uri","base URI for processing RDF") {
- (sValue, opt) => System.setProperty("rww.uriBase", sValue)
- }
+ val uriBase = parser.option[String]("base","uri","base URI for processing RDF")
val rootDirectory = parser.parameter[File]("rootDirectory", "path to root directory where files are served", false) {
(sValue, opt) => {
--- a/src/main/scala/ReadWriteWebJetty.scala Mon Jun 04 16:05:57 2012 -0400
+++ b/src/main/scala/ReadWriteWebJetty.scala Mon Jun 04 18:16:34 2012 -0400
@@ -44,6 +44,7 @@
val rww = new ReadWriteWeb[HttpServletRequest,HttpServletResponse] {
val rm = filesystem
+ val base: Option[String] = uriBase.value
def manif = manifest[HttpServletRequest]
override implicit val authz = new RDFAuthZ[HttpServletRequest,HttpServletResponse](filesystem)
}
--- a/src/main/scala/netty/ReadWriteWebNetty.scala Mon Jun 04 16:05:57 2012 -0400
+++ b/src/main/scala/netty/ReadWriteWebNetty.scala Mon Jun 04 18:16:34 2012 -0400
@@ -64,6 +64,7 @@
val rww = new cycle.Plan with cycle.ThreadPool with ServerErrorResponse with ReadWriteWeb[ReceivedMessage,HttpResponse]{
val rm = filesystem
+ val base: Option[String] = uriBase.value
def manif = manifest[ReceivedMessage]
override val authz = new RDFAuthZ[ReceivedMessage,HttpResponse](filesystem)
}