hyper

Initializing a Rust variable passed to async code such as tokio and hyper

早过忘川 提交于 2020-02-16 05:29:22
问题 I have a value that cannot be computed at compile time. It needs to be computed before any of the app code runs, and then it will only be read throughout the lifetime of the app. It also needs to be passed around to executors such as tokio and hyper handlers. How can I create such a value safely, idiomatically and without unneeded performance losses? If I create it in main and pass it to hyper , it does not live long enough. If I create it with lazy_static! , it only gets computed when it's

Initializing a Rust variable passed to async code such as tokio and hyper

故事扮演 提交于 2020-02-16 05:29:06
问题 I have a value that cannot be computed at compile time. It needs to be computed before any of the app code runs, and then it will only be read throughout the lifetime of the app. It also needs to be passed around to executors such as tokio and hyper handlers. How can I create such a value safely, idiomatically and without unneeded performance losses? If I create it in main and pass it to hyper , it does not live long enough. If I create it with lazy_static! , it only gets computed when it's

Can't read a simple payload making HTTP request via hyper::client::Client: the trait bound `Body: Future` is not satisfied

浪尽此生 提交于 2020-01-15 12:26:05
问题 I am attempting to convert a Result to a Buffer : let ufc_root: String = String::from("https://www.ufc.com/athletes/all?filters%5B0%5D=status%3A23"); // let ufc_root: String = String::from("https://www.google.com"); let https = HttpsConnector::new(4).unwrap(); let client = Client::builder().build::<_, hyper::Body>(https); client .get(ufc_root.parse::<hyper::Uri>().unwrap()) .and_then(|res| { println!("http status code: {}", res.status()); println!("http response headers:\n{:?}: ", res.headers

How to make a request with client certificate in Rust

蓝咒 提交于 2020-01-11 11:36:11
问题 I have a project with microservices deployed in Bluemix with Docker containers. All microservices are written in Java and the communication is using JKS files. I also developed a microservice in Node.js with Express.js. To consume the other microservices, I used the Request module with option.agentOptions feature and a pfx file , like this: var options = { uri: config.get("https://www.example.com/ms/service"), method: 'POST', body: data, json: true, headers: { 'Content-Type': 'application

How do I share a HashMap between Hyper handlers?

白昼怎懂夜的黑 提交于 2020-01-11 08:28:09
问题 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, short_uris: &mut HashMap<&str, &str>) { let mut body = String::new(); match req.read_to_string(&mut body) { Ok(_) => { let key = short_uris.len(); short_uris.insert(&key.to_string(), &body.to_string()); *res.status_mut() = StatusCode::Created; res

How to get the cookie from a GET response?

冷暖自知 提交于 2020-01-06 07:58:26
问题 I am writing a function that makes a GET request to a website and returns the response cookie: extern crate futures; extern crate hyper; extern crate tokio_core; use tokio_core::reactor::Core; use hyper::Client; use std::error::Error; use hyper::header::Cookie; use futures::future::Future; fn get_new_cookie() -> Result<String, Box<Error>> { println!("Getting cookie..."); let core = Core::new()?; let client = Client::new(&core.handle()); println!("Created client"); let uri = "http://www.cnn

How do I read the entire body of a Tokio-based Hyper request?

谁说我不能喝 提交于 2019-12-23 21:04:44
问题 I want to write a server using the current master branch of Hyper that saves a message that is delivered by a POST request and sends this message to every incoming GET request. I have this, mostly copied from the Hyper examples directory: extern crate futures; extern crate hyper; extern crate pretty_env_logger; use futures::future::FutureResult; use hyper::{Get, Post, StatusCode}; use hyper::header::{ContentLength}; use hyper::server::{Http, Service, Request, Response}; use futures::Stream;

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

狂风中的少年 提交于 2019-12-23 21:02:59
问题 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 once: EnterError { reason: "attempted to run an executor while another executor is already running" }', src/libcore/result.rs:999:5 note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace. Panic in Arbiter thread, shutting down

Windows Server 2012重复数据删除 OR 备份软件重复数据删除?

那年仲夏 提交于 2019-12-19 13:56:13
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 转载请在文首保留原文出处: EMC中文支持论坛 https://community.emc.com/go/chinese 介绍 现如今重复数据删除已成为一种存储主流技术。如何在形形色色的重复数据删除解决方案中找到最合适的一款,是IT专业人员面临的难题。在 Windows Server 2012 的存储新功能——重复数据删除 这篇文章中,我们介绍过最新的Windows Server 2012操作系统自带有重复数据删除功能。那么我们究竟是该使用Windows Server 2012操作系统自带的重复数据删除功能呢还是该把重复数据删除的任务交给备份软件来完成呢?这个问题恐怕很难有100%确切的答案,不过我们可以从下面这些因素来考虑。 更多信息 1. 重复数据删除的目标是什么? 首先要考虑的是为什么要重复数据删除,目的何在。源端重复数据删除的主要目的通常不是降低服务器上的存储数据量,而是减少需要传输到备份服务器上进行存储的数据量。 Windows Server 2012自带的重复数据删除功能也是一种源端重复数据删除,但是它的主要目的是为了减少服务器存储空间的消耗,而不是减少备份的数据量(至少对它自己本身而言不是)。 当然,你可能会问这样一个问题:是否可以将Windows Server

How to set timeout for HTTP request with hyper, tokio and futures in Rust?

不羁的心 提交于 2019-12-19 03:45:14
问题 How do I set a timeout for HTTP request using asynchronous Hyper (>= 0.11)? Here is the example of the code without timeout: extern crate hyper; extern crate tokio_core; extern crate futures; use futures::Future; use hyper::Client; use tokio_core::reactor::Core; fn main() { let mut core = Core::new().unwrap(); let client = Client::new(&core.handle()); let uri = "http://stackoverflow.com".parse().unwrap(); let work = client.get(uri).map(|res| { res.status() }); match core.run(work) { Ok(status