Last active
January 4, 2016 08:09
-
-
Save hideshi/8593433 to your computer and use it in GitHub Desktop.
CGI library for Scala
This file contains 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
package cgilib | |
import System._ | |
import scala.io.Source._ | |
import scala.collection.JavaConversions._ | |
object CGI { | |
val GET = "GET" | |
val POST = "POST" | |
def envInfo():Map[String, String] = {getenv().toMap} | |
def params(method:String):Map[String, String] = { | |
val in = method match { | |
case m if m == GET => getenv("QUERY_STRING") | |
case m if m == POST => stdin.getLines.mkString("\n") | |
case _ => throw new IllegalArgumentException() | |
} | |
val list = in.split("&").toList.map(_.split("=")) | |
(for(item <- list) yield { | |
item match { | |
case i if i.length == 1 => (i(0), "") | |
case i if i.length == 2 => (i(0), i(1)) | |
} | |
}).toMap | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment