client: use hyper-tls for now

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
Wolfgang Bumiller 2019-02-13 11:03:02 +01:00
parent 42d6e4fb05
commit 4a3f65172c
2 changed files with 15 additions and 4 deletions

View File

@ -23,6 +23,7 @@ tokio-tls = "0.2.1"
native-tls = "0.2.2"
http = "0.1"
hyper = "0.12"
hyper-tls = "0.3"
lazy_static = "1.1"
regex = "1.0"
libc = "0.2"

View File

@ -22,8 +22,18 @@ impl HttpClient {
}
}
fn run_request(request: Request<Body>) -> Result<Value, Error> {
let client = Client::new();
fn run_request(
request: Request<Body>,
) -> Result<Value, Error> {
let mut builder = native_tls::TlsConnector::builder();
// FIXME: We need a CLI option for this!
builder.danger_accept_invalid_certs(true);
let tlsconnector = builder.build()?;
let mut httpc = hyper::client::HttpConnector::new(1);
httpc.enforce_http(false); // we want https...
let mut https = hyper_tls::HttpsConnector::from((httpc, tlsconnector));
https.https_only(true); // force it!
let client = Client::builder().build::<_, Body>(https);
let (tx, rx) = std::sync::mpsc::channel();
@ -65,7 +75,7 @@ impl HttpClient {
pub fn get(&self, path: &str) -> Result<Value, Error> {
let url: Uri = format!("http://{}:8007/{}", self.server, path).parse()?;
let url: Uri = format!("https://{}:8007/{}", self.server, path).parse()?;
let request = Request::builder()
.method("GET")
@ -78,7 +88,7 @@ impl HttpClient {
pub fn upload(&self, content_type: &str, body: Body, path: &str) -> Result<Value, Error> {
let url: Uri = format!("http://{}:8007/{}", self.server, path).parse()?;
let url: Uri = format!("https://{}:8007/{}", self.server, path).parse()?;
let request = Request::builder()
.method("POST")