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