Class: Thick::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/thick/server.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Server

Returns a new instance of Server.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/thick/server.rb', line 23

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

  @application = Rack::Lint.new(@application)

  @adapter = RackAdapter.new(@options[:address], @options[:port], '', false, JRuby.runtime, self)
  @server = Java::CzWildwebServer::HttpServerImpl.new
  @server.register('/', @adapter)
  @server.register('/*', @adapter)
  @server.start(@options[:address], @options[:port])
end

Class Method Details

.create(options = {}) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/thick/server.rb', line 11

def self.create(options = {})
  options = {
      :address => '0.0.0.0',
      :port => 9292,
      :environment => 'development',
      :directory => Dir.getwd,
      :file => 'config.ru'
  }.merge(options)

  Thick::Server.new(options)
end

Instance Method Details

#call(env) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/thick/server.rb', line 41

def call(env)
  hash = {}
  env.each_pair { |k,v| hash[k] = v }
  hash['rack.version'] = [1,3]
  hash['rack.input'] = StringIO.new(hash['rack.input'].force_encoding("ascii-8bit"))
  hash['rack.errors'] = $stderr
  puts hash.inspect
  status, headers, content = @application.call(hash)
  env['wildweb.response'].status(status)
  headers.each_pair { |k,v| env['wildweb.response'].header(k.to_s, v.to_s) }
  content.each { |data| env['wildweb.response'].write(data.to_s) }
  env['wildweb.response'].close
end