mirror of
https://github.com/neuml/txtai.git
synced 2026-10-12 02:19:52 +00:00
Handle ServiceTask responses without a Content-Type or body (#1387)
This commit is contained in:
@@ -85,6 +85,12 @@ workflow:
|
||||
url: http://127.0.0.1:8001/testpost
|
||||
params:
|
||||
|
||||
empty:
|
||||
tasks:
|
||||
- task: service
|
||||
url: http://127.0.0.1:8001/empty
|
||||
params:
|
||||
|
||||
xml:
|
||||
tasks:
|
||||
- task: service
|
||||
@@ -144,6 +150,12 @@ class RequestHandler(BaseHTTPRequestHandler):
|
||||
length = int(self.headers["content-length"])
|
||||
data = json.loads(self.rfile.read(length))
|
||||
|
||||
if self.path.startswith("/empty"):
|
||||
# Respond without a body or content-type
|
||||
self.send_response(204)
|
||||
self.end_headers()
|
||||
return
|
||||
|
||||
response = json.dumps([[y for y in x.split(".") if y] for x in data]).encode("utf-8")
|
||||
|
||||
self.send_response(200)
|
||||
@@ -235,6 +247,16 @@ class TestWorkflow(unittest.TestCase):
|
||||
self.assertEqual(len(results), 1)
|
||||
self.assertEqual(len(results[0]), 2)
|
||||
|
||||
def testServiceEmpty(self):
|
||||
"""
|
||||
Test workflow with ServiceTask POST via API and an empty response
|
||||
"""
|
||||
|
||||
text = "This is a test sentence. And another sentence to split."
|
||||
results = self.client.post("workflow", json={"name": "empty", "elements": [text]}).json()
|
||||
|
||||
self.assertEqual(results, [None])
|
||||
|
||||
def testServiceXml(self):
|
||||
"""
|
||||
Test workflow with ServiceTask GET via API and XML response
|
||||
|
||||
Reference in New Issue
Block a user