mirror of
https://github.com/fafhrd91/actix-web
synced 2024-11-23 16:21:06 +01:00
s/websocket/WebSocket in docs
This commit is contained in:
parent
81bef93e5e
commit
4fc7d76759
@ -243,7 +243,7 @@ impl TestServer {
|
||||
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(
|
||||
&mut self,
|
||||
path: &str,
|
||||
@ -253,7 +253,7 @@ impl TestServer {
|
||||
connect.await.map(|(_, framed)| framed)
|
||||
}
|
||||
|
||||
/// Connect to a websocket server
|
||||
/// Connect to a WebSocket server.
|
||||
pub async fn ws(
|
||||
&mut self,
|
||||
) -> Result<Framed<impl AsyncRead + AsyncWrite, ws::Codec>, awc::error::WsClientError> {
|
||||
|
@ -224,7 +224,7 @@ impl MessageType for Request {
|
||||
let decoder = match length {
|
||||
PayloadLength::Payload(pl) => pl,
|
||||
PayloadLength::UpgradeWebSocket => {
|
||||
// upgrade(websocket)
|
||||
// upgrade (WebSocket)
|
||||
PayloadType::Stream(PayloadDecoder::eof())
|
||||
}
|
||||
PayloadLength::None => {
|
||||
|
@ -54,7 +54,7 @@ pub enum Frame {
|
||||
Close(Option<CloseReason>),
|
||||
}
|
||||
|
||||
/// A `WebSocket` continuation item.
|
||||
/// A WebSocket continuation item.
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub enum Item {
|
||||
FirstText(Bytes),
|
||||
@ -79,7 +79,7 @@ bitflags! {
|
||||
}
|
||||
|
||||
impl Codec {
|
||||
/// Create new websocket frames decoder.
|
||||
/// Create new WebSocket frames decoder.
|
||||
pub fn new() -> Codec {
|
||||
Codec {
|
||||
max_size: 65_536,
|
||||
|
@ -7,7 +7,7 @@ use crate::ws::mask::apply_mask;
|
||||
use crate::ws::proto::{CloseCode, CloseReason, OpCode};
|
||||
use crate::ws::ProtocolError;
|
||||
|
||||
/// A struct representing a `WebSocket` frame.
|
||||
/// A struct representing a WebSocket frame.
|
||||
#[derive(Debug)]
|
||||
pub struct Parser;
|
||||
|
||||
|
@ -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.
|
||||
|
||||
use std::io;
|
||||
@ -76,7 +76,7 @@ pub enum HandshakeError {
|
||||
#[display(fmt = "Method not allowed.")]
|
||||
GetMethodRequired,
|
||||
|
||||
/// Upgrade header if not set to websocket.
|
||||
/// Upgrade header if not set to WebSocket.
|
||||
#[display(fmt = "WebSocket upgrade is expected.")]
|
||||
NoWebsocketUpgrade,
|
||||
|
||||
@ -88,7 +88,7 @@ pub enum HandshakeError {
|
||||
#[display(fmt = "WebSocket version header is required.")]
|
||||
NoVersionHeader,
|
||||
|
||||
/// Unsupported websocket version.
|
||||
/// Unsupported WebSocket version.
|
||||
#[display(fmt = "Unsupported version.")]
|
||||
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> {
|
||||
verify_handshake(req)?;
|
||||
Ok(handshake_response(req))
|
||||
}
|
||||
|
||||
/// Verify `WebSocket` handshake request.
|
||||
/// Verify WebSocket handshake request.
|
||||
pub fn verify_handshake(req: &RequestHead) -> Result<(), HandshakeError> {
|
||||
// WebSocket accepts only GET
|
||||
if req.method != Method::GET {
|
||||
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) {
|
||||
if let Ok(s) = hdr.to_str() {
|
||||
s.to_ascii_lowercase().contains("websocket")
|
||||
@ -181,7 +181,7 @@ pub fn verify_handshake(req: &RequestHead) -> Result<(), HandshakeError> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Create websocket handshake response
|
||||
/// Create WebSocket handshake response.
|
||||
///
|
||||
/// This function returns handshake `Response`, ready to send to peer.
|
||||
pub fn handshake_response(req: &RequestHead) -> ResponseBuilder {
|
||||
|
@ -74,8 +74,7 @@ impl From<u8> for OpCode {
|
||||
}
|
||||
}
|
||||
|
||||
/// Status code used to indicate why an endpoint is closing the `WebSocket`
|
||||
/// connection.
|
||||
/// Status code used to indicate why an endpoint is closing the WebSocket connection.
|
||||
#[derive(Debug, Eq, PartialEq, Clone, Copy)]
|
||||
pub enum CloseCode {
|
||||
/// Indicates a normal closure, meaning that the purpose for
|
||||
|
@ -48,7 +48,7 @@ where
|
||||
///
|
||||
/// 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
|
||||
/// from the websocket request.
|
||||
/// from the WebSocket request.
|
||||
pub fn start_with_addr<A, T>(
|
||||
actor: A,
|
||||
req: &HttpRequest,
|
||||
@ -63,7 +63,7 @@ where
|
||||
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.
|
||||
pub fn start_with_protocols<A, T>(
|
||||
@ -80,7 +80,7 @@ where
|
||||
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.
|
||||
/// It does not perform any IO.
|
||||
@ -88,7 +88,7 @@ pub fn handshake(req: &HttpRequest) -> Result<HttpResponseBuilder, HandshakeErro
|
||||
handshake_with_protocols(req, &[])
|
||||
}
|
||||
|
||||
/// Prepare `WebSocket` handshake response.
|
||||
/// Prepare WebSocket handshake response.
|
||||
///
|
||||
/// This function returns handshake `HttpResponse`, ready to send to peer.
|
||||
/// It does not perform any IO.
|
||||
@ -105,7 +105,7 @@ pub fn handshake_with_protocols(
|
||||
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) {
|
||||
if let Ok(s) = hdr.to_str() {
|
||||
s.to_ascii_lowercase().contains("websocket")
|
||||
|
@ -45,7 +45,7 @@ use crate::http::{ConnectionType, Error as HttpError, Method, StatusCode, Uri, V
|
||||
use crate::response::ClientResponse;
|
||||
use crate::ClientConfig;
|
||||
|
||||
/// `WebSocket` connection
|
||||
/// WebSocket connection.
|
||||
pub struct WebsocketsRequest {
|
||||
pub(crate) head: RequestHead,
|
||||
err: Option<HttpError>,
|
||||
@ -59,7 +59,7 @@ pub struct WebsocketsRequest {
|
||||
}
|
||||
|
||||
impl WebsocketsRequest {
|
||||
/// Create new websocket connection
|
||||
/// Create new WebSocket connection
|
||||
pub(crate) fn new<U>(uri: U, config: Rc<ClientConfig>) -> Self
|
||||
where
|
||||
Uri: TryFrom<U>,
|
||||
@ -102,7 +102,7 @@ impl WebsocketsRequest {
|
||||
self
|
||||
}
|
||||
|
||||
/// Set supported websocket protocols
|
||||
/// Set supported WebSocket protocols
|
||||
pub fn protocols<U, V>(mut self, protos: U) -> Self
|
||||
where
|
||||
U: IntoIterator<Item = V>,
|
||||
@ -239,7 +239,7 @@ impl WebsocketsRequest {
|
||||
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(
|
||||
mut self,
|
||||
) -> Result<(ClientResponse, Framed<BoxedSocket, Codec>), WsClientError> {
|
||||
@ -338,7 +338,7 @@ impl WebsocketsRequest {
|
||||
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) {
|
||||
if let Ok(s) = hdr.to_str() {
|
||||
s.to_ascii_lowercase().contains("websocket")
|
||||
|
@ -31,7 +31,7 @@ async fn test_simple() {
|
||||
.send(h1::Message::Item((res.drop_body(), BodySize::None)))
|
||||
.await?;
|
||||
|
||||
// start websocket service
|
||||
// start WebSocket service
|
||||
let framed = framed.replace_codec(ws::Codec::new());
|
||||
ws::Dispatcher::with(framed, ws_service).await
|
||||
}
|
||||
|
@ -944,7 +944,7 @@ impl TestServer {
|
||||
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(
|
||||
&mut self,
|
||||
path: &str,
|
||||
@ -954,7 +954,7 @@ impl TestServer {
|
||||
connect.await.map(|(_, framed)| framed)
|
||||
}
|
||||
|
||||
/// Connect to a websocket server
|
||||
/// Connect to a WebSocket server.
|
||||
pub async fn ws(
|
||||
&mut self,
|
||||
) -> Result<Framed<impl AsyncRead + AsyncWrite, ws::Codec>, awc::error::WsClientError> {
|
||||
|
Loading…
Reference in New Issue
Block a user