Commit acbd0c67 authored by Yoshiharu Hirose's avatar Yoshiharu Hirose

アップロード要求に応答する

parent bcc80266
...@@ -64,7 +64,7 @@ object DummyHttpServer { ...@@ -64,7 +64,7 @@ object DummyHttpServer {
if (t.getRequestMethod == "GET") { if (t.getRequestMethod == "GET") {
val q = parseQuery(t.getRequestURI.getRawQuery) val q = parseQuery(t.getRequestURI.getRawQuery)
if (q.nonEmpty) { if (q.nonEmpty) {
println("-- Query") println("-- Queries")
q.foreach { case (k, v) => q.foreach { case (k, v) =>
printf("%s: %s\n", k, v) printf("%s: %s\n", k, v)
} }
...@@ -77,14 +77,17 @@ object DummyHttpServer { ...@@ -77,14 +77,17 @@ object DummyHttpServer {
println("-- Body") println("-- Body")
println(body) println(body)
val q = parseQuery(body) val ctype = t.getRequestHeaders.getFirst("content-type")
if (q.nonEmpty) { if (ctype == null || ctype.matches("application/x-www-form-urlencoded.*")) {
println("-- Query") val q = parseQuery(body)
q.foreach { case (k, v) => if (q.nonEmpty) {
printf("%s: %s\n", k, v) println("-- Queries (parsed body)")
q.foreach { case (k, v) =>
printf("%s: %s\n", k, v)
}
actionOps = q.get("Action")
} }
} }
actionOps = q.get("Action")
} }
} }
...@@ -92,18 +95,17 @@ object DummyHttpServer { ...@@ -92,18 +95,17 @@ object DummyHttpServer {
actionOps.flatMap { action => findFile(action + ".xml", new File(basedir)) } actionOps.flatMap { action => findFile(action + ".xml", new File(basedir)) }
} match { } match {
case Some(file) => case Some(file) =>
t.sendResponseHeaders(200, file.length) replyFile(t, file)
val is = new BufferedInputStream(new FileInputStream(file))
val os = t.getResponseBody
val buf = new Array[Byte](file.length.toInt)
is.read(buf)
os.write(buf)
os.close()
is.close()
printf(" -> 200 (%s)\n", file.getAbsolutePath) printf(" -> 200 (%s)\n", file.getAbsolutePath)
case _ => case _ =>
t.sendResponseHeaders(404, 0) if (t.getRequestHeaders.getFirst("X-nifty-upload-id") != null
printf(" -> 404\n") && t.getRequestHeaders.getFirst("X-nifty-upload-operation") != null) {
replyUpload(t)
printf(" -> 200\n")
} else {
t.sendResponseHeaders(404, 0)
printf(" -> 404\n")
}
} }
} catch { } catch {
case e: Throwable => case e: Throwable =>
...@@ -114,6 +116,38 @@ object DummyHttpServer { ...@@ -114,6 +116,38 @@ object DummyHttpServer {
t.close() t.close()
} }
/**
* ファイルの中身を返す
*
* @param t HttpExchange
* @param file ファイル
*/
def replyFile(t: HttpExchange, file: File): Unit = {
t.sendResponseHeaders(200, file.length)
val is = new BufferedInputStream(new FileInputStream(file))
val os = t.getResponseBody
val buf = new Array[Byte](file.length.toInt)
is.read(buf)
os.write(buf)
os.close()
is.close()
}
/**
* アップロード要求に応答
*
* @param t HttpExchange
*/
def replyUpload(t: HttpExchange): Unit = {
t.getResponseHeaders.add("x-nifty-upload-applet-blocksize", "0")
t.getResponseHeaders.add("x-nifty-upload-applet-timeout", "0")
t.getResponseHeaders.add("x-nifty-upload-applet-socketbufsize", "0")
t.getResponseHeaders.add("x-nifty-upload-next-position", "0")
t.getResponseHeaders.add("x-nifty-upload-result-code", "200")
t.getResponseHeaders.add("x-nifty-upload-result-msg", "ok.")
t.sendResponseHeaders(200, 0)
}
/** /**
* ファイル検索 * ファイル検索
* *
......
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