diff --git a/README.md b/README.md index 42fb99c519e560e538ccd5b108ca655a31f4ef22..789401b6ff767820c4925fb5a0c7590834a683f1 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,16 @@ `ylong_http` has built a complete HTTP capability, supporting users to use HTTP capability to meet the needs of communication scenarios. -`ylong_http` is written in Rust. +`ylong_http` provides HTTP protocol support to the network subsystem in the +`OpenHarmony` system service layer, and through the network subsystem, helps +upper layer applications recommend HTTP communication capabilities. + +`ylong_http` is written in the Rust language to support OpenHarmony's Rust +capability. + +## Structure + +![structure](./figures/structure.png) ### ylong_http_client crate diff --git a/README_zh.md b/README_zh.md index 5b2467213fed0d521d410140adc5360761a966d5..09149431703b969ee1f27fdb4421c5e202c618f2 100644 --- a/README_zh.md +++ b/README_zh.md @@ -4,12 +4,17 @@ ylong_http 协议栈构建了完整的 HTTP 能力,支持用户使用 HTTP 能力完成通信场景的需求。 -ylong_http 协议栈主体使用 Rust 语言编写。 +ylong_http 向 OpenHarmony 系统服务层中的网络子系统提供 HTTP 协议支持,经由网络子系统帮助上层应用建议 HTTP 通信能力。 + +ylong_http 协议栈主体使用 Rust 语言编写,为 OpenHarmony 的 Rust 能力构筑提供支持。 + +## 架构图 + +![structure](./figures/structure.png) ### ylong_http_client 库 -ylong_http_client 库支持 HTTP 客户端功能,支持用户创建 HTTP 客户端向指定 Server 发送 HTTP -请求。 +ylong_http_client 库支持 HTTP 客户端功能,支持用户创建 HTTP 客户端向指定 Server 发送 HTTP 请求。 当前 ylong_http_client 库支持的功能: diff --git a/figures/structure.png b/figures/structure.png new file mode 100644 index 0000000000000000000000000000000000000000..e4ed6e20a20644a38b54e27f0850552d70b4dfb7 Binary files /dev/null and b/figures/structure.png differ diff --git a/ylong_http/Cargo.toml b/ylong_http/Cargo.toml index 113c797de637b6b01ded3725c02653fe94a502c0..d6cb5dffb3fbd2ef9e51ea5e5ab9716179742a55 100644 --- a/ylong_http/Cargo.toml +++ b/ylong_http/Cargo.toml @@ -1,11 +1,10 @@ [package] name = "ylong_http" -version = "1.9.0" -edition = "2018" -description = "HTTP implementation" -readme = "README.md" +version = "1.0.0" +edition = "2021" +description = "HTTP utility implementation" license = "Apache-2.0" -repository = "https://open.codehub.huawei.com/innersource/Ylong_Rust/ylong_rs/files?ref=master&filePath=src%2Fweb%2Fylong_http" +repository = "https://gitee.com/openharmony-sig/commonlibrary_rust_ylong_http" keywords = ["ylong", "http"] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/ylong_http/README.md b/ylong_http/README.md deleted file mode 100644 index 2c0d6a6123f2d9015c940efaf778d1a47619ebf2..0000000000000000000000000000000000000000 --- a/ylong_http/README.md +++ /dev/null @@ -1,85 +0,0 @@ -# ylong_http - -## 简介 - -ylong_http 提供了 HTTP 各个版本下的协议所需的各种基础组件和扩展组件,方便用户组织所需的 HTTP 结构。 - -ylong_http 包含以下核心功能: - -### Request 和 Response - -ylong_http 使用 `Request` 和 `Response` 结构来表示 HTTP 最基础的请求和响应: - -- `Request`:HTTP 请求,包含 `Method`、`Uri`、`Headers`、`Body` 等。 - -- `Response`:HTTP 响应,包含 `StatusCode`、`Version`、`Headers`、`Body `等。 - -用户可以使用 `Request` 和 `Response` 提供的相关方法来获取相关信息,或是自定义请求和响应。 - - - -### Body - -对于`Request`和`Response`的 Body 部分,ylong_http 提供了 `Body` trait,方便用户自定义想要的 Body 结构。 - -为了区分 Body 结构所处在同步还是异步上下文,ylong_http 声明了 `sync_impl::Body` trait 和 `async_impl::Body` trait,使用 mod 进行隔离: - -- `sync_impl::Body` :该 trait 使用同步方法,可以在同步上下文使用。 -- `async_impl::Body`:该 trait 使用异步方法,可以在异步上下文使用。 - -用户可以根据自身需要,选择合适的 `Body` trait 进行实现,也可以两种都实现。 - -ylong_http 也提供默认的 Body 结构供用户使用: - -- `EmptyBody`:空的 Body 结构。 -- `TextBody`:明文的 Body 结构,支持用户传入内存数据或是 IO 数据。 -- `ChunkBody`:分段的 Body 结构,支持用户自定义 Chunk 大小,支持传入内存数据或是 IO 数据。 -- `MimeBody`:MIME 格式的 Body 结构,支持用户使用 MIME 格式设置 Body,支持传入内存数据或是 IO 数据。 - -对应的,也提供了几种 Body 类型的读取器: - -- `TextBodyDecoder`:用于解析明文 Body。 -- `ChunkBodyDecoder`:用于解析分段 Body。 -- `MimeBodyDecoder`:用于解析 MIME 格式的 Body。 - - - -### 其他组件 - -ylong_http 提供了以下几个 HTTP 版本的相关组件: - -- HTTP/1.1:提供了 `RequestEncoder`、`ResponseDecoder` 等。 -- HTTP/2:`DynamicTable`、`StaticTable`、`FrameDecoder`、`FrameEncoder` 等。 -- HTTP/3:`FrameDecoder`、`FrameEncoder` 等。 - - - -## 编译构建 - -在 ```Cargo.toml``` 下添加依赖。添加后使用 ```cargo``` 进行编译和构建: - -```toml -[dependencies] -ylong_http = { path = "/example_path/ylong_http" } # 请使用路径依赖 -``` - - - -## 目录 - -``` -ylong_http -├── examples # ylong_http 代码示例 -├── src -│ ├── body # Body trait 定义和扩展 Body 类型。 -│ ├── h1 # HTTP/1.1 相关组件实现。 -│ ├── h2 # HTTP/2 相关组件实现。 -│ ├── h2 # HTTP/3 相关组件实现。 -│ ├── huffman # Huffman 编解码实现。 -│ ├── request # Request 定义和实现。 -│ └── response # Response 定义和实现。 -└── tests # 测试目录 -``` - - - diff --git a/ylong_http_client/Cargo.toml b/ylong_http_client/Cargo.toml index 64946a48df8e57fa11598712d1363b705d7f9339..56cec58707178f6964b1b2548fe59cdd9025f17a 100644 --- a/ylong_http_client/Cargo.toml +++ b/ylong_http_client/Cargo.toml @@ -1,17 +1,16 @@ [package] name = "ylong_http_client" -version = "1.9.0" -edition = "2018" -description = "http client" -readme = "README.md" +version = "1.0.0" +edition = "2021" +description = "Ylong HTTP Client implementation" license = "Apache-2.0" -repository = "https://open.codehub.huawei.com/innersource/Ylong_Rust/ylong_rs/files?ref=master&filePath=src%2Fweb%2Fylong_http_client" +repository = "https://gitee.com/openharmony-sig/commonlibrary_rust_ylong_http" keywords = ["ylong", "http", "client"] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -ylong_http = { path = "../ylong_http", version = "1.9.0", features = ["full"] } +ylong_http = { path = "../ylong_http", features = ["full"] } libc = { version = "0.2.134", optional = true } tokio = { version = "1.20.1", features = ["io-util", "net", "rt", "rt-multi-thread", "macros", "sync", "time"], optional = true } # ylong_runtime = { path = "../runtime/ylong_runtime", features = ["net", "sync", "fs", "macros", "time"], optional = true } @@ -31,20 +30,20 @@ full = [ "tls_default", ] -sync = [] # Uses sync interfaces. -async = [] # Uses async interfaces. -http1_1 = ["ylong_http/http1_1"] # Uses HTTP/1.1. -http2 = ["ylong_http/http2"] # Uses HTTP/2. -http3 = [] # Uses HTTP/3. +sync = [] # Uses sync interfaces. +async = [] # Uses async interfaces. +http1_1 = ["ylong_http/http1_1"] # Uses HTTP/1.1. +http2 = ["ylong_http/http2"] # Uses HTTP/2. +http3 = [] # Uses HTTP/3. -tokio_base = ["tokio"] # Uses tokio runtime. -ylong_base = [] # Uses ylong runtime. +tokio_base = ["tokio"] # Uses tokio runtime. +ylong_base = [] # Uses ylong runtime. tls_default = ["c_openssl_3_0"] -__tls = [] # Not open to user, only mark to use tls for developer. -__c_openssl = ["__tls", "libc"] # Not open to user, only mark to use tls by C-openssl for developer. -c_openssl_1_1 = ["__c_openssl"] # Uses TLS by FFI of C-openssl 1.1. -c_openssl_3_0 = ["__c_openssl"] # Uses TLS by FFI of C-openssl 3.0. +__tls = [] # Not open to user, only mark to use tls for developer. +__c_openssl = ["__tls", "libc"] # Not open to user, only mark to use tls by C-openssl for developer. +c_openssl_1_1 = ["__c_openssl"] # Uses TLS by FFI of C-openssl 1.1. +c_openssl_3_0 = ["__c_openssl"] # Uses TLS by FFI of C-openssl 3.0. [[example]] name = "async_http" diff --git a/ylong_http_client/README.md b/ylong_http_client/README.md deleted file mode 100644 index 9c7e55318a4ff680404dc961bda31e9095886717..0000000000000000000000000000000000000000 --- a/ylong_http_client/README.md +++ /dev/null @@ -1,40 +0,0 @@ -# ylong_http_client - -## 简介 - -ylong_http_client 支持用户构建 HTTP 客户端,支持用户使用该客户端向服务器发送请求,接收并解析服务器返回的响应。 - -### Client - -ylong_http_client 支持用户创建同步或者异步 HTTP 客户端,用户可以使用 mod 区分两种客户端。 - -- `sync_impl::Client`:同步 HTTP 客户端,整体流程使用同步接口。 - -- `async_impl::Client`:异步 HTTP 客户端,整体流程使用异步接口。 - -不论是同步还是异步客户端,都具有相同的功能,例如:连接复用、自动重定向、自动重试、设置代理等功能。 - -ylong_http_client 创建的客户端支持以下 HTTP 版本: - -- `HTTP/1.1` - -- `HTTP/2` - -- `HTTP/3` - -### Request 和 Response - -ylong_http_client 使用 ylong_http 库提供的 `Request` 结构,支持用户自定义请求内容。 - -在使用客户端发送完请求后,接收到的响应会以 ylong_http 库提供的 `Response` + `HttpBody` 的结构返回。 - -用户可以使用 `Response` 提供的接口来获取请求信息,并且可以使用 ylong_http 提供的 `Body` trait 读取响应的内容。用户也可以使用 ylong_http_client 提供的 `BodyReader` 读取内容。 - -## 编译构建 - -在 ```Cargo.toml``` 下添加依赖。添加后使用 ```cargo``` 进行编译和构建: - -```toml -[dependencies] -ylong_http_client = { path = "/example_path/ylong_http_client" } # 请使用路径依赖 -``` \ No newline at end of file