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

Changed Parsing and support for old Rack #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
15 changes: 9 additions & 6 deletions lib/image_placeholder/middleware.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,17 @@ def call(env)

def serve_placeholder_image(size = 100)
net_response = Net::HTTP.get_response(URI("https://#{@host}/#{size}"))
rack_response = Rack::Response.new(net_response.body, net_response.code.to_i)
safe_headers = net_response.to_hash
.reject { |key, _| hop_by_hop_header_fields.include?(key.downcase) }
.reject { |key, _| key.downcase == 'content-length' }

safe_headers.each do |key, values|
values.each do |value|
rack_response.add_header(key, value)
if Rack.version < '1.6'
rack_response = Rack::Response.new(net_response.body, net_response.code.to_i, safe_headers)
else
rack_response = Rack::Response.new(net_response.body, net_response.code.to_i)
safe_headers.each do |key, values|
values.each do |value|
rack_response.add_header(key, value)
end
end
end
rack_response.finish
Expand All @@ -47,7 +50,7 @@ def not_found?(status)
end

def image?(path)
@image_extensions.include? File.extname(path)[1, 3]
@image_extensions.any? { |i| File.extname(path).include? i }
end

def matched_size(path)
Expand Down