http-rs / http-rs/surf

Response::body_*blank* doesn't consume the response

Open
#363 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
1.5k
Forks
128
PR merge metrics
No merged PRs in 30d

Description

Hello, just spotted my friend trying to run this in his code:
```rs
let text = res.body_string().unwrap();
let json = res.body_json::().unwrap();
```
This made me slightly confused to when would you want to await for the body twice?
I was just wondering if this has any actual use case to it, or is it just a flaw of the current implantation, because if it is just a flaw of the current implantation I would love to look in to the ways of making it more ergonomic.

My first thought was making body_*blank*() just consume the response, but if anyone dislikes this idea, I think generics & zero sized types could also be a great solution.

Contributor guide

Open the contributing guide

Research direction

Start by locating the Response::body_string and Response::body_json entry points and reading how response bodies are currently consumed. Compare the existing behavior with the issue's repeated-await example, then clarify the intended API semantics and define completion with regression coverage for the chosen behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
api
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.