hyper icon indicating copy to clipboard operation
hyper copied to clipboard

refactor: Remove Body's Once variant

Open Xuanwo opened this issue 3 years ago • 5 comments

Signed-off-by: Xuanwo [email protected]

Fix https://github.com/hyperium/hyper/issues/2922

I'm not sure whether I correctly did this, PTAL.

Xuanwo avatar Jul 26 '22 02:07 Xuanwo

Looks like a couple tests that were using the Default impl will need to be changed to construct a Request manually.

seanmonstar avatar Jul 28 '22 18:07 seanmonstar

    pub fn get(&self, uri: Uri) -> ResponseFuture
    where
        B: Default,

Client::get needs B: Default, do we need to remove this API? (This will break many code)

Xuanwo avatar Jul 29 '22 01:07 Xuanwo

No, that method doesn't need to be removed (yet). Just change the tests to use client.request(req).

seanmonstar avatar Jul 29 '22 02:07 seanmonstar

I'm feeling challenged to migrate tests like http2_detect_conn_eof. Can you give me some help?

In those tests, both request and response depend on hpyer::Body (so does Body::empty()), I can't replace them with http_body_util::Empty<bytes::Bytes> simplely.

Any ideas?

Xuanwo avatar Jul 30 '22 11:07 Xuanwo

migrate tests like http2_detect_conn_eof.

I just took a look, and this should be able to fix it:

type Empty = http_body_util::Empty<Bytes>;

let service = service_fn(|_:Request<Body>| future::ok::<_, hyper::Error>(Response::new(Empty::new())));

// ...

let req = Request::builder()
            .uri(format!("http://{}/", addr))
            .body(Empty::new())
            .expect("request builder");

You don't need to change the Request<Body> part of the service_fn, since that's the request that hyper is generating.

seanmonstar avatar Jul 30 '22 17:07 seanmonstar

Thanks so much for taking it so far! I took care of merge conflicts and finishing out the examples, and completed it in #2922.

seanmonstar avatar Aug 24 '22 20:08 seanmonstar