Skip to main content

http_request/
lib.rs

1//! http-request
2//!
3//! An HTTP request library providing client-side HTTP request construction and response parsing.
4
5mod common;
6mod pool;
7mod protocol;
8mod request;
9mod response;
10mod tls;
11mod utils;
12
13#[cfg(test)]
14#[path = "../tests/mod.rs"]
15mod tests;
16
17pub use {request::*, response::*};
18
19pub use http_type::{
20    ACCEPT, ACCEPT_ANY, BR_BYTES, COLON_U8, CONTENT_LENGTH, CONTENT_TYPE, Compress, ContentType,
21    HOST, HTTP_BR_BYTES, HTTPS_LOWERCASE, HashMapXxHash3_64, HttpStatus, HttpUrlComponents,
22    HttpVersion, LOCATION, Method, Protocol, QUERY, RequestError, RequestHeadersKey,
23    RequestHeadersValue, ResponseStatusCode, SPACE_U8, TAB_U8, USER_AGENT, hash_map_xx_hash3_64,
24};
25
26pub use std::{
27    cmp,
28    collections::{HashMap, HashSet, VecDeque},
29    fmt::{self, Debug, Display, Formatter},
30    io::{self, Read, Write},
31    mem,
32    net::{Ipv4Addr, Ipv6Addr, TcpStream},
33    pin::Pin,
34    str::from_utf8,
35    string::FromUtf8Error,
36    sync::Arc,
37    task::{Context, Poll},
38    time::Duration,
39    vec::IntoIter,
40};
41
42pub use {
43    http_type::tokio::io::{AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt, ReadBuf},
44    rustls::{
45        ClientConfig, ClientConnection, Error, RootCertStore, StreamOwned,
46        pki_types::{InvalidDnsNameError, ServerName},
47    },
48    serde::Serialize,
49    serde_json::to_vec,
50    tokio_rustls::{TlsConnector, client::TlsStream},
51    webpki_roots::TLS_SERVER_ROOTS,
52};
53
54pub use common::*;
55pub use lombok_macros::*;
56
57pub(crate) use {pool::*, protocol::*, tls::*};
58
59use std::{
60    cell::{RefCell, RefMut},
61    net::{SocketAddr, ToSocketAddrs},
62    sync::{Mutex, OnceLock},
63    thread,
64    time::Instant,
65};
66
67use {
68    bytes::Bytes,
69    h2::{RecvStream, client::SendRequest},
70    http::{HeaderName, HeaderValue, Request, Response, StatusCode, Uri, request::Builder},
71    http_type::{
72        BodyPart, CLOSE, CONNECTION, COOKIE, CookieBuilder, Cookies, KEEP_ALIVE, SET_COOKIE, tokio,
73    },
74    rustls::client::Resumption,
75    rustls_pki_types::{CertificateDer, pem::PemObject},
76    serde::de::DeserializeOwned,
77    serde_json::from_slice,
78};