Module: Iodine::Http::Rack

Defined in:
lib/iodine/http/rack_support.rb

Overview

This (will be) a Rack handler for the Iodine HTTP server.

Class Method Summary collapse

Class Method Details

.call(request, response) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/iodine/http/rack_support.rb', line 17

def call request, response
  if @pre_rack_handler
    tmp = @pre_rack_handler.call(request, response)
    return tmp if tmp
  end
  # response.quite!
  res = @app.call rack_env(request)
  raise "Rack app returned an unexpected value: #{res.to_s}" unless res && res.is_a?(Array)
  response.status = res[0]
  response.headers.clear
  res[1].each {|k, v| response.headers[k.to_s.downcase] = v }
  response.body = res[2]
  response.raw_cookies.clear
  response.headers['set-cookie'.freeze] = response.headers.delete('set-cookie'.freeze).split("\n".freeze).join("\r\nset-cookie: ".freeze) if request[:io].is_a?(Iodine::Http::Http1) && response.headers['set-cookie'.freeze]
  response.request[:no_log] = true
  true
end

.run(app, options = {}) ⇒ Object



7
8
9
10
11
12
13
14
15
16
# File 'lib/iodine/http/rack_support.rb', line 7

def run(app, options = {})
  @app = app
  Iodine.threads ||= 18
  Iodine.port = options[:Port]
  RACK_DICTIONARY['rack.multiprocess'.freeze] = Iodine.processes.to_i > 1
  Iodine.protocol ||= Iodine::Http::Http1
  @pre_rack_handler = Iodine::Http.on_http unless Iodine::Http.on_http == Iodine::Http::NOT_IMPLEMENTED
  Iodine::Http.on_http self
  true
end