-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat:7.0.0 struct update�[D�[D�[D�[D�[D�[D�[C�[C�[C�[C�[C�[C�[C�[C�[C…
…and add decode response
- Loading branch information
1 parent
abcf845
commit e9ddabb
Showing
65 changed files
with
784 additions
and
634 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,16 @@ | ||
[package] | ||
name = "http-request" | ||
version = "6.0.2" | ||
version = "7.0.0" | ||
edition = "2021" | ||
authors = ["ltpp-universe <[email protected]>"] | ||
license = "MIT" | ||
description = """http_request is a lightweight, efficient library for building, sending, and handling HTTP/HTTPS requests in Rust applications. It provides a simple and intuitive API, allowing developers to easily interact with web services, whether they use the "HTTP" or "HTTPS" protocol. The library supports various HTTP methods, custom headers, request bodies, and automatic handling of redirects (including detecting redirect loops), enabling fast and secure communication. Whether working with secure "HTTPS" connections or standard "HTTP" requests, the library is optimized for performance, minimal resource usage, and easy integration into Rust projects.""" | ||
description = """http-request is a lightweight, efficient library for building, sending, and handling HTTP/HTTPS requests in Rust applications. It provides a simple and intuitive API, allowing developers to easily interact with web services, whether they use the "HTTP" or "HTTPS" protocol. The library supports various HTTP methods, custom headers, request bodies, timeout, automatic handling of redirects (including detecting redirect loops), and enhanced response body decoding (both automatic and manual), enabling fast and secure communication. Whether working with secure "HTTPS" connections or standard "HTTP" requests, the library is optimized for performance, minimal resource usage, and easy integration into Rust projects.""" | ||
keywords = ["http", "request", "response", "tcp", "redirect"] | ||
repository = "https://github.com/ltpp-universe/http-request.git" | ||
|
||
[dependencies] | ||
brotli = "7.0.0" | ||
flate2 = "1.0.35" | ||
hex = "0.4.3" | ||
native-tls = "0.2.12" | ||
serde = { version = "1.0", features = ["derive"] } | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,74 +1,36 @@ | ||
use super::r#type::Body; | ||
use serde::{Serialize, Serializer}; | ||
use std::fmt::{self}; | ||
use std::fmt::{self, Display}; | ||
|
||
/// Represents the body of a request or response, which can be either plain text, JSON, or binary data. | ||
impl Default for Body { | ||
/// Provides a default implementation for the `Body` enum. | ||
/// | ||
/// Returns a `Body::Text` variant with an empty string as the default body. | ||
fn default() -> Self { | ||
Self::Text("") | ||
} | ||
} | ||
|
||
/// Implements the `fmt::Display` trait for the `Body` enum. | ||
/// | ||
/// This trait is responsible for providing a human-readable representation of the body: | ||
/// - For the `Text` variant, the contained text is displayed. | ||
/// - For the `Json` variant, the JSON is serialized to a string. If serialization fails, | ||
/// an empty JSON object (`{}`) is displayed. | ||
/// - For the `Binary` variant, the binary data is displayed in a debug format. | ||
impl fmt::Display for Body { | ||
/// Formats the `Body` instance for user-friendly display. | ||
/// | ||
/// # Parameters | ||
/// - `f`: A mutable reference to the formatter. | ||
/// | ||
/// # Returns | ||
/// A `Result` indicating whether the formatting was successful. The result is | ||
/// `fmt::Result` which is either `Ok` or an error. | ||
impl Display for Body { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
match self { | ||
Body::Text(text) => write!(f, "{}", text.to_string()), | ||
Body::Json(json) => write!( | ||
Self::Text(text) => write!(f, "{}", text.to_string()), | ||
Self::Json(json) => write!( | ||
f, | ||
"{:?}", | ||
serde_json::to_string(json).unwrap_or_else(|_| String::from("{}")) | ||
), | ||
Body::Binary(binary) => write!(f, "{:?}", binary), | ||
Self::Binary(binary) => write!(f, "{:?}", binary), | ||
} | ||
} | ||
} | ||
|
||
/// Implements the `Serialize` trait for the `Body` enum. | ||
/// | ||
/// This trait enables the serialization of the `Body` enum into different formats using | ||
/// the `serde` framework: | ||
/// - The `Text` variant is serialized as a plain string. | ||
/// - The `Json` variant is serialized using the provided `serde` serializer. | ||
/// - The `Binary` variant is serialized as binary data. | ||
impl Serialize for Body { | ||
/// Serializes the `Body` instance into the given serializer. | ||
/// | ||
/// # Type Parameters | ||
/// - `S`: The serializer type implementing the `Serializer` trait. | ||
/// | ||
/// # Parameters | ||
/// - `serializer`: The serializer used for serialization, which will handle | ||
/// the transformation of the `Body` into the target format. | ||
/// | ||
/// # Returns | ||
/// A `Result` containing either the successfully serialized output or an error. | ||
/// If successful, it returns `S::Ok`; if an error occurs, it returns `S::Error`. | ||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> | ||
where | ||
S: Serializer, | ||
{ | ||
match self { | ||
Body::Text(text) => text.serialize(serializer), | ||
Body::Json(json) => json.serialize(serializer), | ||
Body::Binary(binary) => binary.serialize(serializer), | ||
Self::Text(text) => text.serialize(serializer), | ||
Self::Json(json) => json.serialize(serializer), | ||
Self::Binary(binary) => binary.serialize(serializer), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.