Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix impossible to set Content-Type header when using Hobbit::Filter #14

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/hobbit/filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ def _call(env)
env['PATH_INFO'] = '/' if env['PATH_INFO'].empty?
@env = env
@request = Rack::Request.new(@env)
@response = Hobbit::Response.new
@response = Hobbit::Response.new([], 200, {}) # pass empty params so that Content-Type header remains unset. otherwise, the main response's Content-Type will be ignored.
#@response.headers.delete "Content-Type" #another way to undo overriding default content-type
catch :halt do
filter :before
unless @response.status == 302
Expand Down
6 changes: 5 additions & 1 deletion lib/hobbit/render.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ def views_path
'views'
end

def clear_template_render_cache
Thread.current[:hobbit_render_cache] = nil
end

private

def _render(template, locals = {}, options = {}, &block)
Expand All @@ -49,7 +53,7 @@ def _render(template, locals = {}, options = {}, &block)
end

def cache
Thread.current[:cache] ||= Tilt::Cache.new
Thread.current[:hobbit_render_cache] ||= Tilt::Cache.new
end
end
end