diff options
| author | Brice Figureau <brice-puppet@daysofwonder.com> | 2010-04-10 16:30:03 +0200 |
|---|---|---|
| committer | test branch <puppet-dev@googlegroups.com> | 2010-02-17 06:50:53 -0800 |
| commit | ee5d7f196fa62046f8fc3d3d723da608b17ce531 (patch) | |
| tree | aa92df8067b573167034d62e08c6dbe4c0d35b47 /lib/puppet/network/http/rack | |
| parent | 63c122f397c915cb1bec1a645958c808da92dce4 (diff) | |
Add master side file content streaming
This patch allows the puppetmaster to serve file chunks by chunks without
ever reading the file content in RAM.
This allows serving large files directly with the master without impacting
the master memory footprint.
Signed-off-by: Brice Figureau <brice-puppet@daysofwonder.com>
Diffstat (limited to 'lib/puppet/network/http/rack')
| -rw-r--r-- | lib/puppet/network/http/rack/rest.rb | 25 |
1 files changed, 24 insertions, 1 deletions
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. |
