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

Implement prepare_request/build_request and the corresponding Session.send() #498

Open
alive4ever opened this issue Feb 12, 2025 · 1 comment
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@alive4ever
Copy link

Is your feature request related to a problem? Please describe.

Currently, the requests api of curl_cffi is missing prepare_request or httpx's build_request method. The method is useful to construct request object and ability to view or edit the request object before sending the request via Session().send or Client().send().

Describe the solution you'd like

httpx's build_request or requests' prepare_request method implemented in the requests api of curl_cffi

Describe alternatives you've considered

Using curl_cffi as requests adapter, so expected requests features are available.

Context

An example of the usefulness of build_request method in action.

client = requests.Session()
# build_request is httpx method, similar to prepare_request
req = client.build_request(method: 'GET', url, headers, cookies, data)
# show request headers
req.headers
# Update user-agent header
req.headers['User-Agent'] = 'my_web_crawler/0.1'
# show request payload
req.content
# Update request payload using json string
data =  { 'hello': 'world'}
req.content = bytes(json.dumps(data), 'utf-8')
# Update request method
req.method = 'POST'
# send the built request after fixing the issue
resp = client.send(req)
@alive4ever alive4ever added the enhancement New feature or request label Feb 12, 2025
@lexiforest
Copy link
Owner

Good suggestion. On our TODO list now.

@lexiforest lexiforest added the good first issue Good for newcomers label Feb 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants