Giter Club home page Giter Club logo

async-web-client's People

Contributors

florianuekermann avatar joshtriplett avatar mauzigoe avatar

Stargazers

 avatar

Watchers

 avatar

async-web-client's Issues

remove `Clone` or move body requirement

We don't want to require Clone on bodies or force the user to move them. &mut references should be sufficient (cloning non-body parts of the request is fine).

  • implement non-cloneable bodies (like a fixed size AsyncRead wrapper).
  • retain the request and body in the calling scope, which can be handy for context.

However, if possible passing body by reference or value (moving), should both be allowed, because users implementing their own futures on top may run into problems with lifetimes using references, while most other users would likely prefer a reference. Something like:
send(&self, body: AsMut<IntoRequestBody) or send(&self, body: BorrowMut<IntoRequestBody) maybe

support custom transports

We should probably add support custom transports, because why not. Something like send_via(&self, transport: impl AsyncRead + AsyncWrite + Unpin)

This would allow us to add tests which don't require network bits as well.

Maybe this should wait until the underlying protocol crate is in better shape and implements more of the state machine.

send method variants

We want to support:

let request: http::Request<&str> = Request::post("http://postman-echo.com/post").body("jalsdfjlasdjflek")?;
reqeust.send().await?;

as well as

let request: http::Request<()> = Request::post("http://postman-echo.com/post").body(())?;
let response = request.send(Some("jalsdfjlasdjflek")).await?;

multiple ext traits and changes to IntoRequestBody) may be necessary. (IntoRequestBody has an impl for () atm, which may cause problems if both traits are used, assuming the user uses the prelude.rs

It should also be easy to send empty bodies using None or (), which may be a bit tricky because the T in Option<T> can't be inferred. Default type parameters may help... ...worst case we have to differentiation send() and send_with_body().

HTTP semantically doesn't really differentiate between 0 length body and no body, which opens up some more options like "" for no-body scenarios. But it would be good to find a solution that feels more idiomatic (like () or None).

We probably want to make send take a reference instead of moving the request as well...

A good first step may be to add test which cover all options we want to work. They don't need to actually do the async stuff, this is fine:

#[test]
fn test() {
    let request_without_body: http::Request<()> = Request::post("http://example.com").body(())?;
    let request_with_body: http::Request<()> = Request::post("http://example.com").body(())?;

    _ = request_without_body.send(Some("jalsdfjlasdjflek"));
    _ = request_without_body.send(None);
    _ = request_with_body.send();
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.