diff options
Diffstat (limited to 'lib/puppet')
| -rw-r--r-- | lib/puppet/file_serving/content.rb | 7 | ||||
| -rw-r--r-- | lib/puppet/network/http/mongrel/rest.rb | 11 | ||||
| -rw-r--r-- | lib/puppet/network/http/rack/rest.rb | 25 | ||||
| -rw-r--r-- | lib/puppet/network/http/webrick/rest.rb | 7 |
4 files changed, 43 insertions, 7 deletions
diff --git a/lib/puppet/file_serving/content.rb b/lib/puppet/file_serving/content.rb index 9fc1d08b3..87ef4fbbf 100644 --- a/lib/puppet/file_serving/content.rb +++ b/lib/puppet/file_serving/content.rb @@ -26,10 +26,11 @@ class Puppet::FileServing::Content < Puppet::FileServing::Base instance end - # Collect our data. + # BF: we used to fetch the file content here, but this is counter-productive + # for puppetmaster streaming of file content. So collect just returns itself def collect return if stat.ftype == "directory" - content + self end # Read the content of our file in. @@ -44,6 +45,6 @@ class Puppet::FileServing::Content < Puppet::FileServing::Base end def to_raw - content + File.new(full_path(), "r") end end diff --git a/lib/puppet/network/http/mongrel/rest.rb b/lib/puppet/network/http/mongrel/rest.rb index 7b28d880b..8668bf802 100644 --- a/lib/puppet/network/http/mongrel/rest.rb +++ b/lib/puppet/network/http/mongrel/rest.rb @@ -54,12 +54,19 @@ class Puppet::Network::HTTP::MongrelREST < Mongrel::HttpHandler # we have a failure, unless we're on a version of mongrel that doesn't # support this. if status < 300 - response.start(status) { |head, body| body.write(result) } + unless result.is_a?(File) + response.start(status) { |head, body| body.write(result) } + else + response.start(status) { |head, body| } + response.send_status(result.stat.size) + response.send_header + response.send_file(result.path) + end else begin response.start(status,false,result) { |head, body| body.write(result) } rescue ArgumentError - response.start(status) { |head, body| body.write(result) } + response.start(status) { |head, body| body.write(result) } end end end diff --git a/lib/puppet/network/http/rack/rest.rb b/lib/puppet/network/http/rack/rest.rb index 104751271..5245275dd 100644 --- a/lib/puppet/network/http/rack/rest.rb +++ b/lib/puppet/network/http/rack/rest.rb @@ -8,6 +8,24 @@ class Puppet::Network::HTTP::RackREST < Puppet::Network::HTTP::RackHttpHandler HEADER_ACCEPT = 'HTTP_ACCEPT'.freeze ContentType = 'Content-Type'.freeze + CHUNK_SIZE = 8192 + + class RackFile + def initialize(file) + @file = file + end + + def each + while chunk = @file.read(CHUNK_SIZE) + yield chunk + end + end + + def close + @file.close + end + end + def initialize(args={}) super() initialize_for_puppet(args) @@ -20,7 +38,12 @@ class Puppet::Network::HTTP::RackREST < Puppet::Network::HTTP::RackHttpHandler # produce the body of the response def set_response(response, result, status = 200) response.status = status - response.write result + unless result.is_a?(File) + response.write result + else + response["Content-Length"] = result.stat.size + response.body = RackFile.new(result) + end end # Retrieve the accept header from the http request. diff --git a/lib/puppet/network/http/webrick/rest.rb b/lib/puppet/network/http/webrick/rest.rb index 274665dcd..9bfd0ce6a 100644 --- a/lib/puppet/network/http/webrick/rest.rb +++ b/lib/puppet/network/http/webrick/rest.rb @@ -50,7 +50,12 @@ class Puppet::Network::HTTP::WEBrickREST < WEBrick::HTTPServlet::AbstractServlet def set_response(response, result, status = 200) response.status = status - response.body = result if status >= 200 and status != 304 + if status >= 200 and status != 304 + response.body = result + if result.is_a?(File) + response["content-length"] = result.stat.size + end + end response.reason_phrase = result if status < 200 or status >= 300 end |
