http_request/
lib.rs

1//! http-request
2//!
3//! http-request is a lightweight, efficient library for building, sending,
4//! and handling HTTP/HTTPS requests in Rust applications.
5//! It provides a simple and intuitive API, allowing developers to easily
6//! interact with web services, whether they use the "HTTP" or "HTTPS" protocol.
7//! The library supports various HTTP methods, custom headers, request bodies,
8//! timeout, automatic handling of redirects (including detecting redirect loops),
9//! and enhanced response body decoding (both automatic and manual), enabling fast
10//! and secure communication. Whether working with secure "HTTPS" connections
11//! or standard "HTTP" requests, the library is optimized for performance,
12//! minimal resource usage, and easy integration into Rust projects.
13
14pub(crate) mod body;
15pub(crate) mod cfg;
16pub(crate) mod common;
17pub(crate) mod r#const;
18pub(crate) mod request;
19pub(crate) mod response;
20pub(crate) mod utils;
21
22pub use request::*;
23pub use response::*;
24
25pub use http_type::{
26    HashMapXxHash3_64, JsonDeserializer, JsonError, JsonMap, JsonNumber, JsonResult,
27    JsonSerializer, JsonStreamDeserializer, JsonValue, hash_map_xx_hash3_64, json_from_reader,
28    json_from_slice, json_from_str, json_from_value, json_to_string, json_to_string_pretty,
29    json_to_value, json_to_vec, json_to_vec_pretty, json_to_writer, json_to_writer_pretty,
30    json_value,
31};
32
33pub(crate) use body::*;
34pub(crate) use common::*;
35pub(crate) use r#const::*;
36pub(crate) use utils::*;
37
38pub(crate) use futures::{Future, Sink, SinkExt, Stream, StreamExt};
39pub(crate) use http_type::{
40    ACCEPT, ACCEPT_ANY, BR_BYTES, COLON_U8, CONNECTION, CONTENT_LENGTH, CONTENT_TYPE, Compress,
41    ContentType, DEFAULT_BUFFER_SIZE, DEFAULT_HTTP_PATH, DEFAULT_MAX_REDIRECT_TIMES,
42    DEFAULT_TIMEOUT, EMPTY_STR, HOST, HTTP_BR_BYTES, HttpStatus, HttpUrlComponents, HttpVersion,
43    LOCATION, Method, Protocol, QUERY, RequestBody, RequestBodyString, RequestError,
44    RequestHeaders, ResponseHeaders, ResponseStatusCode, SEC_WEBSOCKET_KEY, SEC_WEBSOCKET_VERSION,
45    SPACE_U8, TAB_U8, UPGRADE, USER_AGENT,
46    tokio::{
47        io::{AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt, ReadBuf},
48        net::TcpStream as AsyncTcpStream,
49        runtime::Runtime,
50        sync::{Mutex as AsyncMutex, MutexGuard as AsyncMutexGuard},
51        time::timeout,
52    },
53};
54pub(crate) use rustls::{
55    ClientConfig, ClientConnection, RootCertStore, StreamOwned, pki_types::ServerName,
56};
57pub(crate) use serde::{Serialize, Serializer};
58pub(crate) use std::{
59    borrow::Cow,
60    collections::{HashSet, VecDeque},
61    fmt::{self, Debug, Display, Formatter},
62    io::{Read, Write},
63    net::{Ipv4Addr, Ipv6Addr, TcpStream},
64    pin::Pin,
65    str::from_utf8,
66    sync::{
67        Arc, RwLock,
68        atomic::{AtomicBool, Ordering},
69    },
70    task::{Context, Poll},
71    time::{Duration, SystemTime, UNIX_EPOCH},
72    vec::IntoIter,
73};
74pub(crate) use tokio_rustls::{TlsConnector, client::TlsStream};
75pub(crate) use tokio_tungstenite::{
76    MaybeTlsStream, WebSocketStream, client_async_with_config, connect_async_with_config,
77    tungstenite::Message, tungstenite::handshake::client::Request,
78};
79pub(crate) use webpki_roots::TLS_SERVER_ROOTS;
80
81#[cfg(test)]
82use std::{
83    sync::{Mutex, MutexGuard},
84    thread::{JoinHandle, spawn},
85    time::Instant,
86};
87
88#[cfg(test)]
89use http_type::tokio;