Class: Miron::Handler::Unicorn

Inherits:
Unicorn::HttpServer
  • Object
show all
Defined in:
lib/miron/handlers/unicorn.rb

Defined Under Namespace

Classes: Proxy

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mironfile, options) ⇒ Unicorn

Returns a new instance of Unicorn


10
11
12
13
# File 'lib/miron/handlers/unicorn.rb', line 10

def initialize(mironfile, options)
  @mironfile = mironfile
  super
end

Class Method Details

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


6
7
8
# File 'lib/miron/handlers/unicorn.rb', line 6

def self.run(mironfile, options = {})
  Unicorn::Proxy.new(mironfile, options)
end

Instance Method Details

#process_client(socket) ⇒ Object


15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/miron/handlers/unicorn.rb', line 15

def process_client(socket)
  # Get response
  miron_request = @request.read(socket)
  miron_response = Miron::RequestFetcher.new(miron_request, @mironfile).fetch_response
  # Process response
  response_http_status = miron_response.http_status
  # Add cookies to headers
  miron_response.cookies.each do |k, v|
    miron_response.headers['Set-Cookie'] = "#{k}=#{v}"
  end
  response_body = [miron_response.body]
  # Write back to Unicorn
  http_response_write(socket, response_http_status, miron_response.headers, response_body)
  unless socket.closed?
    socket.shutdown
    socket.close
  end
rescue => e
  handle_error(socket, e)
end