rubyonjets / jets

Ruby on Jets
http://rubyonjets.com
MIT License
2.6k stars 181 forks source link

Support rendering XML #172

Closed philnash closed 5 years ago

philnash commented 5 years ago

Checklist

My Environment

Software Version
Operating System MacOS 10.14.3
Jets 1.6.4
Ruby 2.5.3

Expected Behaviour

When rendering as xml I would expect Jets to set a Content-Type header set to application/xml.

Current Behavior

When you render a string as xml from a controller the Content-Type is set totext/html`

Step-by-step reproduction instructions

Create a Jets application and a controller. Create an action that renders the result as xml:

class MessagesController > ApplicationController
  def create
    render xml: "<Hello>World</Hello>"
  end
end

Create a route for the action. Run the application and visit the route. The response header is text/html.

I am raising this as a bug as the content is rendered when it is passed via render xml: content but it's not served correctly.

Solution Suggestion

This is something that Rails handles, so I'm surprised it didn't work in Jets as the rendering is handed off to ActionController::Base. I tried to follow the render path, which lead me to setting up the render options which shows that the xml key is handled. But I couldn't find where it went from there and where the response headers were set.

Workaround

You can work around this for now by manually setting the content type:

    render xml: "<Hello>World</Hello>", content_type: "application/xml"
tongueroo commented 5 years ago

@philnash Thanks so much for the clear issue 👍

Fixed in #173 Released in v1.6.5