dify icon indicating copy to clipboard operation
dify copied to clipboard

HTTP Request Post Tool in a workflow using form-data body method Bug

Open cskkx1 opened this issue 1 year ago • 1 comments

Self Checks

  • [X] This is only for bug report, if you would like to ask a question, please head to Discussions.
  • [X] I have searched for existing issues search for existing issues, including closed ones.
  • [X] I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • [X] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • [X] Please do not modify this template :) and fill in all the required fields.

Dify version

Version 0.10.0-beta2

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

Using request post tool in a workflow,using form-data as body.

I found in 0.10.0-beta2 at "api/core/workflow/nodes/http_request/http_executor.py".From 316th line: for key, value in self.data.items(): raw += f"--{boundary}\r\n" raw += f'Content-Disposition: form-data; name="{key}"\r\n\r\n' raw += f"{value}\r\n" I think the '\r' is redundant which makes the boundary format wrong.

✔️ Expected Behavior

post request ok.

❌ Actual Behavior

There was an error parsing the body.Did not find boundary character 117 at index 2.

cskkx1 avatar Oct 09 '24 07:10 cskkx1

The issue you're encountering seems to be related to the use of \r\n in the boundary format of the form-data. The \r character might be causing the boundary to be incorrectly formatted, leading to parsing errors.

In HTTP, boundaries in multipart form-data should be separated by \r\n, but if the implementation or the receiving server expects a different format, it could cause issues. You might want to try removing the \r to see if it resolves the problem:

raw += f"--{boundary}\n"
raw += f'Content-Disposition: form-data; name="{key}"\n\n'
raw += f"{value}\n"

This change removes the \r from the boundary lines. Test this modification to see if it resolves the parsing error.

To continue talking to Dosu, mention @dosu.

dosubot[bot] avatar Oct 09 '24 07:10 dosubot[bot]

CRLF is a delimiter that complies with the HTTP standard. In the next version, we will update the log of the HTTP Node to make it look closer to the raw format defined by the HTTP protocol. It will look something like this:

POST /post HTTP/1.1\r\n
Host: httpbin.org\r\n
Content-Type: multipart/form-data; boundary=----WebKitFormBoundarycrhpuhyjtgmrtegr\r\n
Content-Length: [calculated length]\r\n
\r\n
------WebKitFormBoundarycrhpuhyjtgmrtegr\r\n
Content-Disposition: form-data; name="key1"\r\n
\r\n
value1\r\n
------WebKitFormBoundarycrhpuhyjtgmrtegr\r\n
Content-Disposition: form-data; name="key2"\r\n
\r\n
value2\r\n
------WebKitFormBoundarycrhpuhyjtgmrtegr--\r\n

laipz8200 avatar Oct 16 '24 06:10 laipz8200