Skip to content
This repository has been archived by the owner on Dec 7, 2018. It is now read-only.

add server access from requests #228

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/reel/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion lib/reel/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion lib/reel/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 13 additions & 0 deletions spec/reel/connection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down