tep 0.11.8 → 0.11.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/bin/tep +16 -3
- data/lib/tep/http.rb +3 -3
- data/lib/tep/llm.rb +1 -1
- data/lib/tep/proxy.rb +1 -1
- data/lib/tep/request.rb +5 -5
- data/lib/tep/server.rb +5 -3
- data/lib/tep/server_scheduled.rb +7 -3
- data/lib/tep/shell.rb +10 -2
- data/lib/tep/version.rb +1 -1
- data/lib/tep.rb +4 -4
- data/test/test_boot_seed_stdin.rb +29 -0
- data/test/test_ext_cache.rb +81 -0
- data/test/test_http.rb +14 -0
- data/test/test_response.rb +31 -0
- data/test/test_server_scheduled.rb +38 -0
- metadata +3 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ab07017a55b832e36f074079ebb1b1f84cb7b7fb7223bf099b05649f876f6762
|
|
4
|
+
data.tar.gz: 98a0328f60412b5a65859ca2a17856992775c7c9e33ea57efa595b67db6f8444
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 05bc8d5707d6a2a838cb3e2a845d6ef3be3fb11ebb6a66ff72f9ff5e5bb06fa2d135714368a8b8af4caf673b1b6a4e21afbd6d5252196bdebef4bcc616db574f
|
|
7
|
+
data.tar.gz: d2d77d39aa8b589a5617b55c32197d43100b3291f028139b404eef99d8edcf00ade30e521294c61d1cf03806385605470b974b0b5302e030a98bc35095d63773
|
data/bin/tep
CHANGED
|
@@ -2060,13 +2060,26 @@ def resolve_ext_o(entry, entries, env_var)
|
|
|
2060
2060
|
fatal("ext '#{entry["name"]}' needs #{missing} — install its -dev headers")
|
|
2061
2061
|
end
|
|
2062
2062
|
|
|
2063
|
+
# The cached object is keyed by what it was built from: the source
|
|
2064
|
+
# bytes and the compile flags. The directory used to be the checkout's
|
|
2065
|
+
# basename alone with an mtime check, so two trees with the same name
|
|
2066
|
+
# (a dev checkout and an app's vendored copy are both `tep`) shared a
|
|
2067
|
+
# slot, and whichever compiled last won as long as its object was newer
|
|
2068
|
+
# than the other tree's source. The result linked cleanly and returned
|
|
2069
|
+
# wrong data at run time.
|
|
2070
|
+
require "digest"
|
|
2071
|
+
key = Digest::SHA256.hexdigest(File.binread(src) + "\0" + cflags.join("\0"))[0, 16]
|
|
2063
2072
|
cache = File.join(ENV["HOME"] || Dir.tmpdir, ".cache", "tep", "ext", File.basename(REPO_ROOT))
|
|
2064
2073
|
FileUtils.mkdir_p(cache)
|
|
2065
|
-
out = File.join(cache, File.basename(prebuilt))
|
|
2066
|
-
return out if File.exist?(out)
|
|
2074
|
+
out = File.join(cache, File.basename(prebuilt, ".o") + "-" + key + ".o")
|
|
2075
|
+
return out if File.exist?(out)
|
|
2067
2076
|
|
|
2068
2077
|
warn "[tep] building ext '#{entry["name"]}' on demand (#{entry["source"]})"
|
|
2069
|
-
|
|
2078
|
+
# Compile to a private name and rename, so a concurrent build never
|
|
2079
|
+
# links a half-written object.
|
|
2080
|
+
tmp = out + ".#{Process.pid}.tmp"
|
|
2081
|
+
if system(ENV.fetch("CC", "cc"), *cflags, "-c", src, "-o", tmp) && File.exist?(tmp)
|
|
2082
|
+
File.rename(tmp, out)
|
|
2070
2083
|
out
|
|
2071
2084
|
elsif entry["optional"]
|
|
2072
2085
|
warn "[tep] optional ext '#{entry["name"]}' failed to build — disabling"
|
data/lib/tep/http.rb
CHANGED
|
@@ -183,7 +183,7 @@ module Tep
|
|
|
183
183
|
head = head + k + ": " + v + "\r\n"
|
|
184
184
|
end
|
|
185
185
|
if body.length > 0
|
|
186
|
-
head = head + "Content-Length: " + body.
|
|
186
|
+
head = head + "Content-Length: " + body.bytesize.to_s + "\r\n"
|
|
187
187
|
end
|
|
188
188
|
head = head + "\r\n"
|
|
189
189
|
if Sock.sphttp_write_str(fd, head) < 0
|
|
@@ -229,7 +229,7 @@ module Tep
|
|
|
229
229
|
head = head + k + ": " + v + "\r\n"
|
|
230
230
|
end
|
|
231
231
|
if body.length > 0
|
|
232
|
-
head = head + "Content-Length: " + body.
|
|
232
|
+
head = head + "Content-Length: " + body.bytesize.to_s + "\r\n"
|
|
233
233
|
end
|
|
234
234
|
head = head + "\r\n"
|
|
235
235
|
|
|
@@ -335,7 +335,7 @@ module Tep
|
|
|
335
335
|
head = head + k + ": " + v + "\r\n"
|
|
336
336
|
end
|
|
337
337
|
if body.length > 0
|
|
338
|
-
head = head + "Content-Length: " + body.
|
|
338
|
+
head = head + "Content-Length: " + body.bytesize.to_s + "\r\n"
|
|
339
339
|
end
|
|
340
340
|
head = head + "\r\n"
|
|
341
341
|
|
data/lib/tep/llm.rb
CHANGED
|
@@ -111,7 +111,7 @@ module Tep
|
|
|
111
111
|
if @api_key.length > 0
|
|
112
112
|
head = head + "Authorization: Bearer " + @api_key + "\r\n"
|
|
113
113
|
end
|
|
114
|
-
head = head + "Content-Length: " + body.
|
|
114
|
+
head = head + "Content-Length: " + body.bytesize.to_s + "\r\n" +
|
|
115
115
|
"Connection: close\r\n\r\n" + body
|
|
116
116
|
if Sock.sphttp_write_str(fd, head) < 0
|
|
117
117
|
Sock.sphttp_close(fd)
|
data/lib/tep/proxy.rb
CHANGED
|
@@ -450,7 +450,7 @@ module Tep
|
|
|
450
450
|
head = head + k + ": " + v + "\r\n"
|
|
451
451
|
end
|
|
452
452
|
if ureq.body.length > 0
|
|
453
|
-
head = head + "Content-Length: " + ureq.body.
|
|
453
|
+
head = head + "Content-Length: " + ureq.body.bytesize.to_s + "\r\n"
|
|
454
454
|
end
|
|
455
455
|
head = head + "\r\n"
|
|
456
456
|
if Sock.sphttp_write_str(fd, head) < 0
|
data/lib/tep/request.rb
CHANGED
|
@@ -137,7 +137,7 @@ module Tep
|
|
|
137
137
|
# want to consume it directly.
|
|
138
138
|
def consume_body(client_fd)
|
|
139
139
|
cl = content_length
|
|
140
|
-
already = @raw_body.
|
|
140
|
+
already = @raw_body.bytesize
|
|
141
141
|
if cl > already
|
|
142
142
|
rest = Sock.sphttp_drain_body(client_fd, cl - already)
|
|
143
143
|
@raw_body = @raw_body + rest
|
|
@@ -153,18 +153,18 @@ module Tep
|
|
|
153
153
|
# request but never sent the body gets dropped instead of
|
|
154
154
|
# hanging the fiber forever.
|
|
155
155
|
#
|
|
156
|
-
# Returns @raw_body.
|
|
156
|
+
# Returns @raw_body.bytesize after the drain. Body parsing
|
|
157
157
|
# (form / multipart -> @params) happens at the end via
|
|
158
158
|
# parse_form_body, same shape as consume_body.
|
|
159
159
|
def consume_body_via_scheduler(client_fd)
|
|
160
160
|
cl = content_length
|
|
161
|
-
while @raw_body.
|
|
161
|
+
while @raw_body.bytesize < cl
|
|
162
162
|
ready = Tep::Scheduler.io_wait(client_fd, Tep::Scheduler::READ, 5)
|
|
163
163
|
if ready == 0
|
|
164
164
|
break # timeout -- client never finished sending
|
|
165
165
|
end
|
|
166
|
-
chunk = Sock.sphttp_recv_some(client_fd, cl - @raw_body.
|
|
167
|
-
if chunk.
|
|
166
|
+
chunk = Sock.sphttp_recv_some(client_fd, cl - @raw_body.bytesize)
|
|
167
|
+
if chunk.bytesize == 0
|
|
168
168
|
# Over TLS an empty read can be a partial record (SSL_read
|
|
169
169
|
# WANT_READ/WANT_WRITE) rather than a peer close -- re-park on
|
|
170
170
|
# the indicated direction and retry instead of truncating the
|
data/lib/tep/server.rb
CHANGED
|
@@ -238,7 +238,9 @@ module Tep
|
|
|
238
238
|
if !res.headers.key?("Content-Type") && res.status != 204 && res.status != 304
|
|
239
239
|
res.headers["Content-Type"] = "text/html; charset=utf-8"
|
|
240
240
|
end
|
|
241
|
-
|
|
241
|
+
# bytesize, not length: a multibyte body would otherwise announce
|
|
242
|
+
# fewer bytes than it sends and desync keep-alive clients.
|
|
243
|
+
res.headers["Content-Length"] = res.body.bytesize.to_s
|
|
242
244
|
if keep_alive
|
|
243
245
|
res.headers["Connection"] = "keep-alive"
|
|
244
246
|
else
|
|
@@ -247,7 +249,7 @@ module Tep
|
|
|
247
249
|
|
|
248
250
|
head = build_head(req, res)
|
|
249
251
|
Sock.sphttp_write_str(client, head)
|
|
250
|
-
if res.body.
|
|
252
|
+
if res.body.bytesize > 0
|
|
251
253
|
Sock.sphttp_write_str(client, res.body)
|
|
252
254
|
end
|
|
253
255
|
end
|
|
@@ -272,7 +274,7 @@ module Tep
|
|
|
272
274
|
body = "<h1>" + status.to_s + " " + reason + "</h1><p>" + msg + "</p>\n"
|
|
273
275
|
head = "HTTP/1.0 " + status.to_s + " " + reason + "\r\n" +
|
|
274
276
|
"Content-Type: text/html; charset=utf-8\r\n" +
|
|
275
|
-
"Content-Length: " + body.
|
|
277
|
+
"Content-Length: " + body.bytesize.to_s + "\r\n" +
|
|
276
278
|
"Connection: close\r\n\r\n"
|
|
277
279
|
Sock.sphttp_write_str(client, head + body)
|
|
278
280
|
end
|
data/lib/tep/server_scheduled.rb
CHANGED
|
@@ -356,9 +356,13 @@ module Tep
|
|
|
356
356
|
Sock.sphttp_write_str(client, head)
|
|
357
357
|
Sock.sphttp_sendfile(client, res.file_path)
|
|
358
358
|
else
|
|
359
|
-
|
|
359
|
+
# bytesize, not length: `length` counts characters, so a
|
|
360
|
+
# multibyte (UTF-8) body would announce fewer bytes than it
|
|
361
|
+
# sends. A keep-alive client then reads the surplus as the
|
|
362
|
+
# start of the next response and drops the connection.
|
|
363
|
+
head = head + "Content-Length: " + res.body.bytesize.to_s + "\r\n\r\n"
|
|
360
364
|
Sock.sphttp_write_str(client, head)
|
|
361
|
-
if res.body.
|
|
365
|
+
if res.body.bytesize > 0
|
|
362
366
|
Sock.sphttp_write_str(client, res.body)
|
|
363
367
|
end
|
|
364
368
|
end
|
|
@@ -368,7 +372,7 @@ module Tep
|
|
|
368
372
|
def self.send_simple(client, status, msg)
|
|
369
373
|
reason = Tep.reason(status)
|
|
370
374
|
head = "HTTP/1.0 " + status.to_s + " " + reason + "\r\n" +
|
|
371
|
-
"Content-Length: " + msg.
|
|
375
|
+
"Content-Length: " + msg.bytesize.to_s + "\r\n" +
|
|
372
376
|
"Connection: close\r\n\r\n" + msg
|
|
373
377
|
Sock.sphttp_write_str(client, head)
|
|
374
378
|
0
|
data/lib/tep/shell.rb
CHANGED
|
@@ -41,12 +41,20 @@ module Tep
|
|
|
41
41
|
# silently return ""); we rescue here to preserve this helper's
|
|
42
42
|
# never-raise contract -- a handler reading /proc should get "" for
|
|
43
43
|
# an absent file, not a 502'd worker.
|
|
44
|
+
#
|
|
45
|
+
# The result goes through a local rather than being the begin/rescue
|
|
46
|
+
# expression's own value: at spinel 2026.10.25 a method whose value is
|
|
47
|
+
# `begin File.read(path) rescue "" end` hands back its ARGUMENT when
|
|
48
|
+
# the caller pushes the result onto a String array (broke
|
|
49
|
+
# Tep::Parallel#map_processes).
|
|
44
50
|
def self.read(path)
|
|
51
|
+
out = ""
|
|
45
52
|
begin
|
|
46
|
-
File.read(path)
|
|
53
|
+
out = File.read(path)
|
|
47
54
|
rescue => e
|
|
48
|
-
""
|
|
55
|
+
out = ""
|
|
49
56
|
end
|
|
57
|
+
out
|
|
50
58
|
end
|
|
51
59
|
|
|
52
60
|
# Bounded read: slice after the fact. The cap is mostly a
|
data/lib/tep/version.rb
CHANGED
data/lib/tep.rb
CHANGED
|
@@ -255,7 +255,7 @@ module Tep
|
|
|
255
255
|
_tep_seed_sess.get("a")
|
|
256
256
|
_tep_seed_sess.has?("a")
|
|
257
257
|
_tep_seed_res.start_stream(Streamer.new)
|
|
258
|
-
_tep_seed_stream = Stream.new(
|
|
258
|
+
_tep_seed_stream = Stream.new(-1)
|
|
259
259
|
_tep_seed_res.streamer.pump(_tep_seed_stream)
|
|
260
260
|
_tep_seed_stream.write("") # pin the parameter type to :str
|
|
261
261
|
Tep.h("") # pin Tep.h(s)'s param to :str
|
|
@@ -265,7 +265,7 @@ module Tep
|
|
|
265
265
|
Tep::Multipart.parse("", "")
|
|
266
266
|
Tep::Multipart.extract_boundary("")
|
|
267
267
|
Tep::Multipart.extract_field_name("")
|
|
268
|
-
_tep_seed_res.start_websocket("", Tep::WebSocket::Driver.new(
|
|
268
|
+
_tep_seed_res.start_websocket("", Tep::WebSocket::Driver.new(-1))
|
|
269
269
|
|
|
270
270
|
# AuthOAuth2 type-seeding. Every public cmeth needs at least one
|
|
271
271
|
# top-level call so spinel locks the param C types in compile
|
|
@@ -782,7 +782,7 @@ module Tep
|
|
|
782
782
|
_tep_seed_llm_state.acc = ""
|
|
783
783
|
_tep_seed_llm_state.leftover = ""
|
|
784
784
|
_tep_seed_llm_state.done = false
|
|
785
|
-
_tep_seed_llm_stream = Tep::Stream.new(
|
|
785
|
+
_tep_seed_llm_stream = Tep::Stream.new(-1)
|
|
786
786
|
Tep::Llm.consume_sse_events(_tep_seed_llm_stream, _tep_seed_llm_state)
|
|
787
787
|
Tep::Llm.dechunk_consume("")
|
|
788
788
|
Tep::Llm.dechunk_leftover("")
|
|
@@ -822,7 +822,7 @@ module Tep
|
|
|
822
822
|
_tep_seed_ws_event.code = 0
|
|
823
823
|
_tep_seed_ws_event.reason = ""
|
|
824
824
|
_tep_seed_ws_handler.handle_event(_tep_seed_ws_event)
|
|
825
|
-
_tep_seed_ws_drv = Tep::WebSocket::Driver.new(
|
|
825
|
+
_tep_seed_ws_drv = Tep::WebSocket::Driver.new(-1)
|
|
826
826
|
_tep_seed_ws_drv.set_max_frame_size(0)
|
|
827
827
|
_tep_seed_ws_drv.set_subprotocol("")
|
|
828
828
|
_tep_seed_ws_drv.set_on_open(_tep_seed_ws_handler)
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
require_relative "helper"
|
|
2
|
+
require "socket"
|
|
3
|
+
|
|
4
|
+
# The boot-time type seeds used to build a Stream and two WebSocket
|
|
5
|
+
# drivers on descriptor 0 and write test frames to it. With a socket on
|
|
6
|
+
# stdin those 54 bytes reached the peer, and once an unread socket
|
|
7
|
+
# filled, a later start blocked before serving (#283).
|
|
8
|
+
class TestBootSeedStdin < Minitest::Test
|
|
9
|
+
def test_start_writes_nothing_to_a_socket_on_stdin
|
|
10
|
+
tmp = Dir.mktmpdir("tep-seed-stdin")
|
|
11
|
+
src = File.join(tmp, "app.rb")
|
|
12
|
+
File.write(src, "require \"sinatra\"\nget \"/\" do\n \"hi\"\nend\n")
|
|
13
|
+
bin = File.join(tmp, "app")
|
|
14
|
+
TepHarness.build_with_retry("#{TepHarness::TEP_BIN} build #{src} -o #{bin}", "tep build seed stdin app")
|
|
15
|
+
ours, theirs = UNIXSocket.pair
|
|
16
|
+
port = TepHarness.next_port
|
|
17
|
+
pid = Process.spawn(bin, "-p", port.to_s, "-q", in: theirs,
|
|
18
|
+
out: File.join(tmp, "app.log"), err: [:child, :out], pgroup: true)
|
|
19
|
+
theirs.close
|
|
20
|
+
TepHarness.wait_for_port(port, tmp: tmp, pid: pid)
|
|
21
|
+
TepHarness.reap(pid)
|
|
22
|
+
pid = nil
|
|
23
|
+
assert_equal "", ours.read, "the app wrote to its stdin socket at start"
|
|
24
|
+
ensure
|
|
25
|
+
TepHarness.reap(pid) if pid
|
|
26
|
+
ours&.close
|
|
27
|
+
FileUtils.rm_rf(tmp) if tmp
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
require_relative "helper"
|
|
2
|
+
require "net/http"
|
|
3
|
+
|
|
4
|
+
# `tep build` compiles the optional native helpers (sqlite, pg) on demand
|
|
5
|
+
# into ~/.cache/tep/ext/<checkout basename>/. The slot used to be keyed by
|
|
6
|
+
# that basename plus an mtime check, so another tree with the same name
|
|
7
|
+
# could leave an object there that this tree then linked: it built fine
|
|
8
|
+
# and SQLite queries returned nothing. The object is now keyed by the
|
|
9
|
+
# source bytes and compile flags.
|
|
10
|
+
class TestExtCache < Minitest::Test
|
|
11
|
+
REPO = File.expand_path("..", __dir__)
|
|
12
|
+
APP = <<~'RB'
|
|
13
|
+
require "sinatra"
|
|
14
|
+
get "/count" do
|
|
15
|
+
db = Tep::SQLite.new
|
|
16
|
+
db.open(ENV.fetch("DB_PATH", "/tmp/unset.db"))
|
|
17
|
+
db.exec("CREATE TABLE n (id INTEGER PRIMARY KEY, b TEXT)")
|
|
18
|
+
db.exec("INSERT INTO n (b) VALUES ('x')")
|
|
19
|
+
db.exec("INSERT INTO n (b) VALUES ('y')")
|
|
20
|
+
"count=" + db.first_int("SELECT COUNT(*) FROM n WHERE id > ?", "0").to_s
|
|
21
|
+
end
|
|
22
|
+
RB
|
|
23
|
+
|
|
24
|
+
def setup
|
|
25
|
+
skip "TEP_SQLITE_O set; the cache is bypassed" unless ENV["TEP_SQLITE_O"].to_s.empty?
|
|
26
|
+
@tmp = Dir.mktmpdir("tep-extcache")
|
|
27
|
+
@home = File.join(@tmp, "home")
|
|
28
|
+
# A dev checkout has `make helper`s prebuilt lib/tep/tep_sqlite.o, which
|
|
29
|
+
# bypasses the cache. Build from a copy without it, as an installed gem
|
|
30
|
+
# or an app-vendored tep does.
|
|
31
|
+
@tree = File.join(@tmp, "tep")
|
|
32
|
+
FileUtils.mkdir_p(@tree)
|
|
33
|
+
FileUtils.cp_r([File.join(REPO, "bin"), File.join(REPO, "lib"), File.join(REPO, "spinel-ext.json")], @tree)
|
|
34
|
+
FileUtils.rm_f(Dir[File.join(@tree, "lib", "tep", "tep_{sqlite,pg}.o")])
|
|
35
|
+
@slot = File.join(@home, ".cache", "tep", "ext", "tep")
|
|
36
|
+
FileUtils.mkdir_p(@slot)
|
|
37
|
+
@src = File.join(@tmp, "app.rb")
|
|
38
|
+
File.write(@src, APP)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def teardown
|
|
42
|
+
TepHarness.reap(@pid) if @pid
|
|
43
|
+
FileUtils.rm_rf(@tmp) if @tmp
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def build(bin)
|
|
47
|
+
out = `HOME=#{@home} #{File.join(@tree, "bin", "tep")} build #{@src} -o #{bin} 2>&1`
|
|
48
|
+
assert $?.success?, "tep build failed:\n#{out}"
|
|
49
|
+
out
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def test_foreign_object_in_the_slot_is_not_linked
|
|
53
|
+
# What another same-named tree would have left behind under the old
|
|
54
|
+
# scheme: an object at the unkeyed name, newer than our source. This
|
|
55
|
+
# one defines nothing, so linking it cannot produce a working binary.
|
|
56
|
+
decoy_c = File.join(@tmp, "decoy.c")
|
|
57
|
+
File.write(decoy_c, "int tep_decoy_unused;\n")
|
|
58
|
+
decoy = File.join(@slot, "tep_sqlite.o")
|
|
59
|
+
assert system("cc", "-c", decoy_c, "-o", decoy)
|
|
60
|
+
File.utime(Time.now + 3600, Time.now + 3600, decoy)
|
|
61
|
+
|
|
62
|
+
bin = File.join(@tmp, "app")
|
|
63
|
+
build(bin)
|
|
64
|
+
|
|
65
|
+
keyed = Dir[File.join(@slot, "tep_sqlite-*.o")]
|
|
66
|
+
assert_equal 1, keyed.length, "expected one content-keyed object, got #{Dir[File.join(@slot, '*')].inspect}"
|
|
67
|
+
assert_match(/tep_sqlite-\h{16}\.o\z/, keyed[0])
|
|
68
|
+
|
|
69
|
+
@port = TepHarness.next_port
|
|
70
|
+
@pid = Process.spawn({ "DB_PATH" => File.join(@tmp, "t.db") }, bin, "-p", @port.to_s, "-q",
|
|
71
|
+
out: File.join(@tmp, "app.log"), err: [:child, :out], pgroup: true)
|
|
72
|
+
TepHarness.wait_for_port(@port, tmp: @tmp, pid: @pid)
|
|
73
|
+
assert_equal "count=2", Net::HTTP.get(URI("http://127.0.0.1:#{@port}/count"))
|
|
74
|
+
|
|
75
|
+
# A second build reuses the keyed object.
|
|
76
|
+
before = File.mtime(keyed[0])
|
|
77
|
+
out = build(File.join(@tmp, "app2"))
|
|
78
|
+
refute_match(/building ext 'sqlite'/, out)
|
|
79
|
+
assert_equal before, File.mtime(keyed[0])
|
|
80
|
+
end
|
|
81
|
+
end
|
data/test/test_http.rb
CHANGED
|
@@ -68,6 +68,14 @@ class TestHttp < TepTest
|
|
|
68
68
|
"status=" + r.status.to_s + " body=" + r.body
|
|
69
69
|
end
|
|
70
70
|
|
|
71
|
+
# POST with a multibyte body: Content-Length must count bytes or the
|
|
72
|
+
# target reads a truncated body.
|
|
73
|
+
get '/post_echo_utf8/:port' do
|
|
74
|
+
c = Tep::Http.new("http://127.0.0.1:" + params[:port])
|
|
75
|
+
r = c.do_post("/echo_body", "héllo wörld — ü")
|
|
76
|
+
"status=" + r.status.to_s + " body=" + r.body
|
|
77
|
+
end
|
|
78
|
+
|
|
71
79
|
# Non-2xx round trip.
|
|
72
80
|
get '/teapot_from/:port' do
|
|
73
81
|
r = Tep::Http.get("http://127.0.0.1:" + params[:port] + "/teapot")
|
|
@@ -113,6 +121,12 @@ class TestHttp < TepTest
|
|
|
113
121
|
assert_equal "status=200 body=round trip body", res.body
|
|
114
122
|
end
|
|
115
123
|
|
|
124
|
+
def test_multibyte_post_body_round_trips
|
|
125
|
+
res = get("/post_echo_utf8/#{@port}")
|
|
126
|
+
assert_equal "200", res.code
|
|
127
|
+
assert_equal "status=200 body=héllo wörld — ü", res.body.force_encoding("UTF-8")
|
|
128
|
+
end
|
|
129
|
+
|
|
116
130
|
def test_non_2xx_status_propagates
|
|
117
131
|
res = get("/teapot_from/#{@port}")
|
|
118
132
|
assert_equal "200", res.code
|
data/test/test_response.rb
CHANGED
|
@@ -52,6 +52,14 @@ class TestResponse < TepTest
|
|
|
52
52
|
get '/halt-bare' do
|
|
53
53
|
halt 418
|
|
54
54
|
end
|
|
55
|
+
|
|
56
|
+
get '/utf8' do
|
|
57
|
+
"héllo wörld — ü"
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
post '/echo_body' do
|
|
61
|
+
request.body
|
|
62
|
+
end
|
|
55
63
|
RB
|
|
56
64
|
|
|
57
65
|
def test_default_200
|
|
@@ -120,4 +128,27 @@ class TestResponse < TepTest
|
|
|
120
128
|
res = get("/ok")
|
|
121
129
|
assert_equal "2", res["content-length"]
|
|
122
130
|
end
|
|
131
|
+
|
|
132
|
+
def test_multibyte_content_length_counts_bytes
|
|
133
|
+
res = get("/utf8")
|
|
134
|
+
assert_equal "héllo wörld — ü", res.body.force_encoding("UTF-8")
|
|
135
|
+
assert_equal "héllo wörld — ü".bytesize.to_s, res["content-length"]
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
def test_multibyte_request_body_is_read_in_full_without_stalling
|
|
139
|
+
body = "héllo wörld — ü"
|
|
140
|
+
res = post("/echo_body", body, { "Content-Type" => "text/plain" })
|
|
141
|
+
assert_equal "200", res.code
|
|
142
|
+
assert_equal body, res.body.force_encoding("UTF-8")
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
def test_multibyte_body_keeps_keepalive_stream_in_sync
|
|
146
|
+
Net::HTTP.start("127.0.0.1", @port, read_timeout: 3) do |http|
|
|
147
|
+
r1 = http.get("/utf8")
|
|
148
|
+
r2 = http.get("/ok")
|
|
149
|
+
assert_equal "200", r1.code
|
|
150
|
+
assert_equal "200", r2.code
|
|
151
|
+
assert_equal "ok", r2.body
|
|
152
|
+
end
|
|
153
|
+
end
|
|
123
154
|
end
|
|
@@ -22,6 +22,14 @@ class TestServerScheduled < TepTest
|
|
|
22
22
|
post "/upper" do
|
|
23
23
|
request.body.upcase
|
|
24
24
|
end
|
|
25
|
+
|
|
26
|
+
get "/utf8" do
|
|
27
|
+
"héllo wörld — ü"
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
post "/echo_body" do
|
|
31
|
+
request.body
|
|
32
|
+
end
|
|
25
33
|
RB
|
|
26
34
|
|
|
27
35
|
def test_basic_get_through_scheduler
|
|
@@ -53,4 +61,34 @@ class TestServerScheduled < TepTest
|
|
|
53
61
|
assert_equal "pong", r1.body
|
|
54
62
|
assert_equal "two", r2.body
|
|
55
63
|
end
|
|
64
|
+
|
|
65
|
+
def test_multibyte_body_content_length_counts_bytes
|
|
66
|
+
res = get("/utf8")
|
|
67
|
+
assert_equal "200", res.code
|
|
68
|
+
assert_equal "héllo wörld — ü", res.body.force_encoding("UTF-8")
|
|
69
|
+
assert_equal "héllo wörld — ü".bytesize.to_s, res["content-length"]
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def test_multibyte_request_body_is_read_in_full_without_stalling
|
|
73
|
+
# The client's Content-Length is in bytes; counting the body in
|
|
74
|
+
# characters made the server wait for bytes that never come (5s
|
|
75
|
+
# io_wait timeout) before answering.
|
|
76
|
+
body = "héllo wörld — ü"
|
|
77
|
+
res = post("/echo_body", body, { "Content-Type" => "text/plain" })
|
|
78
|
+
assert_equal "200", res.code
|
|
79
|
+
assert_equal body, res.body.force_encoding("UTF-8")
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def test_multibyte_body_keeps_keepalive_stream_in_sync
|
|
83
|
+
# One persistent connection, a multibyte body first. If Content-Length
|
|
84
|
+
# is counted in characters the body's trailing bytes spill into the
|
|
85
|
+
# next response's status line and the client sees a corrupt stream.
|
|
86
|
+
Net::HTTP.start("127.0.0.1", @port, read_timeout: 3) do |http|
|
|
87
|
+
r1 = http.get("/utf8")
|
|
88
|
+
r2 = http.get("/ping")
|
|
89
|
+
assert_equal "200", r1.code
|
|
90
|
+
assert_equal "200", r2.code
|
|
91
|
+
assert_equal "pong", r2.body
|
|
92
|
+
end
|
|
93
|
+
end
|
|
56
94
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: tep
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.11.
|
|
4
|
+
version: 0.11.10
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ori Pekelman
|
|
@@ -183,6 +183,7 @@ files:
|
|
|
183
183
|
- test/test_auth.rb
|
|
184
184
|
- test/test_auth_oauth2.rb
|
|
185
185
|
- test/test_auth_session_cookie.rb
|
|
186
|
+
- test/test_boot_seed_stdin.rb
|
|
186
187
|
- test/test_broadcast.rb
|
|
187
188
|
- test/test_broadcast_pg.rb
|
|
188
189
|
- test/test_cache.rb
|
|
@@ -191,6 +192,7 @@ files:
|
|
|
191
192
|
- test/test_erb.rb
|
|
192
193
|
- test/test_erb_ivars.rb
|
|
193
194
|
- test/test_events.rb
|
|
195
|
+
- test/test_ext_cache.rb
|
|
194
196
|
- test/test_filters.rb
|
|
195
197
|
- test/test_geohash_example.rb
|
|
196
198
|
- test/test_http.rb
|