--- a/src/main/scala/Authoritative.scala Mon Jun 25 10:03:10 2012 +0200
+++ b/src/main/scala/Authoritative.scala Mon Jun 25 10:07:32 2012 +0200
@@ -35,21 +35,52 @@
val r = """^(.*)\.(\w{0,4})$""".r
// all of this would be unnecessary if req.uri would really return the full URI
- // we should try to push for that to be done at unfiltered layer
+ // we should try to push for that to be done at unfiltered layer - HS
+ // Alternatively, build the system to not need to know, or be told, its base hostport. - TBL
+ //
def reqURL[T](m: Manifest[T], r: HttpRequest[T]): String = {
if (m <:< manifest[HttpServletRequest]) reqUrlServlet(r.asInstanceOf[HttpRequest[HttpServletRequest]])
else if (m <:< manifest[ReceivedMessage]) reqUrlNetty(r.asInstanceOf[HttpRequest[ReceivedMessage]])
else "" //todo: should perhaps throw an exception here.
}
- def unapply[T](req: HttpRequest[T]) (implicit m: Manifest[T]) : Option[(URL, Representation)] = {
+ 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
}
- Some((new URL(uri), Representation(suffixOpt, Accept(req))))
+
+ 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
+
+ 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) => Some((new URL(new URL(base), req.uri), Representation(suffixOpt, Accept(req))))
+ case None => Some((new URL(uri), Representation(suffixOpt, Accept(req))))
+ }
}
--- a/src/main/scala/ReadWriteWeb.scala Mon Jun 25 10:03:10 2012 +0200
+++ b/src/main/scala/ReadWriteWeb.scala Mon Jun 25 10:07:32 2012 +0200
@@ -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 25 10:03:10 2012 +0200
+++ b/src/main/scala/ReadWriteWebArgs.scala Mon Jun 25 10:07:32 2012 +0200
@@ -180,6 +180,8 @@
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")
+
val rootDirectory = parser.parameter[File]("rootDirectory", "path to root directory where files are served", false) {
(sValue, opt) => {
val file = new File(sValue)
--- a/src/main/scala/ReadWriteWebJetty.scala Mon Jun 25 10:03:10 2012 +0200
+++ b/src/main/scala/ReadWriteWebJetty.scala Mon Jun 25 10:07:32 2012 +0200
@@ -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 25 10:03:10 2012 +0200
+++ b/src/main/scala/netty/ReadWriteWebNetty.scala Mon Jun 25 10:07:32 2012 +0200
@@ -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)
}