1
0
mirror of https://github.com/actix/actix-extras.git synced 2025-06-26 02:19:22 +02:00

Add missing API docs

These were written without much knowledge of the actix-web internals!
Please review carefully!
This commit is contained in:
Pascal Hertleif
2018-06-02 15:51:58 +02:00
parent 47b7be4fd3
commit 890a7e70d6
24 changed files with 82 additions and 2 deletions

View File

@ -34,32 +34,46 @@ use super::{Message, ProtocolError, WsWriter};
/// Websocket client error
#[derive(Fail, Debug)]
pub enum ClientError {
/// Invalid url
#[fail(display = "Invalid url")]
InvalidUrl,
/// Invalid response status
#[fail(display = "Invalid response status")]
InvalidResponseStatus(StatusCode),
/// Invalid upgrade header
#[fail(display = "Invalid upgrade header")]
InvalidUpgradeHeader,
/// Invalid connection header
#[fail(display = "Invalid connection header")]
InvalidConnectionHeader(HeaderValue),
/// Missing CONNECTION header
#[fail(display = "Missing CONNECTION header")]
MissingConnectionHeader,
/// Missing SEC-WEBSOCKET-ACCEPT header
#[fail(display = "Missing SEC-WEBSOCKET-ACCEPT header")]
MissingWebSocketAcceptHeader,
/// Invalid challenge response
#[fail(display = "Invalid challenge response")]
InvalidChallengeResponse(String, HeaderValue),
/// Http parsing error
#[fail(display = "Http parsing error")]
Http(Error),
/// Url parsing error
#[fail(display = "Url parsing error")]
Url(UrlParseError),
/// Response parsing error
#[fail(display = "Response parsing error")]
ResponseParseError(HttpResponseParserError),
/// Send request error
#[fail(display = "{}", _0)]
SendRequest(SendRequestError),
/// Protocol error
#[fail(display = "{}", _0)]
Protocol(#[cause] ProtocolError),
/// IO Error
#[fail(display = "{}", _0)]
Io(io::Error),
/// "Disconnected"
#[fail(display = "Disconnected")]
Disconnected,
}
@ -419,6 +433,7 @@ impl Future for ClientHandshake {
}
}
/// Websocket reader client
pub struct ClientReader {
inner: Rc<UnsafeCell<Inner>>,
max_size: usize,
@ -497,6 +512,7 @@ impl Stream for ClientReader {
}
}
/// Websocket writer client
pub struct ClientWriter {
inner: Rc<UnsafeCell<Inner>>,
}

View File

@ -86,10 +86,12 @@ where
A: Actor<Context = Self>,
{
#[inline]
/// Create a new Websocket context from a request and an actor
pub fn new(req: HttpRequest<S>, actor: A) -> WebsocketContext<A, S> {
WebsocketContext::from_request(req).actor(actor)
}
/// Create a new Websocket context from a request
pub fn from_request(req: HttpRequest<S>) -> WebsocketContext<A, S> {
WebsocketContext {
inner: ContextImpl::new(None),
@ -100,6 +102,7 @@ where
}
#[inline]
/// Set actor for this execution context
pub fn actor(mut self, actor: A) -> WebsocketContext<A, S> {
self.inner.set_actor(actor);
self

View File

@ -158,10 +158,15 @@ impl ResponseError for HandshakeError {
/// `WebSocket` Message
#[derive(Debug, PartialEq, Message)]
pub enum Message {
/// Text message
Text(String),
/// Binary message
Binary(Binary),
/// Ping message
Ping(String),
/// Pong message
Pong(String),
/// Close message with optional reason
Close(Option<CloseReason>),
}

View File

@ -180,8 +180,11 @@ impl From<u16> for CloseCode {
}
#[derive(Debug, Eq, PartialEq, Clone)]
/// Reason for closing the connection
pub struct CloseReason {
/// Exit code
pub code: CloseCode,
/// Optional description of the exit code
pub description: Option<String>,
}