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

robyn request body processing problem #954

Open
tqq1994516 opened this issue Aug 28, 2024 · 3 comments · May be fixed by #956
Open

robyn request body processing problem #954

tqq1994516 opened this issue Aug 28, 2024 · 3 comments · May be fixed by #956
Labels
bug Something isn't working

Comments

@tqq1994516
Copy link

Bug Description

1.Improper handling of form information
2.The form contains a file and the form field contains the same field
3.request.json()Method serializes the result of a list field when the string of the list is not the list object,But expected when using orjson.loads(request.body) results
4.The form contains files, and the corresponding fields cannot be obtained, and only the file name and file stream can be obtained

Steps to Reproduce

This is a sample server-side code

from robyn import Robyn, Request

app = Robyn(__file__)

@app.post("/")
async def h(request: Request):
    print(request.headers)
    print(request.form_data)
    print(request.body)
    # print(request.json())
    return "Hello, world!"

app.start(host="0.0.0.0", port=8080)
  1. For question 1, I use the following client code to make a request:
import requests

requests.post(
    'http://127.0.0.1:8080/',
    data={
        "title": "xxxx",
        "field": ['a', 'b', 'c'],
    }
)

I got headers included"content-type": ["application/x-www-form-urlencoded"],But the value I get when I use the request.form_data is{}request.body can obtain the original request value
2. For question 2, I use the following client code to make a request:

import requests

requests.post(
    "http://127.0.0.1:8080/",
    data={
        'title': "11",
        'job_url': '11',
        'build_num': 1,
        'display_env': ['Platform', 'NODE_NAME', "version"],
        'robot_webhook': ["http://aa"],
    },
    files={
        'json': open('.report.json', 'r', encoding='utf-8'),
    }
)

Now form_data I can try to get the value of type dict, but he only has the value of the last element in the list field{'title': '11', 'job_url': '11', 'display_env': 'version', 'robot_webhook': 'http://aa', 'build_num': '1'},request.body contains all the values, but there is no field identifier and cannot be extracted
3. For question 3, I use the following client code to make a request,At the same time, the annotation of the request.json() method on the server side is removed:

import requests

requests.post(
    'http://127.0.0.1:8080/',
    json={
        "title": "xxxx",
        "field": ['a', 'b', 'c'],
    }
)

The resulting list field is a string object containing the contents of the list rather than the list object{'field': '["a","b","c"]', 'title': 'xxxx'}, but the expected result {'title': 'xxxx', 'field': ['a', 'b', 'c']} can be obtained by using orjson.loads(request.body)
4. For question 4, I use the following client code to make a request:

import requests

requests.post(
    "http://127.0.0.1:8080/",
    data={
        'title': "11",
        'job_url': '11',
        'build_num': 1,
        'display_env': ['Platform', 'NODE_NAME', "version"],
        'robot_webhook': ["http://aa"],
    },
    files={
        'json': open('.report.json', 'r', encoding='utf-8'),
    }
)

When I use the same request as question 2 to get request.files, I can't get the field name json and only the file name .report.json and file contents<class 'bytes'>

Your operating system

Linux

Your Python version (python --version)

3.12

Your Robyn version

latest

Additional Info

I hope the above feedback can be answered, whether it is a problem I use or a bug in the framework

@tqq1994516 tqq1994516 added the bug Something isn't working label Aug 28, 2024
@sansyrox
Copy link
Member

Hey @tqq1994516 👋

Thanks for raising this issue. @VishnuSanal can you have a look? Otherwise I can have a look by the weekend

@tqq1994516
Copy link
Author

@sansyrox

I am currently attempting to fix at https://github.com/tqq1994516/Robyn/tree/fix-request-body-parsing and expect to submit the pull request by Friday.

@tqq1994516 tqq1994516 linked a pull request Aug 30, 2024 that will close this issue
6 tasks
@tqq1994516
Copy link
Author

tqq1994516 commented Aug 30, 2024

@sansyrox Hi, the PR #956 is done, help see if it needs to be revised.

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

Successfully merging a pull request may close this issue.

2 participants