in core/controller/src/main/scala/org/apache/openwhisk/core/controller/WebActions.scala [579:632]
private def extractEntityAndProcessRequest(authorizedToProceed: Boolean,
actionOwnerIdentity: Identity,
action: WhiskActionMetaData,
extension: MediaExtension,
onBehalfOf: Option[Identity],
context: Context,
httpEntity: HttpEntity)(implicit transid: TransactionId) = {
def process(body: Option[JsValue], isRawHttpAction: Boolean) = {
processRequest(actionOwnerIdentity, action, extension, onBehalfOf, context.withBody(body), isRawHttpAction)
}
if (authorizedToProceed) {
provide(action.annotations.getAs[Boolean](Annotations.RawHttpAnnotationName).getOrElse(false)) {
isRawHttpAction =>
httpEntity match {
case Empty =>
process(None, isRawHttpAction)
case HttpEntity.Strict(ct, json) if WhiskWebActionsApi.isJsonFamily(ct.mediaType) && !isRawHttpAction =>
if (json.nonEmpty) {
entity(as[JsValue]) { body =>
process(Some(body), isRawHttpAction)
}
} else {
process(None, isRawHttpAction)
}
case HttpEntity.Strict(ContentType(MediaTypes.`application/x-www-form-urlencoded`, _), _)
if !isRawHttpAction =>
entity(as[FormData]) { form =>
val body = form.fields.toMap.toJson.asJsObject
process(Some(body), isRawHttpAction)
}
case HttpEntity.Strict(contentType, data) =>
// for legacy, we are encoding application/json still
if (contentType.mediaType.binary || contentType.mediaType == `application/json`) {
Try(JsString(Base64.getEncoder.encodeToString(data.toArray))) match {
case Success(bytes) => process(Some(bytes), isRawHttpAction)
case Failure(t) => terminate(BadRequest, Messages.unsupportedContentType(contentType.mediaType))
}
} else {
val str = JsString(data.utf8String)
process(Some(str), isRawHttpAction)
}
case _ => terminate(BadRequest, Messages.unsupportedContentType)
}
}
} else {
terminate(Unauthorized)
}
}