1
0
mirror of https://github.com/fafhrd91/actix-web synced 2024-11-28 18:02:39 +01:00
actix-web/actix-http/src/h1/mod.rs

86 lines
1.7 KiB
Rust
Raw Normal View History

2018-10-05 05:02:10 +02:00
//! HTTP/1 implementation
2019-04-02 20:11:32 +02:00
use bytes::{Bytes, BytesMut};
mod client;
2018-10-05 05:02:10 +02:00
mod codec;
mod decoder;
mod dispatcher;
2018-10-05 19:03:10 +02:00
mod encoder;
2019-04-06 01:46:44 +02:00
mod expect;
mod payload;
2018-10-05 05:02:10 +02:00
mod service;
2019-04-08 23:51:16 +02:00
mod upgrade;
mod utils;
2018-10-05 05:02:10 +02:00
pub use self::client::{ClientCodec, ClientPayloadCodec};
pub use self::codec::Codec;
2018-10-05 05:02:10 +02:00
pub use self::dispatcher::Dispatcher;
2019-04-06 01:46:44 +02:00
pub use self::expect::ExpectHandler;
2019-04-07 19:29:26 +02:00
pub use self::payload::Payload;
2018-10-16 01:46:13 +02:00
pub use self::service::{H1Service, H1ServiceHandler, OneRequest};
2019-04-08 23:51:16 +02:00
pub use self::upgrade::UpgradeHandler;
pub use self::utils::SendResponse;
#[derive(Debug)]
/// Codec message
pub enum Message<T> {
/// Http message
Item(T),
/// Payload chunk
Chunk(Option<Bytes>),
}
impl<T> From<T> for Message<T> {
fn from(item: T) -> Self {
Message::Item(item)
}
}
/// Incoming request type
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum MessageType {
None,
Payload,
2018-11-14 07:53:30 +01:00
Stream,
}
2018-11-06 04:32:03 +01:00
2019-04-02 20:11:32 +02:00
const LW: usize = 2 * 1024;
const HW: usize = 32 * 1024;
pub(crate) fn reserve_readbuf(src: &mut BytesMut) {
let cap = src.capacity();
if cap < LW {
src.reserve(HW - cap);
}
}
2018-11-06 04:32:03 +01:00
#[cfg(test)]
mod tests {
use super::*;
2019-03-07 07:56:34 +01:00
use crate::request::Request;
2018-11-06 04:32:03 +01:00
impl Message<Request> {
pub fn message(self) -> Request {
match self {
Message::Item(req) => req,
_ => panic!("error"),
}
}
pub fn chunk(self) -> Bytes {
match self {
Message::Chunk(Some(data)) => data,
_ => panic!("error"),
}
}
pub fn eof(self) -> bool {
match self {
Message::Chunk(None) => true,
Message::Chunk(Some(_)) => false,
_ => panic!("error"),
}
}
}
}