Skip to main content

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
14mod common;
15mod request;
16mod response;
17mod utils;
18
19pub use {request::*, response::*};
20
21pub use {
22    http_type::{HashMapXxHash3_64, RequestError, hash_map_xx_hash3_64},
23    serde_json::{
24        Deserializer, Error, Map, Number, StreamDeserializer, Value, from_reader, from_slice,
25        from_str, from_value, to_string, to_string_pretty, to_value, to_vec, to_vec_pretty,
26        to_writer, to_writer_pretty, value,
27    },
28};
29
30use {common::*, utils::*};
31
32use std::{
33    borrow::Cow,
34    collections::{HashSet, VecDeque},
35    fmt::{self, Debug, Display, Formatter},
36    io::{Read, Write},
37    net::{Ipv4Addr, Ipv6Addr, TcpStream},
38    pin::Pin,
39    str::from_utf8,
40    sync::{
41        Arc, RwLock,
42        atomic::{AtomicBool, Ordering},
43    },
44    task::{Context, Poll},
45    time::{Duration, SystemTime, UNIX_EPOCH},
46    vec::IntoIter,
47};
48
49use {
50    futures::{Future, Sink, SinkExt, Stream, StreamExt},
51    http_type::{
52        ACCEPT, ACCEPT_ANY, BR_BYTES, COLON_U8, CONNECTION, CONTENT_LENGTH, CONTENT_TYPE, Compress,
53        ContentType, DEFAULT_BUFFER_SIZE, DEFAULT_HIGH_SECURITY_READ_TIMEOUT_MS, DEFAULT_HTTP_PATH,
54        DEFAULT_MAX_REDIRECT_TIMES, EMPTY_STR, HOST, HTTP_BR_BYTES, HttpStatus, HttpUrlComponents,
55        HttpVersion, LOCATION, Method, Protocol, QUERY, RequestBody, RequestBodyString,
56        RequestHeaders, ResponseHeaders, ResponseStatusCode, SEC_WEBSOCKET_KEY,
57        SEC_WEBSOCKET_VERSION, SPACE_U8, TAB_U8, UPGRADE, USER_AGENT,
58        tokio::{
59            io::{AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt, ReadBuf},
60            net::TcpStream as AsyncTcpStream,
61            runtime::Runtime,
62            sync::{Mutex as AsyncMutex, MutexGuard as AsyncMutexGuard},
63            time::timeout,
64        },
65    },
66    rustls::{ClientConfig, ClientConnection, RootCertStore, StreamOwned, pki_types::ServerName},
67    serde::{Serialize, Serializer},
68    tokio_rustls::{TlsConnector, client::TlsStream},
69    tokio_tungstenite::{
70        MaybeTlsStream, WebSocketStream, client_async_with_config, connect_async_with_config,
71        tungstenite::Message, tungstenite::handshake::client::Request,
72    },
73    webpki_roots::TLS_SERVER_ROOTS,
74};