Skip to content

robyn request body processing problem #954

@tqq1994516

Description

@tqq1994516

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions