23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/rhet-butler/stasis/rack-loader.rb', line 23
def load(source_uri)
doc = Document.new
doc.source_uri = source_uri
source_uri = root_uri.join(source_uri).route_from(root_uri).to_s
source_uri = "/" if source_uri == "#"
env = {
"REQUEST_METHOD" => "GET",
"SCRIPT_NAME" => "",
"PATH_INFO" => source_uri,
"QUERY_STRING" => "",
"SERVER_NAME" => server_name,
"rack.errors" => StringIO.new,
"rack.input" => StringIO.new,
"rack.url_scheme" => "http",
"rack.version" => Rack::VERSION,
"rack.multithread" => false,
"rack.multiprocess" => false,
"rack.runonce" => false,
"rack.hijack?" => false,
}
response = @app.call(env)
code, , body = *response
unless code == 200
raise LoadFailed, "Bad response from local server for #{source_uri}:\n#{response[0..1].inspect} body: #{response[2].to_a.join.length}"
end
doc.type = ["Content-Type"]
doc.body = body.to_a.join("")
return doc
end
|