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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 84fcc50ae2b18a1a82394d70439a9970283c45f246b1e3efa30d0f9b8be63f4a
4
- data.tar.gz: 691b026a9bbd0f932fdbb2fc0cd753d59125691ce0539c3cb0001170ad43de67
3
+ metadata.gz: c54dbc5bf68ee5357424ba22dcfdb2ef1ebebb2608d5ac9958b51b1f65e0ae8b
4
+ data.tar.gz: a1ac0bc1688aa1fc4db65513685f62d4488189c80374bc83dae8cc77a29751b2
5
5
  SHA512:
6
- metadata.gz: 3725bd9228b2299cf31485c4fd96e10750e44a6a23afb63cd5ac9edc55896f284f7e581f1f94108e8f906a2208755580a8b083942ad4f73812625eca09a4bf97
7
- data.tar.gz: 0b1272174433cf3eb1f2f2b8991156eada221cfb474dc288ab833c387eb8011da759cd09753ae7e64e6e39e7cfcaff40f20f1658404210068b94042aa0063181
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
- if file_body
11
- content_length = response.body.file.size
12
- else
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
- socket.write(head << body_data)
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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Low
4
4
  module Loop
5
- VERSION = '0.8.9'
5
+ VERSION = '0.8.10'
6
6
  end
7
7
  end
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.9
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: 1980-01-02 00:00:00.000000000 Z
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: 4.0.20
165
+ rubygems_version: 3.6.2
166
166
  specification_version: 4
167
167
  summary: An event-driven event loop
168
168
  test_files: []