Class: Thick::Loader

Inherits:
Object
  • Object
show all
Includes:
Java::ServerRubyInterface
Defined in:
lib/thick/loader.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Loader

Returns a new instance of Loader.



7
8
9
10
11
# File 'lib/thick/loader.rb', line 7

def initialize(options)
  @options = options
  ENV['RACK_ENV'] ||= ENV['RAILS_ENV'] ||= @options[:environment]
  @application = @options[:application] ||= Rack::Builder.parse_file(File.expand_path(@options[:file], @options[:directory]))[0]
end

Instance Method Details

#call(env) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/thick/loader.rb', line 13

def call(env)
  env['rack.input'] = Buffer.new(env['rack.input'])
  env['rack.errors'] = env['rack.errors'].to_io

  status, headers, body = @application.call(env)

  return if env['thick.response_bypass']

  response = env['thick.response']

  response.setStatus(status)

  hijack = headers.delete('rack.hijack')

  headers.each_pair do |name, value|
    response.setHeader(name, value)
  end

  if body.respond_to?(:to_path)
    response.send_file(body.to_path)
  else
    body.each { |chunk| response.writeContent(chunk.to_s) }
    response.send
    # Rack Hijack async response
    hijack.call(env['rack.hijakck_io']) if hijack
    # Thick native async response
    env['thick.async'].call(response) if response.chunked?
  end
rescue => e
  puts e.message
  puts e.backtrace
end