mirror of
https://github.com/librecaptcha/lc-core.git
synced 2025-05-22 10:01:44 -04:00
optimise string operations
This commit is contained in:
parent
89eeb76c46
commit
6fd34c16ac
@ -19,15 +19,15 @@ class Server(port: Int) {
|
|||||||
private def getRequestJson(ex: HttpExchange): JValue = {
|
private def getRequestJson(ex: HttpExchange): JValue = {
|
||||||
val requestBody = ex.getRequestBody
|
val requestBody = ex.getRequestBody
|
||||||
val bytes = requestBody.readAllBytes
|
val bytes = requestBody.readAllBytes
|
||||||
val string = bytes.map(_.toChar).mkString
|
val string = new String(bytes)
|
||||||
parse(string)
|
parse(string)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private val eqPattern = java.util.regex.Pattern.compile("=")
|
||||||
private def getPathParameter(ex: HttpExchange): String = {
|
private def getPathParameter(ex: HttpExchange): String = {
|
||||||
try {
|
try {
|
||||||
val uri = ex.getRequestURI.toString
|
val query = ex.getRequestURI.getQuery
|
||||||
val param = uri.split("\\?")(1)
|
eqPattern.split(query)(1)
|
||||||
param.split("=")(1)
|
|
||||||
} catch {
|
} catch {
|
||||||
case exception: ArrayIndexOutOfBoundsException => {
|
case exception: ArrayIndexOutOfBoundsException => {
|
||||||
println(exception.getStackTrace)
|
println(exception.getStackTrace)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user