Skip to content

Commit

Permalink
Upgrade sinatra to 1.4.2
Browse files Browse the repository at this point in the history
Changes needed to upgrade to sinatra 1.4.2

- Use Rack:File instead of Sinatra::Base::StaticFile
- Redirects uses 303 http code for other verbs than GET
  • Loading branch information
frodenas committed Apr 3, 2013
1 parent 140ab42 commit ec67394
Show file tree
Hide file tree
Showing 15 changed files with 62 additions and 41 deletions.
25 changes: 13 additions & 12 deletions Gemfile.lock
Expand Up @@ -31,7 +31,7 @@ PATH
retryable (~> 1.3.2)
ruby-atmos-pure (~> 1.0.5)
sigar (~> 0.7.2)
sinatra (~> 1.2.8)
sinatra (~> 1.4.2)
sys-filesystem (~> 1.1.0)
thin (~> 1.5.0)
uuidtools (~> 2.1.2)
Expand Down Expand Up @@ -121,7 +121,7 @@ PATH
aws-sdk (= 1.8.5)
fog (~> 1.10.0)
sequel (~> 3.43.0)
sinatra (~> 1.2.8)
sinatra (~> 1.4.2)
thin (~> 1.5.0)
yajl-ruby (~> 1.1.0)

Expand Down Expand Up @@ -167,7 +167,7 @@ PATH
redis (~> 3.0.2)
resque (~> 1.23.0)
sequel (~> 3.43.0)
sinatra (~> 1.2.8)
sinatra (~> 1.4.2)
thin (~> 1.5.0)
yajl-ruby (~> 1.1.0)

Expand All @@ -180,7 +180,7 @@ PATH
eventmachine (~> 0.12.10)
logging (~> 1.5.0)
nats (~> 0.4.28)
sinatra (~> 1.2.8)
sinatra (~> 1.4.2)
thin (~> 1.5.0)
yajl-ruby (~> 1.1.0)

Expand Down Expand Up @@ -221,7 +221,7 @@ PATH
remote: simple_blobstore_server
specs:
simple_blobstore_server (1.5.0.pre.3)
sinatra (~> 1.2.8)
sinatra (~> 1.4.2)
thin (~> 1.5.0)

GEM
Expand All @@ -233,7 +233,6 @@ GEM
json (~> 1.4)
nokogiri (>= 1.4.4)
uuidtools (~> 2.1)
backports (3.1.1)
bcrypt-ruby (3.0.1)
builder (3.1.4)
ci_reporter (1.8.4)
Expand All @@ -259,7 +258,7 @@ GEM
ffi (1.6.0)
fog (1.10.0)
builder
excon (~> 0.14)
excon (~> 0.20)
formatador (~> 0.2.0)
mime-types
multi_json (~> 1.0)
Expand Down Expand Up @@ -318,7 +317,9 @@ GEM
coderay (~> 1.0.5)
method_source (~> 0.8)
slop (~> 3.4)
rack (1.4.5)
rack (1.5.2)
rack-protection (1.5.0)
rack
rack-test (0.6.2)
rack (>= 1.0)
rake (10.0.4)
Expand Down Expand Up @@ -354,10 +355,10 @@ GEM
simplecov-html (0.7.1)
simplecov-rcov (0.2.3)
simplecov (>= 0.4.1)
sinatra (1.2.9)
backports
rack (~> 1.1, < 1.5)
tilt (>= 1.2.2, < 2.0)
sinatra (1.4.2)
rack (~> 1.5, >= 1.5.2)
rack-protection (~> 1.4)
tilt (~> 1.3, >= 1.3.4)
slop (3.4.4)
sqlite3 (1.3.7)
sys-filesystem (1.1.0)
Expand Down
2 changes: 1 addition & 1 deletion bosh_agent/bosh_agent.gemspec
Expand Up @@ -21,7 +21,7 @@ Gem::Specification.new do |s|
s.add_dependency 'ruby-atmos-pure', '~>1.0.5'
s.add_dependency 'thin', '~>1.5.0'
s.add_dependency 'yajl-ruby', '~>1.1.0'
s.add_dependency 'sinatra', '~>1.2.8'
s.add_dependency 'sinatra', '~>1.4.2'
s.add_dependency 'nats', '~>0.4.28'
s.add_dependency 'sigar', '~>0.7.2'
s.add_dependency 'httpclient', '=2.2.4'
Expand Down
2 changes: 1 addition & 1 deletion bosh_cli/lib/cli/director.rb
Expand Up @@ -456,7 +456,7 @@ def request_and_track(method, uri, options = {})

http_status, _, headers = request(method, uri, content_type, payload)
location = headers[:location]
redirected = http_status == 302
redirected = [302, 303].include? http_status
task_id = nil

if redirected
Expand Down
25 changes: 23 additions & 2 deletions bosh_cli/spec/unit/director_spec.rb
Expand Up @@ -271,7 +271,7 @@
end

describe "tracking request" do
it "starts polling task if request responded with a redirect to task URL" do
it "starts polling task if request responded with a redirect (302) to task URL" do
options = { :arg1 => 1, :arg2 => 2 }

@director.should_receive(:request).
Expand All @@ -292,6 +292,27 @@
should == ["polling result", "502"]
end

it "starts polling task if request responded with a redirect (303) to task URL" do
options = { :arg1 => 1, :arg2 => 2 }

@director.should_receive(:request).
with(:get, "/stuff", "text/plain", "abc").
and_return([303, "body", { :location => "/tasks/502" }])

tracker = mock("tracker", :track => "polling result", :output => "foo")

Bosh::Cli::TaskTracker.should_receive(:new).
with(@director, "502", options).
and_return(tracker)

