Questions tagged [hyper]

A fast and correct HTTP implementation for Rust.

Hyper is a fast, safe HTTP implementation written in and for Rust.

  • A Client for talking to web services.
  • A Server for building those web services.
  • Blazing fast* thanks to Rust.
  • High concurrency with non-blocking sockets.
  • HTTP/1 and HTTP/2 support.

Github Repository

Guide

256 questions
7
votes
1 answer

How do I share a HashMap between Hyper handlers?

I'm attempting to learn Rust by implementing a simple in-memory URL shortener with Hyper 0.10. I'm running into an issue that I think is caused by trying to close over a mutable HashMap in my handler: fn post(mut req: Request, mut res: Response,…
forTruce
  • 829
  • 2
  • 7
  • 17
6
votes
1 answer

How to make an axum router handle return different content-type responses?

For example, when user access http://127.0.0.1:8080/hello, if query parameter id is 1, a plain text response return. If id is 2, give a json structure. Summary: id (input) status code content-type body 1 200 application/json {"name":…
progquester
  • 1,228
  • 14
  • 23
6
votes
1 answer

Passing additional state to rust `hyper::service::service_fn`

I am having trouble passing additional state to my service function, but I can't sort out the lifetimes in the closures. None of the tutorials seem to address…
Dan Jenson
  • 961
  • 7
  • 20
6
votes
1 answer

Parsing an object inside an object with serde_json

I am stuck, below is the JSON which I am receiving: { "BCH": { "aclass": "currency", "altname": "BCH", "decimals": 10, "display_decimals": 5 } } I am bit confused on how my struct should look like to parse the…
BalaB
  • 3,687
  • 9
  • 36
  • 58
6
votes
1 answer

How to download a large file with hyper and resume on error?

I want to download large files (500mb) with hyper, and be able to resume if the download fails. Is there any way with hyper to run some function for each chunk of data received? The send() method returns a Result, but I can't find any…
jbrown
  • 7,518
  • 16
  • 69
  • 117
6
votes
3 answers

Displaying the response body with Hyper only shows the size of the body

I tried to display the content (body) of an URL as text using Hyper extern crate hyper; use hyper::client::Client; use std::io::Read; fn main () { let client = Client::new(); let mut s = String::new(); let res =…
rap-2-h
  • 30,204
  • 37
  • 167
  • 263
5
votes
1 answer

Using a custom transporter for Rust's hyper http crate

ps: the answer below helped but it's not the answer I need, I have a new problem and I edited the question I'm trying to make a custom transporter for the hyper http crate, so I can transport http packets in my own way. Hyper's http client can be…
Guerlando OCs
  • 1,886
  • 9
  • 61
  • 150
5
votes
0 answers

Rust Hyper streaming capability

I'm currently trying to achieve data streaming trough a simple HTTP get request in rust with hyper (0.13). The idea is simple. If the client sends a request the server responds in "chunks" every 5s leaving the connection open the whole time. I'm…
5
votes
0 answers

async stream `hyper::body::Body` to file in rust

How can you stream from a hyper::body::Body to a file using tokio::io::AsyncWriteExt or tokio::io::{AsyncRead,AsyncWrite} traits. It seems like in 0.13.5, hyper::error::Error cannot be created, so converting from std::io::Error to…
Dan Jenson
  • 961
  • 7
  • 20
5
votes
1 answer

Implementing HTTPS Server using Rustls with Hyper in Rust

I am trying to implement implement HTTPS server using Rustls with Hyper, but am not able to get proper example of how to implement the same. And for that i have followed and tried example given on hyper-rustls repository here (Hyper Rustls server…
kanudo
  • 2,119
  • 1
  • 17
  • 33
5
votes
2 answers

HTTP request inside actix-web handler -> Multiple executors at once: EnterError

When creating a hyper post request inside an actix-web resolver, the following error is thrown - how can one send one a http request by spawning the request into the existing executor? thread 'actix-rt:worker:1' panicked at 'Multiple executors at…
Techradar
  • 3,506
  • 3
  • 18
  • 28
5
votes
1 answer

How do I stream a hyper Request's Body from a slow-processing side thread that produces chunks of data?

I have a program which generates data slowly (we can say it's computationally intensive, like computing digits of pi). It produces a lot of data; each response can be 1GiB, will not fit in memory, and must be generated on demand. I'm using hyper to…
njaard
  • 529
  • 4
  • 15
5
votes
1 answer

How to copy data from a stream while also forwarding a stream

I am using hyper 0.12 to build a proxy service. When receiving a response body from the upstream server I want to forward it back to the client ASAP, and save the contents in a buffer for later processing. So I need a function that: takes a Stream…
molf
  • 73,644
  • 13
  • 135
  • 118
5
votes
1 answer

How can I use hyper::client from another thread?

I have multiple threads performing some heavy operations and I need to use a client in middle of work. I'm using Hyper v0.11 as a HTTP client and I would like to reuse the connections so I need to share the same hyper::Client in order to keep open…
cspinetta
  • 443
  • 6
  • 17
5
votes
1 answer

`for<'r, 'r, 'r> ...` cannot be sent between threads safely

I learn Rust and I tried to build a micro route system built on top of hyper (it's just for learning purpose, I know frameworks exists). I don't know how to share a "complex" type with an hyper::server::Handler. I read the error message, but…
rap-2-h
  • 30,204
  • 37
  • 167
  • 263
1
2
3
17 18