Class: Zapp::HTTPContext::Context
- Inherits:
-
Object
- Object
- Zapp::HTTPContext::Context
- Defined in:
- lib/zapp/http_context/context.rb
Overview
Context containing request and response
Instance Attribute Summary collapse
-
#req ⇒ Object
readonly
Returns the value of attribute req.
-
#res ⇒ Object
readonly
Returns the value of attribute res.
-
#socket ⇒ Object
readonly
Returns the value of attribute socket.
Instance Method Summary collapse
- #client_closed? ⇒ Boolean
- #close ⇒ Object
-
#initialize(socket:, logger: Zapp::Logger) ⇒ Context
constructor
A new instance of Context.
Constructor Details
#initialize(socket:, logger: Zapp::Logger) ⇒ Context
Returns a new instance of Context.
12 13 14 15 16 17 18 19 20 |
# File 'lib/zapp/http_context/context.rb', line 12 def initialize(socket:, logger: Zapp::Logger) @socket = socket @req = Zapp::HTTPContext::Request.new(socket: socket) @res = Zapp::HTTPContext::Response.new(socket: socket) rescue Puma::HttpParserError => e res.write(data: "Invalid HTTP request", status: 400, headers: {}) logger.warn("Puma parser error: #{e}") logger.debug("HTTP request raw: #{context.req.raw}") end |
Instance Attribute Details
#req ⇒ Object (readonly)
Returns the value of attribute req.
10 11 12 |
# File 'lib/zapp/http_context/context.rb', line 10 def req @req end |
#res ⇒ Object (readonly)
Returns the value of attribute res.
10 11 12 |
# File 'lib/zapp/http_context/context.rb', line 10 def res @res end |
#socket ⇒ Object (readonly)
Returns the value of attribute socket.
10 11 12 |
# File 'lib/zapp/http_context/context.rb', line 10 def socket @socket end |
Instance Method Details
#client_closed? ⇒ Boolean
26 27 28 |
# File 'lib/zapp/http_context/context.rb', line 26 def client_closed? req.data["HTTP_CONNECTION"] == "close" end |
#close ⇒ Object
22 23 24 |
# File 'lib/zapp/http_context/context.rb', line 22 def close @socket.close end |