From eea0d72a856771604041e16af5c484e5cc27a0ca Mon Sep 17 00:00:00 2001 From: Michael Iles Date: Sat, 18 Jan 2014 11:41:08 -0500 Subject: [PATCH] Added support for pretty-printing responses for media types with extended subtypes. For example the media type 'application/vnd.myresource+json; version=1.2' will be correctly recognized as JSON and pretty-printed. Conforms to RFC 6838, 6839. --- src/main/coffeescript/view/OperationView.coffee | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/coffeescript/view/OperationView.coffee b/src/main/coffeescript/view/OperationView.coffee index 4a79f138..19594c18 100644 --- a/src/main/coffeescript/view/OperationView.coffee +++ b/src/main/coffeescript/view/OperationView.coffee @@ -276,21 +276,21 @@ class OperationView extends Backbone.View headers = data.getHeaders() # if server is nice, and sends content-type back, we can use it - contentType = headers["Content-Type"] + contentType = if headers["Content-Type"] then headers["Content-Type"].split(";")[0].trim() else null - if content == undefined + if !content code = $('').text("no content") pre = $('
').append(code)
-    else if contentType.indexOf("application/json") == 0 || contentType.indexOf("application/hal+json") == 0
+    else if contentType is "application/json" || /\+json$/.test(contentType)
       code = $('').text(JSON.stringify(JSON.parse(content), null, 2))
       pre = $('
').append(code)
-    else if contentType.indexOf("application/xml") == 0
+    else if contentType is "application/xml" || /\+xml$/.test(contentType)
       code = $('').text(@formatXml(content))
       pre = $('
').append(code)
-    else if contentType.indexOf("text/html") == 0
+    else if contentType is "text/html"
       code = $('').html(content)
       pre = $('
').append(code)
-    else if contentType.indexOf("image/") == 0
+    else if /^image\//.test(contentType)
       pre = $('').attr('src',data.request.url)
     else
       # don't know what to render!