bwillis / versioncake

:cake: Version Cake is an unobtrusive way to version APIs in your Rails or Rack apps
655 stars 47 forks source link

Sidekiq web UI failing to load #100

Closed garrettd714 closed 2 years ago

garrettd714 commented 3 years ago

I use Sidekiq along with the Sidekiq web UI. The web UI was failing to load after implementing versioncake.

FrozenError (can't modify frozen String) versioncake (4.0.2) lib/versioncake/response_strategy/http_content_type_strategy.rb:7:in 'execute'

To fix this, I added this code to the bottom (after the setup block) of the versioncake initializer

VersionCake::ResponseStrategy::HttpContentTypeStrategy.class_eval do
  def execute(context, _status, headers, _response)
    return if headers['Content-Type'].nil? || headers['Content-Type'].frozen?

    headers['Content-Type'] << ';' unless headers['Content-Type'].end_with? ';'
    headers['Content-Type'] << " #{version_key}=#{context.version.to_s}"
  end
end

Hope this helps anyone who runs into the same issue.

QuintinAdam commented 2 years ago

Thank you for the fix, we were stuck on this for a while!