diff options
| author | Erik Larkö <erik@mullvad.net> | 2017-03-22 22:15:16 +0800 |
|---|---|---|
| committer | Erik Larkö <erik@mullvad.net> | 2017-03-22 22:16:59 +0800 |
| commit | d32e3609e21498842f5da2aae5ae14373f0337d5 (patch) | |
| tree | 69558d92e9fd9242ac1c082f4d497efa12f22249 | |
| parent | 258de4f4594740566641c2c3fa94f6c73c5980a2 (diff) | |
| download | mullvadvpn-d32e3609e21498842f5da2aae5ae14373f0337d5.tar.xz mullvadvpn-d32e3609e21498842f5da2aae5ae14373f0337d5.zip | |
Remove the http ipc client
| -rw-r--r-- | talpid_ipc/Cargo.toml | 1 | ||||
| -rw-r--r-- | talpid_ipc/src/http_ipc.rs | 43 | ||||
| -rw-r--r-- | talpid_ipc/tests/http_integration_tests.rs | 40 |
3 files changed, 1 insertions, 83 deletions
diff --git a/talpid_ipc/Cargo.toml b/talpid_ipc/Cargo.toml index 11efc69ef2..49d9c6cd02 100644 --- a/talpid_ipc/Cargo.toml +++ b/talpid_ipc/Cargo.toml @@ -10,7 +10,6 @@ serde = "0.9" serde_json = "0.9" log = "0.3" tiny_http = "0.5" -hyper = "0.10" [target.'cfg(not(windows))'.dependencies] zmq = "0.8" diff --git a/talpid_ipc/src/http_ipc.rs b/talpid_ipc/src/http_ipc.rs index 1cd675a990..f63c15e159 100644 --- a/talpid_ipc/src/http_ipc.rs +++ b/talpid_ipc/src/http_ipc.rs @@ -1,6 +1,5 @@ extern crate tiny_http; extern crate serde_json; -extern crate hyper; use super::{ErrorKind, Result, ResultExt, IpcServerId}; use serde; @@ -58,44 +57,4 @@ fn send_response<U: serde::Serialize>(response: &U, request: tiny_http::Request) request.respond(tiny_http::Response::from_string(response_as_string)) .chain_err(|| "Failed responding to HTTP request") }) -} - -pub struct IpcClient<T, U> - where T: serde::Serialize, - U: serde::Deserialize -{ - server_id: IpcServerId, - client: hyper::Client, - _phantom_t: ::std::marker::PhantomData<T>, - _phantom_u: ::std::marker::PhantomData<U>, -} - -impl<T, U> IpcClient<T, U> - where T: serde::Serialize, - U: serde::Deserialize -{ - pub fn new(server_id: IpcServerId) -> Self { - IpcClient { - server_id: server_id, - client: hyper::Client::new(), - _phantom_t: ::std::marker::PhantomData, - _phantom_u: ::std::marker::PhantomData, - } - } - - pub fn send(&mut self, message: &T) -> Result<U> { - let message_json = serde_json::to_string(message).chain_err(|| ErrorKind::ParseFailure)?; - debug!("HTTP IPC sending {}", message_json); - let mut reply = self.client - .post(&self.server_id) - .body(&message_json) - .send() - .chain_err(|| ErrorKind::SendError)?; - - Self::parse_reply(&mut reply) - } - - fn parse_reply(reply: &mut hyper::client::response::Response) -> Result<U> { - serde_json::from_reader(reply).chain_err(|| ErrorKind::ParseFailure) - } -} +}
\ No newline at end of file diff --git a/talpid_ipc/tests/http_integration_tests.rs b/talpid_ipc/tests/http_integration_tests.rs deleted file mode 100644 index 72f6d190bc..0000000000 --- a/talpid_ipc/tests/http_integration_tests.rs +++ /dev/null @@ -1,40 +0,0 @@ -#[cfg(all(test, not(windows)))] -mod http_integration_tests { - extern crate serde; - extern crate talpid_ipc; - - use self::talpid_ipc::{Result, IpcServerId}; - use self::talpid_ipc::http_ipc; - - use std::sync::mpsc::{self, Receiver}; - use std::time::Duration; - - #[test] - fn can_connect_and_send_and_receive_messages() { - let (connection_string, server_messages) = start_server::<String>(); - - let mut ipc_client = http_ipc::IpcClient::new(connection_string); - let msg = "Hello".to_owned(); - let response: String = ipc_client.send(&msg).expect("Could not send message"); - - let message = server_messages.recv_timeout(Duration::from_millis(1000)) - .expect("Did not receive a message"); - - assert_eq!(message.unwrap(), "Hello", "Got wrong message"); - assert_eq!(response, "RESPONSE"); - } - - fn start_server<T>() -> (IpcServerId, Receiver<Result<T>>) - where T: serde::Deserialize + Send + 'static - { - let (tx, rx) = mpsc::channel(); - - let connection_string = http_ipc::start_new_server(move |message: Result<T>| { - let _ = tx.send(message); - "RESPONSE" - }) - .expect("Could not start the server"); - - (connection_string, rx) - } -} |
