Skip to content

Commit

Permalink
refactor: don't initialise property list for each request proxy.
Browse files Browse the repository at this point in the history
  • Loading branch information
outofcoffee committed May 13, 2024
1 parent 0e7f3d8 commit f7f6f4e
Showing 1 changed file with 18 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,27 +51,30 @@ import org.graalvm.polyglot.Value
import org.graalvm.polyglot.proxy.ProxyObject

// wrap request to allow property access syntactic sugar
val objectProxyRequestBuilder : ScriptRequestBuilder = { request ->
val objectProxyRequestBuilder: ScriptRequestBuilder = { request ->
RequestProxy(request)
}

/**
* Graal polyglot object proxy for [ScriptRequest].
*/
class RequestProxy(
request: HttpRequest
request: HttpRequest,
) : SimpleScriptRequest(request), ProxyObject {
private val properties = arrayOf(
"path",
"method",
"uri",
"headers",
"pathParams",
"queryParams",
"formParams",
"body",
"normalisedHeaders",
)

companion object {
private val properties = arrayOf(
"path",
"method",
"uri",
"headers",
"pathParams",
"queryParams",
"formParams",
"body",
"normalisedHeaders",
)
}

override fun getMember(key: String?): Any? = when (key) {
"path" -> path
Expand All @@ -96,7 +99,7 @@ class RequestProxy(
}
}

class MapObjectProxy(private val orig: Map<String, *>): ProxyObject {
class MapObjectProxy(private val orig: Map<String, *>) : ProxyObject {
override fun getMember(key: String?): Any? {
return key?.let { orig[key] }
}
Expand All @@ -106,7 +109,7 @@ class MapObjectProxy(private val orig: Map<String, *>): ProxyObject {
}

override fun hasMember(key: String?): Boolean {
return key?.let { orig.containsKey(key) } ?: false
return key?.let { orig.containsKey(key) } ?: false
}

override fun putMember(key: String?, value: Value?) {
Expand Down

0 comments on commit f7f6f4e

Please sign in to comment.