Fix Gemini protocol status codes and error handling
- Path security violations now return 51 (Not Found) instead of 59 (Bad Request) - Timeouts return 41 (Server Unavailable) per Gemini spec - Add comprehensive request validation: empty requests, oversized requests (>1024 bytes), malformed URLs - Fix CLI argument conflict (config -c vs cert -c) - Update documentation with status codes, error handling guidelines, and lint checking - Add environment setup instructions for clippy and cargo PATH
This commit is contained in:
parent
2347c04211
commit
9d29321806
5 changed files with 166 additions and 62 deletions
36
AGENTS.md
36
AGENTS.md
|
|
@ -11,7 +11,9 @@ nothing else. It is meant to be generic so other people can use it.
|
|||
- `cargo test` - Run all unit tests
|
||||
- `cargo test <test_name>` - Run a specific test
|
||||
- `cargo test <module>::tests` - Run tests in a specific module
|
||||
- `cargo clippy` - Run linter checks
|
||||
- `cargo clippy` - Run linter checks for code quality
|
||||
- `cargo clippy --fix` - Automatically fix clippy suggestions
|
||||
- `cargo clippy --bin <name>` - Check specific binary
|
||||
- `cargo fmt` - Format code according to Rust standards
|
||||
- `cargo check` - Quick compile check without building
|
||||
|
||||
|
|
@ -64,6 +66,16 @@ nothing else. It is meant to be generic so other people can use it.
|
|||
- Test security boundaries (path traversal, invalid inputs)
|
||||
- Use `assert_eq!` and `assert!` for validations
|
||||
|
||||
## Lint Checking
|
||||
- `cargo clippy` - Run linter checks for code quality
|
||||
- `cargo clippy --fix` - Automatically fix clippy suggestions
|
||||
- `cargo clippy --bin <name>` - Check specific binary
|
||||
- `cargo fmt` - Format code to match Rust standards
|
||||
- **Run clippy before every commit** - Address all warnings before pushing code
|
||||
- Current clippy warnings (2025-01-15):
|
||||
- src/server.rs:16-17 - Unnecessary borrows on file_path
|
||||
- src/logging.rs:31 - Match could be simplified to let statement
|
||||
|
||||
## Async Patterns
|
||||
- Use `.await` on async calls
|
||||
- Prefer `tokio::fs` over `std::fs` in async contexts
|
||||
|
|
@ -73,11 +85,24 @@ nothing else. It is meant to be generic so other people can use it.
|
|||
## Gemini Protocol Specific
|
||||
- Response format: "STATUS META\r\n"
|
||||
- Status 20: Success (follow with MIME type)
|
||||
- Status 51: Not found
|
||||
- Status 59: Bad request
|
||||
- Status 41: Server unavailable (timeout, overload)
|
||||
- Status 51: Not found (resource doesn't exist)
|
||||
- Status 59: Bad request (malformed URL, protocol violation)
|
||||
- Default MIME: "text/gemini" for .gmi files
|
||||
- Default file: "index.gmi" for directory requests
|
||||
|
||||
## Error Handling
|
||||
- **Timeout**: Return status 41 "Server unavailable" (not 59)
|
||||
- **Request too large**: Return status 59 "Bad request"
|
||||
- **Empty request**: Return status 59 "Bad request"
|
||||
- **Invalid URL format**: Return status 59 "Bad request"
|
||||
- **Hostname mismatch**: Return status 59 "Bad request"
|
||||
- **Path resolution failure**: Return status 51 "Not found" (including security violations)
|
||||
- **File not found**: Return status 51 "Not found"
|
||||
- Reject requests > 1024 bytes (per Gemini spec)
|
||||
- Reject requests without proper `\r\n` termination
|
||||
- Use `tokio::time::timeout()` for request timeout handling
|
||||
|
||||
## Configuration
|
||||
- TOML config files with `serde::Deserialize`
|
||||
- CLI args override config file values
|
||||
|
|
@ -94,3 +119,8 @@ nothing else. It is meant to be generic so other people can use it.
|
|||
- Default port: 1965 (standard Gemini port)
|
||||
- Default host: 0.0.0.0 for listening
|
||||
- Log level defaults to "info"
|
||||
|
||||
## Environment Setup
|
||||
- Install clippy: `rustup component add clippy`
|
||||
- Ensure `~/.cargo/bin` is in PATH (add `source "$HOME/.cargo/env"` to `~/.bashrc`)
|
||||
- Verify setup: `cargo clippy --version`
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue