diff --git a/lib/reel/connection.rb b/lib/reel/connection.rb index d2eaf2b..2268edd 100644 --- a/lib/reel/connection.rb +++ b/lib/reel/connection.rb @@ -16,13 +16,14 @@ class Connection # Attempt to read this much data BUFFER_SIZE = 16384 - attr_reader :buffer_size + attr_reader :buffer_size, :server - def initialize(socket, buffer_size = nil) + def initialize(socket, buffer_size = nil, server = nil) @attached = true @socket = socket @keepalive = true @buffer_size = buffer_size || BUFFER_SIZE + @server = server @parser = Request::Parser.new(self) @request_fsm = Request::StateMachine.new(@socket) diff --git a/lib/reel/request.rb b/lib/reel/request.rb index 5ec7b79..468b87b 100644 --- a/lib/reel/request.rb +++ b/lib/reel/request.rb @@ -14,7 +14,7 @@ class Request def_delegators :@connection, :remote_addr, :respond def_delegator :@response_writer, :handle_response - attr_reader :body + attr_reader :body, :connection # request_info is a RequestInfo object including the headers and # the url, method and http version. diff --git a/lib/reel/server.rb b/lib/reel/server.rb index 226cd91..7ec02cc 100644 --- a/lib/reel/server.rb +++ b/lib/reel/server.rb @@ -44,7 +44,7 @@ def handle_connection(socket) socket = Reel::Spy.new(socket, @spy) end - connection = Connection.new(socket) + connection = Connection.new(socket, nil, self) begin @callback.call(connection) diff --git a/spec/reel/connection_spec.rb b/spec/reel/connection_spec.rb index da24627..23f65dc 100644 --- a/spec/reel/connection_spec.rb +++ b/spec/reel/connection_spec.rb @@ -338,6 +338,19 @@ def test_chunked_response(request, client) end end + it "allows access to server instance" do + with_socket_pair do |client, peer| + server = Object.new + connection = Reel::Connection.new(peer, nil, server) + example_request = ExampleRequest.new + + client << example_request.to_s + request = connection.request + + expect(request.connection.server).to eq server + end + end + context "#readpartial" do it "streams request bodies" do with_socket_pair do |client, peer|