@director.request_and_track(:get, "/stuff",
{:content_type => "text/plain",
:payload => "abc",
:arg1 => 1, :arg2 => 2
}).
should == ["polling result", "502"]
end

describe "not tracking trackable requests" do
it "returns without tracking/polling task if request responded with a redirect to task URL" do
options = { :arg1 => 1, :arg2 => 2 }
Expand Down Expand Up @@ -319,7 +340,7 @@
end
end

it "considers all responses but 302 a failure" do
it "considers all responses but 302 and 303 a failure" do
[200, 404, 403].each do |code|
@director.should_receive(:request).
with(:get, "/stuff", "text/plain", "abc").
Expand Down
2 changes: 1 addition & 1 deletion bosh_registry/bosh_registry.gemspec
Expand Up @@ -20,7 +20,7 @@ Gem::Specification.new do |s|
s.executables = %w(bosh_registry migrate)

s.add_dependency "sequel", "~>3.43.0"
s.add_dependency "sinatra", "~>1.2.8"
s.add_dependency "sinatra", "~>1.4.2"
s.add_dependency "thin", "~>1.5.0"
s.add_dependency "yajl-ruby", "~>1.1.0"
s.add_dependency "fog", "~>1.10.0"
Expand Down
2 changes: 1 addition & 1 deletion director/director.gemspec
Expand Up @@ -38,7 +38,7 @@ Gem::Specification.new do |s|
s.add_dependency "redis", "~>3.0.2"
s.add_dependency "resque", "~>1.23.0"
s.add_dependency "sequel", "~>3.43.0"
s.add_dependency "sinatra", "~>1.2.8"
s.add_dependency "sinatra", "~>1.4.2"
s.add_dependency "thin", "~>1.5.0"
s.add_dependency "yajl-ruby", "~>1.1.0"

Expand Down
41 changes: 20 additions & 21 deletions director/lib/director/api/api_helper.rb
Expand Up @@ -5,38 +5,37 @@ module Api
module ApiHelper
READ_CHUNK_SIZE = 16384

class DisposableStaticFile < ::Sinatra::Base::StaticFile
class DisposableFile < ::Rack::File
def close
super
FileUtils.rm_rf(self.path) if File.exists?(self.path)
end
end

# Adapted from Sinatra::Base#send_file. There are two differences:
# it doesn't support range queries
# it uses DisposableStaticFile instead of Sinatra::Base::StaticFile.
# DisposableStaticFile gets removed on "close" call. This is primarily
# Adapted from Sinatra::Base#send_file. There is one difference:
# it uses DisposableFile instead of Rack::File.
# DisposableFile gets removed on "close" call. This is primarily
# meant to serve temporary files fetched from the blobstore.
# We CANNOT use a Sinatra after filter, as the filter is called before
# the contents of the file is sent to the client.
def send_disposable_file(path, opts = {})
stat = File.stat(path)
last_modified(opts[:last_modified] || stat.mtime)

if opts[:type] or not response["Content-Type"]
content_type(opts[:type] || File.extname(path),
:default => "application/octet-stream")
if opts[:type] || !response['Content-Type']
content_type opts[:type] || File.extname(path), :default => 'application/octet-stream'
end

if opts[:disposition] == "attachment" || opts[:filename]
attachment opts[:filename] || path
elsif opts[:disposition] == "inline"
response["Content-Disposition"] = "inline"
end
disposition = opts[:disposition]
filename = opts[:filename]
disposition = 'attachment' if disposition.nil? && filename
filename = path if filename.nil?
attachment(filename, disposition) if disposition

file_length = opts[:length] || stat.size
sf = DisposableStaticFile.open(path, "rb")
last_modified opts[:last_modified] if opts[:last_modified]

response["Content-Length"] ||= file_length.to_s
halt sf
file = DisposableFile.new nil
file.path = path
result = file.serving env
result[1].each { |k,v| headers[k] ||= v }
headers['Content-Length'] = result[1]['Content-Length']
halt opts[:status] || result[0], result[2]
rescue Errno::ENOENT
not_found
end
Expand Down
2 changes: 1 addition & 1 deletion health_monitor/health_monitor.gemspec
Expand Up @@ -23,7 +23,7 @@ Gem::Specification.new do |s|
s.add_dependency "nats", "~>0.4.28"
s.add_dependency "yajl-ruby", "~>1.1.0"
s.add_dependency "thin", "~>1.5.0"
s.add_dependency "sinatra", "~>1.2.8"
s.add_dependency "sinatra", "~>1.4.2"
s.add_dependency "aws-sdk", "1.8.5"

s.bindir = 'bin'
Expand Down
2 changes: 1 addition & 1 deletion simple_blobstore_server/simple_blobstore_server.gemspec
Expand Up @@ -18,7 +18,7 @@ Gem::Specification.new do |s|
s.require_path = "lib"

s.add_dependency "thin", "~>1.5.0"
s.add_dependency "sinatra", "~> 1.2.8"
s.add_dependency "sinatra", "~> 1.4.2"

s.bindir = 'bin'
s.executables << 'simple_blobstore_server'
Expand Down
Binary file removed vendor/cache/backports-3.1.1.gem
Binary file not shown.
Binary file removed vendor/cache/rack-1.4.5.gem
Binary file not shown.
Binary file added vendor/cache/rack-1.5.2.gem
Binary file not shown.
Binary file added vendor/cache/rack-protection-1.5.0.gem
Binary file not shown.
Binary file removed vendor/cache/sinatra-1.2.9.gem
Binary file not shown.
Binary file added vendor/cache/sinatra-1.4.2.gem
Binary file not shown.

0 comments on commit ec67394

Please sign in to comment.