You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@openwhisk.apache.org by gi...@git.apache.org on 2017/09/09 16:54:57 UTC

[GitHub] markusthoemmes commented on a change in pull request #2717: Ensure that base64 encoded '+json' bodies are accepted and decoded.

markusthoemmes commented on a change in pull request #2717: Ensure that base64 encoded '+json' bodies are accepted and decoded.
URL: https://github.com/apache/incubator-openwhisk/pull/2717#discussion_r137930456
 
 

 ##########
 File path: core/controller/src/main/scala/whisk/core/controller/WebActions.scala
 ##########
 @@ -264,37 +264,47 @@ protected[core] object WhiskWebActionsApi extends Directives {
   }
 
   /**
-   * Finds the content-type in the header list and maps it to a known media type. If it is not
-   * recognized, construct a failure with appropriate message.
+   * Finds the content-type in the header list and ensures that it is a valid format. If it is not
+   * valid, construct a failure with appropriate message.
+   * If the content-type header is missing, then return the supplied defaultType
    */
   private def findContentTypeInHeader(headers: List[RawHeader],
                                       transid: TransactionId,
                                       defaultType: MediaType): Try[MediaType] = {
     headers.find(_.lowercaseName == `Content-Type`.lowercaseName) match {
       case Some(header) =>
         MediaType.parse(header.value) match {
-          case Right(mediaType: MediaType) =>
-            // lookup the media type specified in the content header to see if it is a recognized type
-            MediaTypes.getForKey(mediaType.mainType -> mediaType.subType).map(Success(_)).getOrElse {
-              // this is a content-type that is not recognized, reject it
-              Failure(RejectRequest(BadRequest, Messages.httpUnknownContentType)(transid))
-            }
-          case _ => Failure(RejectRequest(BadRequest, Messages.httpUnknownContentType)(transid))
+          case Right(mediaType: MediaType) => Success(mediaType)
+          case _                           => Failure(RejectRequest(BadRequest, Messages.httpUnknownContentType)(transid))
         }
       case None => Success(defaultType)
     }
   }
 
+  private def isJsonFamily(mt: MediaType) = {
+    mt == `application/json` || Option(mt.value).map(_.endsWith("+json")).exists(identity)
 
 Review comment:
   Can `mt.value` be `null`? 
   
   I don't think it can. Should it then just be 
   
   ```scala
   mt == `application/json` || mt.value.endsWith("+json")
   ```
 
----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services