diff --git a/awc/CHANGES.md b/awc/CHANGES.md index 9192e2db..dcc38c31 100644 --- a/awc/CHANGES.md +++ b/awc/CHANGES.md @@ -1,6 +1,6 @@ # Changes -## [0.1.0-alpha.2] - 2019-04-xx +## [0.1.0-alpha.2] - 2019-03-xx ### Added @@ -12,6 +12,10 @@ * Session wide basic and bearer auth. +### Changed + +* Export `ws` sub-module with websockets related types + ## [0.1.0-alpha.1] - 2019-03-28 diff --git a/awc/src/error.rs b/awc/src/error.rs index d3f1c1a1..8f51fd7d 100644 --- a/awc/src/error.rs +++ b/awc/src/error.rs @@ -1,6 +1,7 @@ //! Http client errors pub use actix_http::client::{ConnectError, InvalidUrl, SendRequestError}; pub use actix_http::error::PayloadError; +pub use actix_http::ws::HandshakeError as WsHandshakeError; pub use actix_http::ws::ProtocolError as WsProtocolError; use actix_http::http::{header::HeaderValue, Error as HttpError, StatusCode}; diff --git a/awc/src/lib.rs b/awc/src/lib.rs index 9a8daeb4..92f749d0 100644 --- a/awc/src/lib.rs +++ b/awc/src/lib.rs @@ -35,12 +35,11 @@ pub mod error; mod request; mod response; pub mod test; -mod ws; +pub mod ws; pub use self::builder::ClientBuilder; pub use self::request::ClientRequest; pub use self::response::ClientResponse; -pub use self::ws::WebsocketsRequest; use self::connect::{Connect, ConnectorWrapper}; @@ -126,6 +125,7 @@ impl Client { req } + /// Construct HTTP *GET* request. pub fn get(&self, url: U) -> ClientRequest where Uri: HttpTryFrom, @@ -133,6 +133,7 @@ impl Client { self.request(Method::GET, url) } + /// Construct HTTP *HEAD* request. pub fn head(&self, url: U) -> ClientRequest where Uri: HttpTryFrom, @@ -140,6 +141,7 @@ impl Client { self.request(Method::HEAD, url) } + /// Construct HTTP *PUT* request. pub fn put(&self, url: U) -> ClientRequest where Uri: HttpTryFrom, @@ -147,6 +149,7 @@ impl Client { self.request(Method::PUT, url) } + /// Construct HTTP *POST* request. pub fn post(&self, url: U) -> ClientRequest where Uri: HttpTryFrom, @@ -154,6 +157,7 @@ impl Client { self.request(Method::POST, url) } + /// Construct HTTP *PATCH* request. pub fn patch(&self, url: U) -> ClientRequest where Uri: HttpTryFrom, @@ -161,6 +165,7 @@ impl Client { self.request(Method::PATCH, url) } + /// Construct HTTP *DELETE* request. pub fn delete(&self, url: U) -> ClientRequest where Uri: HttpTryFrom, @@ -168,6 +173,7 @@ impl Client { self.request(Method::DELETE, url) } + /// Construct HTTP *OPTIONS* request. pub fn options(&self, url: U) -> ClientRequest where Uri: HttpTryFrom, @@ -175,11 +181,12 @@ impl Client { self.request(Method::OPTIONS, url) } - pub fn ws(&self, url: U) -> WebsocketsRequest + /// Construct WebSockets request. + pub fn ws(&self, url: U) -> ws::WebsocketsRequest where Uri: HttpTryFrom, { - let mut req = WebsocketsRequest::new(url, self.0.clone()); + let mut req = ws::WebsocketsRequest::new(url, self.0.clone()); for (key, value) in &self.0.headers { req.head.headers.insert(key.clone(), value.clone()); } diff --git a/awc/src/ws.rs b/awc/src/ws.rs index 26594531..9697210d 100644 --- a/awc/src/ws.rs +++ b/awc/src/ws.rs @@ -11,6 +11,8 @@ use cookie::{Cookie, CookieJar}; use futures::future::{err, Either, Future}; use tokio_timer::Timeout; +pub use actix_http::ws::{CloseCode, CloseReason, Frame, Message}; + use crate::connect::BoxedSocket; use crate::error::{InvalidUrl, SendRequestError, WsClientError}; use crate::http::header::{ @@ -208,7 +210,7 @@ impl WebsocketsRequest { self.header(AUTHORIZATION, format!("Bearer {}", token)) } - /// Complete request construction and connect. + /// Complete request construction and connect to a websockets server. pub fn connect( mut self, ) -> impl Future<