module Crystal class RackApp def initialize @monitor = Monitor.new end 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 # def handle_not_found!(boom) # @env['sinatra.error'] = boom # @response.status = 404 # @response.headers['X-Cascade'] = 'pass' # @response.body = ['

Not Found

'] # error_block! boom.class, NotFound # end # # def handle_exception!(boom) # @env['sinatra.error'] = boom # # dump_errors!(boom) if configs.dump_errors? # raise boom if configs.show_exceptions? # # @response.status = 500 # if res = error_block!(boom.class) # res # elsif configs.raise_errors? # raise boom # else # error_block!(Exception) # end # end # Run the block with 'throw :halt' support and apply result to the response. # def invoke(&block) # res = catch(:halt) { instance_eval(&block) } # return if res.nil? # # case # when res.respond_to?(:to_str) # @response.body = [res] # when res.respond_to?(:to_ary) # res = res.to_ary # if Fixnum === res.first # if res.length == 3 # @response.status, headers, body = res # @response.body = body if body # headers.each { |k, v| @response.headers[k] = v } if headers # elsif res.length == 2 # @response.status = res.first # @response.body = res.last # else # raise TypeError, "#{res.inspect} not supported" # end # else # @response.body = res # end # when res.respond_to?(:each) # @response.body = res # when (100...599) === res # @response.status = res # end # # res # end end end