Commit eea0d72a authored by Michael Iles's avatar Michael Iles
Browse files

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.
parent 15acb15a
......@@ -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 = $('<code />').text("no content")
pre = $('<pre class="json" />').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 = $('<code />').text(JSON.stringify(JSON.parse(content), null, 2))
pre = $('<pre class="json" />').append(code)
else if contentType.indexOf("application/xml") == 0
else if contentType is "application/xml" || /\+xml$/.test(contentType)
code = $('<code />').text(@formatXml(content))
pre = $('<pre class="xml" />').append(code)
else if contentType.indexOf("text/html") == 0
else if contentType is "text/html"
code = $('<code />').html(content)
pre = $('<pre class="xml" />').append(code)
else if contentType.indexOf("image/") == 0
else if /^image\//.test(contentType)
pre = $('<img>').attr('src',data.request.url)
# don't know what to render!
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment