lowloop 0.8.9 → 0.8.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/responses/response_builder.rb +19 -11
- data/lib/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c54dbc5bf68ee5357424ba22dcfdb2ef1ebebb2608d5ac9958b51b1f65e0ae8b
|
|
4
|
+
data.tar.gz: a1ac0bc1688aa1fc4db65513685f62d4488189c80374bc83dae8cc77a29751b2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0aaac6f932f6d100d24fa5790b1b628af5582a8e452328a596e5e416aa4c09c85853d44948e9fc6059fecd505f5f040efa2b77db213eb93fc9cede90253d325c
|
|
7
|
+
data.tar.gz: 3539918d7bf62a8999ce433d3f4dc8ab2e234fcd3fb325c031d45723e0e702e329838293c3d33965a25d61dd4e35ebc61a0b9db5b981b6d7c9d67b50a34a6006
|
|
@@ -2,21 +2,19 @@
|
|
|
2
2
|
|
|
3
3
|
module Low
|
|
4
4
|
class ResponseBuilder
|
|
5
|
+
# Room for the status line and headers of most responses.
|
|
6
|
+
HEAD_CAPACITY = 1024
|
|
7
|
+
|
|
5
8
|
class << self
|
|
6
9
|
# TODO: Use Async wherever we can where it doesn't have "Task" requirement.
|
|
7
10
|
def respond(socket:, response:, keep_alive: true)
|
|
8
11
|
file_body = response.body.respond_to?(:file)
|
|
12
|
+
chunks = body_chunks(response.body) unless file_body
|
|
13
|
+
content_length = file_body ? response.body.file.size : chunks.sum(&:bytesize)
|
|
9
14
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
# A response can have no body, like a node returning "Status[201]", and "join" reads every chunk of a body.
|
|
14
|
-
body_data = response.body&.join || ''
|
|
15
|
-
content_length = body_data.bytesize
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
# Build the whole head in memory then write once, as every socket write is a syscall.
|
|
19
|
-
head = +''
|
|
15
|
+
# Build the whole response in one string, sized up front so it isn't copied as it grows, then write once, as
|
|
16
|
+
# every socket write is a syscall.
|
|
17
|
+
head = String.new(capacity: HEAD_CAPACITY + (file_body ? 0 : content_length))
|
|
20
18
|
write_status_line(head, response)
|
|
21
19
|
write_response_headers(head, response)
|
|
22
20
|
write_final_headers(head, content_length, keep_alive)
|
|
@@ -25,7 +23,9 @@ module Low
|
|
|
25
23
|
socket.write(head)
|
|
26
24
|
IO.copy_stream(response.body.file, socket)
|
|
27
25
|
else
|
|
28
|
-
|
|
26
|
+
# As bytes, so a body in any encoding can follow headers in any other.
|
|
27
|
+
chunks.each { head.append_as_bytes(it) }
|
|
28
|
+
socket.write(head)
|
|
29
29
|
end
|
|
30
30
|
ensure
|
|
31
31
|
response.body.close if file_body
|
|
@@ -33,6 +33,14 @@ module Low
|
|
|
33
33
|
|
|
34
34
|
private
|
|
35
35
|
|
|
36
|
+
# A buffered body's chunks as they are, rather than joined into a copy. Any other body is read, and a response
|
|
37
|
+
# can have no body, like a node returning "Status[201]".
|
|
38
|
+
def body_chunks(body)
|
|
39
|
+
return body.chunks if body.is_a?(Protocol::HTTP::Body::Buffered)
|
|
40
|
+
|
|
41
|
+
[body&.join].compact
|
|
42
|
+
end
|
|
43
|
+
|
|
36
44
|
def write_status_line(head, response)
|
|
37
45
|
head << "#{response.version} #{response.status}\r\n"
|
|
38
46
|
end
|
data/lib/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: lowloop
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.8.
|
|
4
|
+
version: 0.8.10
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- maedi
|
|
8
8
|
bindir: exe
|
|
9
9
|
cert_chain: []
|
|
10
|
-
date:
|
|
10
|
+
date: 2026-11-23 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
12
|
- !ruby/object:Gem::Dependency
|
|
13
13
|
name: async
|
|
@@ -162,7 +162,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
162
162
|
- !ruby/object:Gem::Version
|
|
163
163
|
version: '0'
|
|
164
164
|
requirements: []
|
|
165
|
-
rubygems_version:
|
|
165
|
+
rubygems_version: 3.6.2
|
|
166
166
|
specification_version: 4
|
|
167
167
|
summary: An event-driven event loop
|
|
168
168
|
test_files: []
|