Created
July 24, 2012 17:04
-
-
Save joshcough/3171223 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object HTMLWriterWebServer { | |
import unfiltered.request._ | |
import unfiltered.response._ | |
import unfiltered.netty._ | |
import unfiltered.netty.request._ | |
def main(a: Array[String]) { | |
case class Report(command:String, module:String) | |
val reports = collection.mutable.Map[Int, Report]() | |
Http(8080).handler(cycle.MultiPartDecoder{ | |
case POST(Path("/addReport")) & MultiPart(req) => { | |
case Decode(binding) => | |
val disk = MultiPartParams.Disk(binding) | |
(disk.files("module"), disk.params("command")(0)) match { | |
case (Seq(f, _*), command) => | |
val newId = reports.size | |
reports.put(newId, Report(command, new String(f.bytes))) | |
ResponseString((newId -> reports(newId)).toString) | |
case _ => ResponseString("no module uploaded!") | |
} | |
} | |
}).handler(cycle.Planify{ | |
case GET(Path("/runReport")) => Html( | |
<html> | |
<head><title>Run Report</title></head> | |
<body> | |
I would have ran this: { /* reports(id.toInt).toString */ "ugh" } | |
</body> | |
</html> | |
) | |
case GET(Path("/addReport")) => { | |
Html( | |
<html> | |
<head><title>upload module!</title></head> | |
<body> | |
<h1>upload module!</h1> | |
<form action="/addReport" method="POST" enctype="multipart/form-data"> | |
Module: <input type="file" name="module" /><br/> | |
Command: <input type="text" name="command"/><br/> | |
<input type="submit"/> | |
</form> | |
</body> | |
</html> | |
) | |
} | |
}).run | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment