Commit 33e4876d authored by Yoshiharu Hirose's avatar Yoshiharu Hirose

POSTリクエストに対しても応答を返すようにした。

parent 76f826ca
......@@ -53,6 +53,8 @@ object DummyHttpServer {
printf("%s: %s\n", ent.getKey, v)
}
}
var actionOps: Option[String] = None
if (t.getRequestMethod == "GET") {
val q = parseQuery(t.getRequestURI.getRawQuery)
if (q.nonEmpty) {
println("-- Query")
......@@ -60,15 +62,27 @@ object DummyHttpServer {
printf("%s: %s\n", k, v)
}
}
actionOps = q.get("Action")
} else {
val reader = new BufferedReader(new InputStreamReader(t.getRequestBody))
val body = Iterator.continually(reader.read()).takeWhile(_ != -1).map(_.toChar).mkString("")
if (body.length > 0) {
println("-- Body")
println(body)
val q = parseQuery(body)
if (q.nonEmpty) {
println("-- Query")
q.foreach { case (k, v) =>
printf("%s: %s\n", k, v)
}
}
actionOps = q.get("Action")
}
}
findFile(new File(t.getRequestURI.getPath).getName, new File(basedir)).orElse {
q.get("Action").flatMap { action => findFile(action + ".xml", new File(basedir)) }
actionOps.flatMap { action => findFile(action + ".xml", new File(basedir)) }
} match {
case Some(file) =>
t.sendResponseHeaders(200, file.length)
......@@ -88,6 +102,7 @@ object DummyHttpServer {
case e: Throwable =>
t.sendResponseHeaders(500, 0)
printf(" -> 500 (%s)\n", e.toString)
e.printStackTrace()
}
t.close()
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment