Giter Site home page Giter Site logo

http_io's Introduction

http_io Latest Version

Crate containing HTTP client and server.

  • Designed to have limited dependencies, supports #![no_std].
  • Focus on streaming IO.
  • Support for providing your own transport.
  • Supports HTTPS

The no_std build requires nightly since it relies on the alloc crate.

Example

use http_io::error::Result;
use std::fs::File;
use std::io;

fn main() -> Result<()> {
    // Stream contents of url to stdout
    let mut body = http_io::client::get("https://postman-echo.com/get")?;
    io::copy(&mut body, &mut std::io::stdout())?;

    // Stream contents of file to remote server
    let file = File::open("src/client.rs")?;
    http_io::client::put("https://postman-echo.com/put", file)?;
    Ok(())
}

Choosing a TLS backend

By default http_io uses native-tls as its library for TLS (HTTPS support). It supports two other TLS libraries, rustls and openssl. These other "back-ends" can be selected using feaures

$ # If you want to use `rustls`:
$ cargo build --no-default-features --features std,ssl-rustls
$ # If you want to use `openssl`:
$ cargo build --no-default-features --features std,ssl-openssl

http_io's People

Contributors

bobbobbio avatar

Stargazers

Clayton Kehoe avatar Will Dumm avatar Joe Cross avatar Noah Gude avatar Nick Spain avatar Andrejs Agejevs avatar Hanneli Tavante avatar Zhang Kaizhao avatar iamazy avatar Brendan Zabarauskas avatar Zhao Xiaohong avatar  avatar Ayrton Sparling avatar Jessie Chatham Spencer avatar Kyle Charters avatar Cameron Elliott avatar  avatar  avatar Henrik Alsér avatar Armer song avatar Vitaliy Yermolenko avatar Rust avatar Peyman Salehi avatar Wesley Moore avatar

Watchers

 avatar James Cloos avatar Oto Petřík avatar

http_io's Issues

response lifetime appears to require 'static, which makes it tricky to pass references.

I am experimenting with serving camera images from an ESP32 microcontroller. It has a std environment available. In order to fetch the image, I must repeatedly communicate with the camera via SPI.

I store a reference to the camera in MyHandler and pass it to the CameraBody (: impl Read) , but when I wrap that CameraBody in a Box and an HttpResponse, I get

error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'a` due to conflicting requirements
  --> src/httpd.rs:45:24
   |
45 |             let body = CameraBody::new(self.camera, self.spi).map_err(|e| {
   |                        ^^^^^^^^^^^^^^^
   |
note: first, the lifetime cannot outlive the lifetime `'a` as defined here...
  --> src/httpd.rs:21:6
   |
21 | impl<'a, SPI, CS, I2C, ES, EI, S> HttpRequestHandler<S> for MyHandler<'a, SPI, CS, I2C, ES, EI>
   |      ^^
note: ...so that reference does not outlive borrowed content
  --> src/httpd.rs:45:40
   |
45 |             let body = CameraBody::new(self.camera, self.spi).map_err(|e| {
   |                                        ^^^^^^^^^^^
   = note: but, the lifetime must be valid for the static lifetime...
note: ...so that the types are compatible
  --> src/httpd.rs:66:9
   |
66 |         Ok(resp)
   |         ^^^^^^^^
   = note: expected `Result<HttpResponse<Box<(dyn std::io::Read + 'static)>>, HttpResponse<Box<(dyn std::io::Read + 'static)>>>`
              found `Result<HttpResponse<Box<dyn std::io::Read>>, HttpResponse<Box<dyn std::io::Read>>>`

I get the feeling I'm going to have to wrap some things in an Arc<Mutex<_>> to help them live longer. This will get significantly harder if I target a no_std environment (which often lack Arc or Mutex).

I can't help but wonder if the API could be upgraded to have a lifetime on the result of the get() function to simplify things.

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.