1
0
mirror of https://github.com/fafhrd91/actix-web synced 2024-11-24 00:21:08 +01:00

s/websocket/WebSocket in docs

This commit is contained in:
Rob Ede 2021-02-12 00:27:20 +00:00
parent 81bef93e5e
commit 4fc7d76759
No known key found for this signature in database
GPG Key ID: C2A3B36E841A91E6
10 changed files with 28 additions and 29 deletions

View File

@ -243,7 +243,7 @@ impl TestServer {
response.body().limit(10_485_760).await response.body().limit(10_485_760).await
} }
/// Connect to websocket server at a given path /// Connect to WebSocket server at a given path.
pub async fn ws_at( pub async fn ws_at(
&mut self, &mut self,
path: &str, path: &str,
@ -253,7 +253,7 @@ impl TestServer {
connect.await.map(|(_, framed)| framed) connect.await.map(|(_, framed)| framed)
} }
/// Connect to a websocket server /// Connect to a WebSocket server.
pub async fn ws( pub async fn ws(
&mut self, &mut self,
) -> Result<Framed<impl AsyncRead + AsyncWrite, ws::Codec>, awc::error::WsClientError> { ) -> Result<Framed<impl AsyncRead + AsyncWrite, ws::Codec>, awc::error::WsClientError> {

View File

@ -224,7 +224,7 @@ impl MessageType for Request {
let decoder = match length { let decoder = match length {
PayloadLength::Payload(pl) => pl, PayloadLength::Payload(pl) => pl,
PayloadLength::UpgradeWebSocket => { PayloadLength::UpgradeWebSocket => {
// upgrade(websocket) // upgrade (WebSocket)
PayloadType::Stream(PayloadDecoder::eof()) PayloadType::Stream(PayloadDecoder::eof())
} }
PayloadLength::None => { PayloadLength::None => {

View File

@ -54,7 +54,7 @@ pub enum Frame {
Close(Option<CloseReason>), Close(Option<CloseReason>),
} }
/// A `WebSocket` continuation item. /// A WebSocket continuation item.
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq)]
pub enum Item { pub enum Item {
FirstText(Bytes), FirstText(Bytes),
@ -79,7 +79,7 @@ bitflags! {
} }
impl Codec { impl Codec {
/// Create new websocket frames decoder. /// Create new WebSocket frames decoder.
pub fn new() -> Codec { pub fn new() -> Codec {
Codec { Codec {
max_size: 65_536, max_size: 65_536,

View File

@ -7,7 +7,7 @@ use crate::ws::mask::apply_mask;
use crate::ws::proto::{CloseCode, CloseReason, OpCode}; use crate::ws::proto::{CloseCode, CloseReason, OpCode};
use crate::ws::ProtocolError; use crate::ws::ProtocolError;
/// A struct representing a `WebSocket` frame. /// A struct representing a WebSocket frame.
#[derive(Debug)] #[derive(Debug)]
pub struct Parser; pub struct Parser;

View File

@ -1,6 +1,6 @@
//! WebSocket protocol support. //! WebSocket protocol.
//! //!
//! To setup a WebSocket, first do web socket handshake then on success convert `Payload` into a //! To setup a WebSocket, first perform the WebSocket handshake then on success convert `Payload` into a
//! `WsStream` stream and then use `WsWriter` to communicate with the peer. //! `WsStream` stream and then use `WsWriter` to communicate with the peer.
use std::io; use std::io;
@ -76,7 +76,7 @@ pub enum HandshakeError {
#[display(fmt = "Method not allowed.")] #[display(fmt = "Method not allowed.")]
GetMethodRequired, GetMethodRequired,
/// Upgrade header if not set to websocket. /// Upgrade header if not set to WebSocket.
#[display(fmt = "WebSocket upgrade is expected.")] #[display(fmt = "WebSocket upgrade is expected.")]
NoWebsocketUpgrade, NoWebsocketUpgrade,
@ -88,7 +88,7 @@ pub enum HandshakeError {
#[display(fmt = "WebSocket version header is required.")] #[display(fmt = "WebSocket version header is required.")]
NoVersionHeader, NoVersionHeader,
/// Unsupported websocket version. /// Unsupported WebSocket version.
#[display(fmt = "Unsupported version.")] #[display(fmt = "Unsupported version.")]
UnsupportedVersion, UnsupportedVersion,
@ -127,20 +127,20 @@ impl ResponseError for HandshakeError {
} }
} }
/// Verify `WebSocket` handshake request and create handshake response. /// Verify WebSocket handshake request and create handshake response.
pub fn handshake(req: &RequestHead) -> Result<ResponseBuilder, HandshakeError> { pub fn handshake(req: &RequestHead) -> Result<ResponseBuilder, HandshakeError> {
verify_handshake(req)?; verify_handshake(req)?;
Ok(handshake_response(req)) Ok(handshake_response(req))
} }
/// Verify `WebSocket` handshake request. /// Verify WebSocket handshake request.
pub fn verify_handshake(req: &RequestHead) -> Result<(), HandshakeError> { pub fn verify_handshake(req: &RequestHead) -> Result<(), HandshakeError> {
// WebSocket accepts only GET // WebSocket accepts only GET
if req.method != Method::GET { if req.method != Method::GET {
return Err(HandshakeError::GetMethodRequired); return Err(HandshakeError::GetMethodRequired);
} }
// Check for "UPGRADE" to websocket header // Check for "UPGRADE" to WebSocket header
let has_hdr = if let Some(hdr) = req.headers().get(header::UPGRADE) { let has_hdr = if let Some(hdr) = req.headers().get(header::UPGRADE) {
if let Ok(s) = hdr.to_str() { if let Ok(s) = hdr.to_str() {
s.to_ascii_lowercase().contains("websocket") s.to_ascii_lowercase().contains("websocket")
@ -181,7 +181,7 @@ pub fn verify_handshake(req: &RequestHead) -> Result<(), HandshakeError> {
Ok(()) Ok(())
} }
/// Create websocket handshake response /// Create WebSocket handshake response.
/// ///
/// This function returns handshake `Response`, ready to send to peer. /// This function returns handshake `Response`, ready to send to peer.
pub fn handshake_response(req: &RequestHead) -> ResponseBuilder { pub fn handshake_response(req: &RequestHead) -> ResponseBuilder {

View File

@ -74,8 +74,7 @@ impl From<u8> for OpCode {
} }
} }
/// Status code used to indicate why an endpoint is closing the `WebSocket` /// Status code used to indicate why an endpoint is closing the WebSocket connection.
/// connection.
#[derive(Debug, Eq, PartialEq, Clone, Copy)] #[derive(Debug, Eq, PartialEq, Clone, Copy)]
pub enum CloseCode { pub enum CloseCode {
/// Indicates a normal closure, meaning that the purpose for /// Indicates a normal closure, meaning that the purpose for

View File

@ -48,7 +48,7 @@ where
/// ///
/// If successful, returns a pair where the first item is an address for the /// If successful, returns a pair where the first item is an address for the
/// created actor and the second item is the response that should be returned /// created actor and the second item is the response that should be returned
/// from the websocket request. /// from the WebSocket request.
pub fn start_with_addr<A, T>( pub fn start_with_addr<A, T>(
actor: A, actor: A,
req: &HttpRequest, req: &HttpRequest,
@ -63,7 +63,7 @@ where
Ok((addr, res.streaming(out_stream))) Ok((addr, res.streaming(out_stream)))
} }
/// Do websocket handshake and start ws actor. /// Do WebSocket handshake and start ws actor.
/// ///
/// `protocols` is a sequence of known protocols. /// `protocols` is a sequence of known protocols.
pub fn start_with_protocols<A, T>( pub fn start_with_protocols<A, T>(
@ -80,7 +80,7 @@ where
Ok(res.streaming(WebsocketContext::create(actor, stream))) Ok(res.streaming(WebsocketContext::create(actor, stream)))
} }
/// Prepare `WebSocket` handshake response. /// Prepare WebSocket handshake response.
/// ///
/// This function returns handshake `HttpResponse`, ready to send to peer. /// This function returns handshake `HttpResponse`, ready to send to peer.
/// It does not perform any IO. /// It does not perform any IO.
@ -88,7 +88,7 @@ pub fn handshake(req: &HttpRequest) -> Result<HttpResponseBuilder, HandshakeErro
handshake_with_protocols(req, &[]) handshake_with_protocols(req, &[])
} }
/// Prepare `WebSocket` handshake response. /// Prepare WebSocket handshake response.
/// ///
/// This function returns handshake `HttpResponse`, ready to send to peer. /// This function returns handshake `HttpResponse`, ready to send to peer.
/// It does not perform any IO. /// It does not perform any IO.
@ -105,7 +105,7 @@ pub fn handshake_with_protocols(
return Err(HandshakeError::GetMethodRequired); return Err(HandshakeError::GetMethodRequired);
} }
// Check for "UPGRADE" to websocket header // check for "UPGRADE" to WebSocket header
let has_hdr = if let Some(hdr) = req.headers().get(&header::UPGRADE) { let has_hdr = if let Some(hdr) = req.headers().get(&header::UPGRADE) {
if let Ok(s) = hdr.to_str() { if let Ok(s) = hdr.to_str() {
s.to_ascii_lowercase().contains("websocket") s.to_ascii_lowercase().contains("websocket")

View File

@ -45,7 +45,7 @@ use crate::http::{ConnectionType, Error as HttpError, Method, StatusCode, Uri, V
use crate::response::ClientResponse; use crate::response::ClientResponse;
use crate::ClientConfig; use crate::ClientConfig;
/// `WebSocket` connection /// WebSocket connection.
pub struct WebsocketsRequest { pub struct WebsocketsRequest {
pub(crate) head: RequestHead, pub(crate) head: RequestHead,
err: Option<HttpError>, err: Option<HttpError>,
@ -59,7 +59,7 @@ pub struct WebsocketsRequest {
} }
impl WebsocketsRequest { impl WebsocketsRequest {
/// Create new websocket connection /// Create new WebSocket connection
pub(crate) fn new<U>(uri: U, config: Rc<ClientConfig>) -> Self pub(crate) fn new<U>(uri: U, config: Rc<ClientConfig>) -> Self
where where
Uri: TryFrom<U>, Uri: TryFrom<U>,
@ -102,7 +102,7 @@ impl WebsocketsRequest {
self self
} }
/// Set supported websocket protocols /// Set supported WebSocket protocols
pub fn protocols<U, V>(mut self, protos: U) -> Self pub fn protocols<U, V>(mut self, protos: U) -> Self
where where
U: IntoIterator<Item = V>, U: IntoIterator<Item = V>,
@ -239,7 +239,7 @@ impl WebsocketsRequest {
self.header(AUTHORIZATION, format!("Bearer {}", token)) self.header(AUTHORIZATION, format!("Bearer {}", token))
} }
/// Complete request construction and connect to a websockets server. /// Complete request construction and connect to a WebSocket server.
pub async fn connect( pub async fn connect(
mut self, mut self,
) -> Result<(ClientResponse, Framed<BoxedSocket, Codec>), WsClientError> { ) -> Result<(ClientResponse, Framed<BoxedSocket, Codec>), WsClientError> {
@ -338,7 +338,7 @@ impl WebsocketsRequest {
return Err(WsClientError::InvalidResponseStatus(head.status)); return Err(WsClientError::InvalidResponseStatus(head.status));
} }
// Check for "UPGRADE" to websocket header // check for "UPGRADE" to WebSocket header
let has_hdr = if let Some(hdr) = head.headers.get(&header::UPGRADE) { let has_hdr = if let Some(hdr) = head.headers.get(&header::UPGRADE) {
if let Ok(s) = hdr.to_str() { if let Ok(s) = hdr.to_str() {
s.to_ascii_lowercase().contains("websocket") s.to_ascii_lowercase().contains("websocket")

View File

@ -31,7 +31,7 @@ async fn test_simple() {
.send(h1::Message::Item((res.drop_body(), BodySize::None))) .send(h1::Message::Item((res.drop_body(), BodySize::None)))
.await?; .await?;
// start websocket service // start WebSocket service
let framed = framed.replace_codec(ws::Codec::new()); let framed = framed.replace_codec(ws::Codec::new());
ws::Dispatcher::with(framed, ws_service).await ws::Dispatcher::with(framed, ws_service).await
} }

View File

@ -944,7 +944,7 @@ impl TestServer {
response.body().limit(10_485_760).await response.body().limit(10_485_760).await
} }
/// Connect to websocket server at a given path /// Connect to WebSocket server at a given path.
pub async fn ws_at( pub async fn ws_at(
&mut self, &mut self,
path: &str, path: &str,
@ -954,7 +954,7 @@ impl TestServer {
connect.await.map(|(_, framed)| framed) connect.await.map(|(_, framed)| framed)
} }
/// Connect to a websocket server /// Connect to a WebSocket server.
pub async fn ws( pub async fn ws(
&mut self, &mut self,
) -> Result<Framed<impl AsyncRead + AsyncWrite, ws::Codec>, awc::error::WsClientError> { ) -> Result<Framed<impl AsyncRead + AsyncWrite, ws::Codec>, awc::error::WsClientError> {