Class: Ebb::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/ebb.rb,
ext/ebb_ffi.c

Constant Summary collapse

BASE_ENV =
{
  'SERVER_NAME' => '0.0.0.0',
  'SCRIPT_NAME' => '',
  'SERVER_SOFTWARE' => Ebb::VERSION_STRING,
  'SERVER_PROTOCOL' => 'HTTP/1.1',
  'rack.version' => [0, 1],
  'rack.errors' => STDERR,
  'rack.multiprocess' => false,
  'rack.run_once' => false
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#connectionObject

Returns the value of attribute connection.



282
283
284
# File 'lib/ebb.rb', line 282

def connection
  @connection
end

Instance Method Details

#envObject



295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
# File 'lib/ebb.rb', line 295

def env
  @env ||= begin
    env = BASE_ENV.merge(@env_ffi)
    env.update(
      'rack.input' => self,
      'async.callback' => response,
      'rack.url_scheme' => Ebb.ssl? ? 'https' : 'http'
    )
    env["HTTP_HOST"] ||= BASE_ENV["SERVER_NAME"]
    if env.has_key?('HTTP_CONTENT_LENGTH')
      env['CONTENT_LENGTH'] = env.delete('HTTP_CONTENT_LENGTH')
    end
    if env.has_key?('HTTP_CONTENT_TYPE')
      env['CONTENT_TYPE'] = env.delete('HTTP_CONTENT_TYPE')
    end
    env
  end
end

#keep_alive?Boolean

Returns:

  • (Boolean)


314
315
316
# File 'lib/ebb.rb', line 314

def keep_alive?
  FFI::request_should_keep_alive?(self)
end

#read(want = 1024) ⇒ Object



325
326
327
# File 'lib/ebb.rb', line 325

def read(want = 1024)
  FFI::request_read(self, want)
end

#responseObject



318
319
320
321
322
323
# File 'lib/ebb.rb', line 318

def response
  @response ||= begin
    last = !keep_alive? # this is the last response if the request isnt keep-alive
    Response.new(@connection, last)
  end
end