Class: Swee::Connection
- Defined in:
- lib/swee/connection.rb
Instance Attribute Summary collapse
-
#request ⇒ Object
Returns the value of attribute request.
-
#response ⇒ Object
Returns the value of attribute response.
-
#server ⇒ Object
Returns the value of attribute server.
Instance Method Summary collapse
-
#post_init ⇒ Object
EM 初始化请求.
-
#receive_data(data) ⇒ Object
EM 接收 data.
- #unbind ⇒ Object
Instance Attribute Details
#request ⇒ Object
Returns the value of attribute request.
6 7 8 |
# File 'lib/swee/connection.rb', line 6 def request @request end |
#response ⇒ Object
Returns the value of attribute response.
7 8 9 |
# File 'lib/swee/connection.rb', line 7 def response @response end |
#server ⇒ Object
Returns the value of attribute server.
5 6 7 |
# File 'lib/swee/connection.rb', line 5 def server @server end |
Instance Method Details
#post_init ⇒ Object
EM 初始化请求
10 11 12 13 |
# File 'lib/swee/connection.rb', line 10 def post_init @request = ::Thin::Request.new @response = ::Thin::Response.new end |
#receive_data(data) ⇒ Object
EM 接收 data
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/swee/connection.rb', line 16 def receive_data(data) EM.defer do # thin -> 解析 http @request.parse(data) # 获取 env env = @request.env # 默认 middlewave 先被执行 app = AppExecutor.method(:run) # 代码重新加载 app = Reloader.new(app,Engine.server.logger) if @server.code_reload # rack -> 代码异常 app = Rack::ShowExceptions.new(app) # rack -> 请求日志 app = Rack::CommonLogger.new(app,Engine.server.logger) # rack -> 自动分配 Content-Encoding app = Rack::Deflater.new(app) # 计算 content-length app = ContentLength.new(app) @response.status, @response.headers, @response.body = app.call(env) @response.each do |chunk| send_data chunk end end end |
#unbind ⇒ Object
44 45 46 |
# File 'lib/swee/connection.rb', line 44 def unbind @server.connection_finished(self) end |