markusthoemmes commented on a change in pull request #2676: Change response
when entity is empty from 200 to 204.
URL:
https://github.com/apache/incubator-openwhisk/pull/2676#discussion_r136289207
##########
File path:
core/controller/src/main/scala/whisk/core/controller/WebActions.scala
##########
@@ -216,32 +216,48 @@ protected[core] object WhiskWebActionsApi extends
Directives {
case _ => throw new Throwable("Invalid header")
} getOrElse List()
+ val body = fields.get("body")
+
val code = fields.get(rp.statusCode).map {
case JsNumber(c) =>
// the following throws an exception if the code is
// not a whole number or a valid code
StatusCode.int2StatusCode(c.toIntExact)
case _ => throw new Throwable("Illegal code")
- } getOrElse (OK)
+ }
+
+ body map {
+ case JsString(str) =>
Review comment:
Thinking about it, we could simplify it even more maybe:
```scala
body.collect {
case JsString(str) if str.nonEmpty =>
interpretHttpResponse(code.getOrElse(OK), headers, str, transid)
case js if js != JsNull =>
interpretHttpResponseAsJson(code.getOrElse(OK), headers, js, transid)
}.getOrElse(respondWithEmptyEntity(code.getOrElse(NoContent), headers))
```
Should be equivalent to the existing code. `collect` makes all non-defined
cases of the partial function turn into a `None`.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services