markusthoemmes commented on a change in pull request #2218: Port Controller
from Spray to Akka
URL:
https://github.com/apache/incubator-openwhisk/pull/2218#discussion_r127581735
##########
File path:
core/controller/src/main/scala/whisk/core/controller/WebActions.scala
##########
@@ -251,35 +260,33 @@ protected[core] object WhiskWebActionsApi extends
Directives {
}
}
- private def interpretHttpResponse(code: StatusCode, headers:
List[RawHeader], str: String, transid: TransactionId): RequestContext => Unit =
{
+ private def interpretHttpResponse(code: StatusCode, headers:
List[RawHeader], str: String, transid: TransactionId) = {
val parsedHeader: Try[MediaType] = headers.find(_.lowercaseName ==
`Content-Type`.lowercaseName) match {
case Some(header) =>
- HttpParser.parseHeader(header) match {
- case Right(header: `Content-Type`) =>
- val mediaType = header.contentType.mediaType
+ 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 _ => Failure(RejectRequest(BadRequest,
Messages.httpUnknownContentType)(transid))
+ }
case None => Success(`text/html`)
}
parsedHeader.flatMap { mediaType =>
- if (mediaType.binary) {
- Try(HttpData(Base64.getDecoder().decode(str))).map((mediaType,
_))
+ if (mediaType.binary || mediaType == `application/json`) {
+ Try(new String(Base64.getDecoder().decode(str),
"UTF-8")).map((mediaType, _))
} else {
- Success(mediaType, HttpData(str))
+ Success(mediaType, str)
}
} match {
- case Success((mediaType, data)) =>
+ case Success((mediaType, data: String)) =>
respondWithHeaders(headers) {
- respondWithMediaType(mediaType) {
- complete(code, data)
+ mediaType.toString.split("/") match {
+ case Array(mainType, subType) =>
+ complete(code,
HttpEntity(ContentType(MediaType.customWithFixedCharset(mainType, subType,
HttpCharsets.`UTF-8`)), data))
Review comment:
I'm a bit uneasy with the changes to this method.
Do we need to manually split Strings here vs. parsing the data out using
akka methods?
----------------------------------------------------------------
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