Class: Gemkeeper::CompactIndexServer::ResponseBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/gemkeeper/compact_index_server/response_builder.rb

Overview

Builds Rack responses for compact index payloads: conditional GET (ETag), byte-range requests, and the digest/accept-ranges headers Bundler expects.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(req) ⇒ ResponseBuilder

Returns a new instance of ResponseBuilder.



17
18
19
# File 'lib/gemkeeper/compact_index_server/response_builder.rb', line 17

def initialize(req)
  @req = req
end

Class Method Details

.file(path) ⇒ Object



10
11
12
13
14
15
# File 'lib/gemkeeper/compact_index_server/response_builder.rb', line 10

def self.file(path)
  [200,
   { "content-type" => "application/octet-stream",
     "content-length" => File.size(path).to_s },
   File.open(path, "rb")]
end

Instance Method Details

#index(body, etag) ⇒ Object

200 / 206 / 304 for an in-memory index body.



22
23
24
25
26
27
# File 'lib/gemkeeper/compact_index_server/response_builder.rb', line 22

def index(body, etag)
  quoted = %("#{etag}")
  return [304, { "etag" => quoted }, []] if @req.env["HTTP_IF_NONE_MATCH"] == quoted

  range(body, etag) || [200, index_headers(body, etag), [body]]
end