Skip to content

Commit 1e70a6a

Browse files
committed
Cleanup
1 parent f225061 commit 1e70a6a

6 files changed

Lines changed: 10 additions & 64 deletions

File tree

lib/syntropy/app.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ def file_watcher_loop
497497
@module_loader.invalidate_fn(fn)
498498
debounce_file_change
499499
}
500-
500+
501501

502502

503503
# Syntropy.file_watch(@machine, @root_dir, period: period) do |event, fn|

lib/syntropy/connection.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# frozen_string_literal: true
22

3-
require 'stringio'
43
require 'syntropy/errors'
54

65
module Syntropy
@@ -117,7 +116,7 @@ def get_body(req)
117116
nil
118117
end
119118

120-
def get_body_chunk(req, _buffered_only = false)
119+
def get_body_chunk(req)
121120
headers = req.headers
122121
content_length = headers['content-length']
123122
if content_length

lib/syntropy/request.rb

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class Request
1010
include RequestInfoMethods
1111
include RequestValidationMethods
1212
include ResponseMethods
13-
13+
1414
extend RequestInfoClassMethods
1515

1616
attr_reader :headers, :adapter, :start_stamp, :route_params
@@ -30,45 +30,17 @@ def ctx
3030
@ctx ||= {}
3131
end
3232

33-
def buffer_body_chunk(chunk)
34-
@buffered_body_chunks ||= []
35-
@buffered_body_chunks << chunk
36-
end
37-
38-
def next_chunk(buffered_only = false)
39-
if @buffered_body_chunks
40-
chunk = @buffered_body_chunks.shift
41-
@buffered_body_chunks = nil if @buffered_body_chunks.empty?
42-
return chunk
43-
elsif buffered_only
44-
return nil
45-
end
46-
47-
@adapter.get_body_chunk(self, buffered_only)
33+
def next_chunk
34+
@adapter.get_body_chunk(self)
4835
end
4936

5037
def each_chunk
51-
if @buffered_body_chunks
52-
while (chunk = @buffered_body_chunks.shift)
53-
yield chunk
54-
end
55-
@buffered_body_chunks = nil
56-
end
57-
while (chunk = @adapter.get_body_chunk(self, false))
38+
while (chunk = @adapter.get_body_chunk(self))
5839
yield chunk
5940
end
6041
end
6142

6243
def read
63-
if @buffered_body_chunks
64-
body = @buffered_body_chunks.join
65-
if !complete?
66-
rest = @adapter.get_body(self)
67-
body << rest if rest
68-
end
69-
@buffered_body_chunks = nil
70-
return body
71-
end
7244
@adapter.get_body(self)
7345
end
7446
alias_method :body, :read

lib/syntropy/request/mock_adapter.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module Syntropy
44
class MockAdapter
55
attr_reader :response_body, :response_headers, :calls
66

7-
def get_body_chunk(_req, _buffered_only)
7+
def get_body_chunk(_req)
88
@request_body_chunks.shift
99
end
1010

lib/syntropy/request/response.rb

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
# frozen_string_literal: true
22

33
require 'time'
4-
require 'zlib'
5-
require 'stringio'
64
require 'digest/sha1'
75

86
require_relative './status'
@@ -94,29 +92,6 @@ def serve_io(io, opts)
9492
respond(io.read, opts[:headers] || {})
9593
end
9694

97-
def serve_io_deflate(io, opts)
98-
deflate = Zlib::Deflate.new
99-
headers = opts[:headers].merge(
100-
'content-encoding' => 'deflate',
101-
'vary' => 'Accept-Encoding'
102-
)
103-
104-
respond(deflate.deflate(io.read, Zlib::FINISH), headers)
105-
end
106-
107-
def serve_io_gzip(io, opts)
108-
buf = StringIO.new
109-
z = Zlib::GzipWriter.new(buf)
110-
z << io.read
111-
z.flush
112-
z.close
113-
headers = opts[:headers].merge(
114-
'content-encoding' => 'gzip',
115-
'vary' => 'Accept-Encoding'
116-
)
117-
respond(buf.string, headers)
118-
end
119-
12095
def respond_with_static_file(path, etag, last_modified, opts)
12196
cache_headers = (etag || last_modified) ? {
12297
'etag' => etag,

test/test_connection.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ def test_set_cookie_single
614614
response = read_client_side(65536)
615615
expected = "HTTP/1.1 200\r\nTransfer-Encoding: chunked\r\nSet-Cookie: foo=bar; HttpOnly\r\n\r\n3\r\nfoo\r\n0\r\n\r\n"
616616
assert_equal expected, response
617-
617+
618618
end
619619

620620
def test_set_cookie_multi1
@@ -628,7 +628,7 @@ def test_set_cookie_multi1
628628
response = read_client_side(65536)
629629
expected = "HTTP/1.1 200\r\nTransfer-Encoding: chunked\r\nSet-Cookie: foo=bar; HttpOnly\r\nSet-Cookie: bar=baz\r\n\r\n3\r\nfoo\r\n0\r\n\r\n"
630630
assert_equal expected, response
631-
631+
632632
end
633633

634634
def test_set_cookie_multi2
@@ -644,6 +644,6 @@ def test_set_cookie_multi2
644644
response = read_client_side(65536)
645645
expected = "HTTP/1.1 200\r\nTransfer-Encoding: chunked\r\nSet-Cookie: a=1\r\nSet-Cookie: b=2\r\nSet-Cookie: c=3\r\nSet-Cookie: d=4\r\nSet-Cookie: e=5\r\n\r\n3\r\nfoo\r\n0\r\n\r\n"
646646
assert_equal expected, response
647-
647+
648648
end
649649
end

0 commit comments

Comments
 (0)