瀏覽代碼

fix(http): force multipart/form-data even without files(#20322) (#20323)

tags/1.4.2
teawoong Kim 5 月之前
父節點
當前提交
400ae664bb
沒有連結到貢獻者的電子郵件帳戶。

+ 8
- 1
api/core/workflow/nodes/http_request/executor.py 查看文件

files[key].append(file_tuple) files[key].append(file_tuple)


# convert files to list for httpx request # convert files to list for httpx request
# If there are no actual files, we still need to force httpx to use `multipart/form-data`.
# This is achieved by inserting a harmless placeholder file that will be ignored by the server.
if not files:
self.files = [("__multipart_placeholder__", ("", b"", "application/octet-stream"))]
if files: if files:
self.files = [] self.files = []
for key, file_tuples in files.items(): for key, file_tuples in files.items():
raw += f"{k}: {v}\r\n" raw += f"{k}: {v}\r\n"


body_string = "" body_string = ""
if self.files:
# Only log actual files if present.
# '__multipart_placeholder__' is inserted to force multipart encoding but is not a real file.
# This prevents logging meaningless placeholder entries.
if self.files and not all(f[0] == "__multipart_placeholder__" for f in self.files):
for key, (filename, content, mime_type) in self.files: for key, (filename, content, mime_type) in self.files:
body_string += f"--{boundary}\r\n" body_string += f"--{boundary}\r\n"
body_string += f'Content-Disposition: form-data; name="{key}"\r\n\r\n' body_string += f'Content-Disposition: form-data; name="{key}"\r\n\r\n'

+ 3
- 1
api/tests/unit_tests/core/workflow/nodes/http_request/test_http_request_executor.py 查看文件

assert "multipart/form-data" in executor.headers["Content-Type"] assert "multipart/form-data" in executor.headers["Content-Type"]
assert executor.params == [] assert executor.params == []
assert executor.json is None assert executor.json is None
assert executor.files is None
# '__multipart_placeholder__' is expected when no file inputs exist,
# to ensure the request is treated as multipart/form-data by the backend.
assert executor.files == [("__multipart_placeholder__", ("", b"", "application/octet-stream"))]
assert executor.content is None assert executor.content is None


# Check that the form data is correctly loaded in executor.data # Check that the form data is correctly loaded in executor.data

Loading…
取消
儲存