Class: Crystal::RackApp

Inherits:
Object
  • Object
show all
Defined in:
lib/crystal/rack/rack_app.rb

Instance Method Summary collapse

Constructor Details

#initializeRackApp

Returns a new instance of RackApp.



4
5
6
# File 'lib/crystal/rack/rack_app.rb', line 4

def initialize
  @monitor = Monitor.new
end

Instance Method Details

#call(env) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/crystal/rack/rack_app.rb', line 8

def call env
  @monitor.synchronize do
    # [200, {"Content-Type" => "text/plain"}, ["Hello world!"]]
    # template_cache.clear if configs.reload_templates

    request  = Request.new(env)
    response = Response.new
    params   = request.params        
    
    Crystal.call request, response, params
    
    # 
    # invoke { dispatch! }
    # invoke { error_block!(response.status) }
    # 
            
    status, header, body = response.finish
            
    # Never produce a body on HEAD requests. Do retain the Content-Length
    # unless it's "0", in which case we assume it was calculated erroneously
    # for a manual HEAD response and remove it entirely.
    if env['REQUEST_METHOD'] == 'HEAD'
      body = []
      header.delete('Content-Length') if header['Content-Length'] == '0'
    end
    
    [status, header, body]
  end
end