Skip to content

Commit

Permalink
Removed body proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
MirkoMignini committed Jan 8, 2016
1 parent 8938527 commit e5d5f29
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 15 deletions.
13 changes: 13 additions & 0 deletions lib/lydia/response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,18 @@ def build(input)
end
finish
end

def finish(&block)
@block = block

if [204, 205, 304].include?(status.to_i)
headers.delete 'Content-Length'
headers.delete 'Content-Type'
close
[status.to_i, header, []]
else
[status.to_i, header, @body]
end
end
end
end
6 changes: 3 additions & 3 deletions spec/middleware_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ def initialize(app)
end

def call(env)
result = @app.call(env)
result[2].body[0] = result[2].body[0].upcase
result
status, headers, body = @app.call(env)
upcased_body = body.map { |chunk| chunk.upcase }
[status, headers, upcased_body]
end
end

Expand Down
24 changes: 12 additions & 12 deletions spec/response_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
expect(result[0]).to eq(200)
expect(result[1]).to include('Content-Type' => 'text/html')
expect(result[1]).to include('Content-Length' => body.length.to_s)
expect(result[2].body).to be_an(Array)
expect(result[2].body[0]).to eq(body)
expect(result[2]).to be_an(Array)
expect(result[2][0]).to eq(body)
end

it 'builds using a fixnum (status)' do
Expand All @@ -51,8 +51,8 @@
expect(result[0]).to eq(200)
expect(result[1]).to include('Content-Type' => 'application/json')
expect(result[1]).to include('Content-Length' => body.to_json.length.to_s)
expect(result[2].body).to be_an(Array)
expect(result[2].body[0]).to eq(body.to_json)
expect(result[2]).to be_an(Array)
expect(result[2][0]).to eq(body.to_json)
end

it 'builds using an array of two (body is array)' do
Expand All @@ -63,8 +63,8 @@
expect(result[0]).to eq(201)
expect(result[1]).to include('Content-Type' => 'text/html')
expect(result[1]).to include('Content-Length' => body[1][0].length.to_s)
expect(result[2].body).to be_an(Array)
expect(result[2].body[0]).to eq(body[1][0])
expect(result[2]).to be_an(Array)
expect(result[2][0]).to eq(body[1][0])
end

it 'builds using an array of two (body is noy an array)' do
Expand All @@ -75,8 +75,8 @@
expect(result[0]).to eq(201)
expect(result[1]).to include('Content-Type' => 'text/html')
expect(result[1]).to include('Content-Length' => body[1].length.to_s)
expect(result[2].body).to be_an(Array)
expect(result[2].body[0]).to eq(body[1])
expect(result[2]).to be_an(Array)
expect(result[2][0]).to eq(body[1])
end

it 'builds using an array of three' do
Expand All @@ -88,8 +88,8 @@
expect(result[1]).to include('Content-Type' => 'text/html')
expect(result[1]).to include('Content-Length' => body[2].length.to_s)
expect(result[1]).to include('Authentication' => '12345')
expect(result[2].body).to be_an(Array)
expect(result[2].body[0]).to eq(body[2])
expect(result[2]).to be_an(Array)
expect(result[2][0]).to eq(body[2])
end

class Stream
Expand All @@ -113,8 +113,8 @@ def each
expect(result[0]).to eq(200)
expect(result[1]).to include('Content-Type' => 'text/html')
expect(result[1]).to include('Content-Length')
expect(result[2].body).to be_an(Array)
expect(result[2].body[0]).to_not be_nil
expect(result[2]).to be_an(Array)
expect(result[2][0]).to_not be_nil
end

end
Expand Down

0 comments on commit e5d5f29

Please sign in to comment.