Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
5 tasks done
cskkx1 opened this issue Oct 9, 2024 · 2 comments
Closed
5 tasks done

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

cskkx1 opened this issue Oct 9, 2024 · 2 comments
Assignees
Labels
🐞 bug Something isn't working

Comments

@cskkx1
Copy link

cskkx1 commented Oct 9, 2024

Self Checks

  • This is only for bug report, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • 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.

Copy link

dosubot bot commented Oct 9, 2024

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.

@laipz8200
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants