Skip to content

Commit

Permalink
Return jsnull if null read
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieuancelin committed Mar 15, 2024
1 parent 490f470 commit 3aa85bf
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
3 changes: 3 additions & 0 deletions otoroshi/app/env/Env.scala
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,9 @@ class Env(
private lazy val halloweenStop =
DateTime.now().withMonthOfYear(10).withDayOfMonth(31).plusDays(1).withMillisOfDay(1)

lazy val jsonPathNullReadIsJsNull =
configuration.getOptionalWithFileSupport[Boolean]("otoroshi.options.jsonPathNullReadIsJsNull").getOrElse(false)

lazy val dynamicBodySizeCompute =
configuration.getOptionalWithFileSupport[Boolean]("otoroshi.options.dynamicBodySizeCompute").getOrElse(true)

Expand Down
8 changes: 7 additions & 1 deletion otoroshi/app/utils/jsonpath.scala
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ object JsonPathUtils {
// }
}

private lazy val jsonPathNullReadIsJsNull = OtoroshiEnvHolder.get().jsonPathNullReadIsJsNull

def getAtPolyF(payload: String, path: String): Either[JsonPathReadError, JsValue] = {
//val env = OtoroshiEnvHolder.get()
//env.metrics.withTimer("JsonPathUtils.getAtPolyF") {
Expand All @@ -95,7 +97,11 @@ object JsonPathUtils {
if (read != null) {
Right(Writes.jsonNodeWrites.writes(read))
} else {
Left(JsonPathReadError("null read", path, payload, None))
if (jsonPathNullReadIsJsNull) {
Right(JsNull)
} else {
Left(JsonPathReadError("null read", path, payload, None))
}
}
} match {
case Failure(e) => Left(JsonPathReadError("error while trying to read", path, payload, e.some))
Expand Down
2 changes: 2 additions & 0 deletions otoroshi/conf/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -1033,6 +1033,8 @@ otoroshi {
}
}
options {
jsonPathNullReadIsJsNull = false
jsonPathNullReadIsJsNull = ${?OTOROSHI_OPTIONS_JSONPATHNULLREADISJSNULL}
bypassUserRightsCheck = false
bypassUserRightsCheck = ${?OTOROSHI_OPTIONS_BYPASSUSERRIGHTSCHECK}
emptyContentLengthIsChunked = true
Expand Down

0 comments on commit 3aa85bf

Please sign in to comment.