Skip to content

Commit 08fd912

Browse files
committed
fix: allow multipart/form-data boundary to end with a newline
The RFC 7578 spec for multipart/form-data requests does not require the body of a request to end with a CRLF, only that each section begins with a CRLF. While many clients implement multipart requests with the trailing CRLF, the implementation for fetch in Node.js version 22 and below does not. This caused my a good number of hours debugging! It does turn out that in September 2024 the Node.js fetch implementation added the CRLF (nodejs/undici#3625), though this hasn't made it to a Node.js release yet. This change allows the boundary to end with a newline or not, as long as the boundary is followed by the end of the request body.
1 parent e7a2005 commit 08fd912

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/backend/base/langflow/main.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,12 @@ async def check_boundary(request: Request, call_next):
184184
body = await request.body()
185185

186186
boundary_start = f"--{boundary}".encode()
187+
# The multipart/form-data spec doesn't require a newline after the boundary, however many clients do
188+
# implement it that way
187189
boundary_end = f"--{boundary}--\r\n".encode()
190+
boundary_end_no_newline = f"--{boundary}--".encode()
188191

189-
if not body.startswith(boundary_start) or not body.endswith(boundary_end):
192+
if not body.startswith(boundary_start) or not body.endswith((boundary_end, boundary_end_no_newline)):
190193
return JSONResponse(
191194
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
192195
content={"detail": "Invalid multipart formatting"},

0 commit comments

Comments
 (0)