Skip to content

Commit

Permalink
chore: optimized reader.md
Browse files Browse the repository at this point in the history
  • Loading branch information
zavakid committed Feb 9, 2025
1 parent 9259f4a commit 76cac5c
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 16 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ edition = "2021"
homepage = "https://github.com/foldright/micro-http"
license = "MIT OR Apache-2.0"
readme = "README.md"
repository = "https://github.com/foldright/micro-http"

[workspace.dependencies]
http = "1.1.0"
Expand Down
1 change: 1 addition & 0 deletions crates/http/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ authors.workspace = true
edition.workspace = true
homepage.workspace = true
license.workspace = true
repository.workspace = true
readme = "README.md"
keywords = ["http", "async", "web"]
categories = ["web-programming::http-server", "network-programming"]
Expand Down
5 changes: 2 additions & 3 deletions crates/http/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Add this to your `Cargo.toml`:
```toml
[dependencies]
micro-http = "0.1"
tokio = { version = "1", features = ["rt-multi-thread", "net", "io-util", "macros", "sync", "signal", "test-util"] }
tokio = { version = "1", features = ["full"] }
http = "1"
http-body = "1"
tracing = "0.1"
Expand Down Expand Up @@ -107,7 +107,6 @@ async fn simple_handler(request: Request<ReqBody>) -> Result<Response<String>, B

Ok(response)
}

```

## Architecture
Expand All @@ -131,7 +130,7 @@ The implementation focuses on performance through:

## Limitations

- HTTP/1.1 only (HTTP/2 or HTTP/3 not supported)
- HTTP/1.1 only (HTTP/2 or HTTP/3 currently not supported yet)
- No TLS support (use a reverse proxy for HTTPS)
- Maximum header size: 8KB
- Maximum number of headers: 64
Expand Down
5 changes: 3 additions & 2 deletions crates/http/src/codec/header/header_encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::protocol::{PayloadSize, ResponseHead, SendError};

use bytes::{BufMut, BytesMut};

use http::{header, Version};
use http::{header, HeaderValue, Version};
use std::io;
use std::io::{ErrorKind, Write};
use tokio_util::codec::Encoder;
Expand Down Expand Up @@ -86,7 +86,8 @@ impl Encoder<(ResponseHead, PayloadSize)> for HeaderEncoder {
PayloadSize::Empty => match header.headers_mut().get_mut(header::CONTENT_LENGTH) {
Some(value) => *value = 0.into(),
None => {
header.headers_mut().insert(header::CONTENT_LENGTH, 0.into());
const ZERO_VALUE: HeaderValue = HeaderValue::from_static("0");
header.headers_mut().insert(header::CONTENT_LENGTH, ZERO_VALUE);
}
},
}
Expand Down
1 change: 1 addition & 0 deletions crates/web/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ authors.workspace = true
edition.workspace = true
homepage.workspace = true
license.workspace = true
repository.workspace = true
readme = "README.md"
keywords = ["http", "async", "web"]
categories = ["web-programming::http-server", "network-programming"]
Expand Down
15 changes: 4 additions & 11 deletions crates/web/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,6 @@ tokio = { version = "1", features = ["rt-multi-thread", "net", "io-util", "macro
Here's a simple hello world example:

```rust
//! Basic example demonstrating how to create a simple web server using micro_web.
//! This example shows:
//! - How to define route handlers
//! - How to set up a router with middleware
//! - How to configure and start a server

use micro_web::router::{get, Router};
use micro_web::{handler_fn, Server};
use micro_web::date::DateServiceDecorator;
Expand All @@ -56,7 +50,7 @@ async fn main() {
// handler_fn converts our async function into a handler
.route("/", get(handler_fn(hello_world)))
// Add middleware that will add date headers to responses
.with_decorator(DateServiceDecorator)
.with_global_decorator(DateServiceDecorator)
.build();

// Configure and start the server
Expand All @@ -74,7 +68,6 @@ async fn main() {
.start()
.await;
}

```

### Advanced Example
Expand Down Expand Up @@ -189,7 +182,7 @@ async fn main() {
// Additional GET route
.route("/4", get(handler_fn(simple_another_get)))
// Add response encoding wrapper
.with_decorator(EncodeDecorator)
.with_global_decorator(EncodeDecorator)
.build();

// Configure and start the server
Expand Down Expand Up @@ -256,8 +249,8 @@ The framework uses a flexible decorator pattern for middleware:
```rust
// Add multiple decorators
router.builder()
.with_decorator(DateServiceDecorator) // Adds Date header
.with_decorator(CompressionDecorator) // Handles response compression
.with_global_decorator(DateServiceDecorator) // Adds Date header
.with_global_decorator(CompressionDecorator) // Handles response compression
.build();
```

Expand Down

0 comments on commit 76cac5c

Please sign in to comment.