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    string::FromUtf8Error,
41    sync::{
42        Arc, RwLock, RwLockReadGuard,
43        atomic::{AtomicBool, Ordering},
44    },
45    task::{Context, Poll},
46    time::{Duration, SystemTime, UNIX_EPOCH},
47    vec::IntoIter,
48};
49
50use {
51    futures::{Future, Sink, SinkExt, Stream, StreamExt},
52    http_type::{
53        ACCEPT, ACCEPT_ANY, BR_BYTES, COLON_U8, CONNECTION, CONTENT_LENGTH, CONTENT_TYPE, Compress,
54        ContentType, DEFAULT_BUFFER_SIZE, DEFAULT_HIGH_SECURITY_READ_TIMEOUT_MS, DEFAULT_HTTP_PATH,
55        DEFAULT_MAX_REDIRECT_TIMES, EMPTY_STR, HOST, HTTP_BR_BYTES, HttpStatus, HttpUrlComponents,
56        HttpVersion, LOCATION, Method, Protocol, QUERY, RequestBody, RequestBodyString,
57        RequestHeaders, ResponseHeaders, ResponseStatusCode, SEC_WEBSOCKET_KEY,
58        SEC_WEBSOCKET_VERSION, SPACE_U8, TAB_U8, UPGRADE, USER_AGENT,
59        tokio::{
60            io::{AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt, ReadBuf},
61            runtime::Runtime,
62            sync::Mutex,
63            time::timeout,
64        },
65    },
66    rustls::{
67        ClientConfig, ClientConnection, RootCertStore, StreamOwned,
68        pki_types::{InvalidDnsNameError, ServerName},
69    },
70    serde::{Serialize, Serializer},
71    tokio_rustls::{TlsConnector, client::TlsStream},
72    tokio_tungstenite::{
73        MaybeTlsStream, WebSocketStream, client_async_with_config, connect_async_with_config,
74        tungstenite::Message, tungstenite::handshake::client::Request,
75    },
76    webpki_roots::TLS_SERVER_ROOTS,
77};