mirror of
https://github.com/Niko1221/Strata.git
synced 2026-11-09 17:36:14 -10:00
serve: /config and /load bodies are marked read, so the close does not wait for the drain (#594)
This commit is contained in:
1 parent
a8497cf157
commit
da170f8ae7
2 files changed
+10
-1
No files matched your search
+2
-1
@@ -3435,6 +3435,7 @@ def make_handler(svc: Service):
|
||||
complete = False
|
||||
finally:
|
||||
self.connection.settimeout(timeout)
|
||||
self.body_read = True # nothing left for the drain to wait for (#594)
|
||||
if not complete:
|
||||
self._json(400, {"error": {"message": "incomplete control request body"}})
|
||||
return complete
|
||||
@@ -3465,7 +3466,7 @@ def make_handler(svc: Service):
|
||||
def _config_post(self):
|
||||
"""#564: change a few documented keys of the run config - JSON from Strata's own page only, as
|
||||
/settings (the key is checked before); every other key of the file stays as it is."""
|
||||
body = self.rfile.read(int(self.headers.get("Content-Length", 0)))
|
||||
body = self._body()
|
||||
if not self._own_page("the run config can be changed"):
|
||||
return
|
||||
if not svc.config_path:
|
||||
|
||||
@@ -3090,6 +3090,14 @@ class AnswerBeforeTheBody(unittest.TestCase):
|
||||
def test_not_the_apps_own_page(self):
|
||||
self.assertEqual(self.status("POST", "/load", {"Origin": "https://example.com"}), "HTTP/1.0 403 Forbidden")
|
||||
|
||||
def test_a_body_a_handler_read_is_not_waited_for(self):
|
||||
"""#594: /config and /load read their body themselves: the close must not wait for the drain's 5 s."""
|
||||
for path in ("/config", "/load", "/unload"):
|
||||
with self.subTest(path=path):
|
||||
t0 = time.monotonic()
|
||||
self.status("POST", path)
|
||||
self.assertLess(time.monotonic() - t0, 1.5) # the status() helper itself pauses 0.5 s
|
||||
|
||||
def test_a_host_the_server_does_not_answer_to(self):
|
||||
self.assertEqual(self.status("POST", "/v1/chat/completions", {"Host": "rebind.example.com"}),
|
||||
"HTTP/1.0 403 Forbidden")
|
||||
|
||||
Reference in new issue
Block a user