Expand description
Embeddable libfw server: axum routing, bearer-token authorization,
HTTP range handling and streaming upload/download.
§Example
use std::sync::Arc;
use axum::Router;
use libfw_core::auth::{Action, PathValidator, TokenVerifier, Validator};
use libfw_core::claims::{Permission, TokenClaims};
use libfw_server::{router, ServerState};
// 1. Token verifier: parse & verify bearer tokens into claims.
#[derive(Clone)]
struct MyVerifier;
impl TokenVerifier for MyVerifier {
fn verify(&self, token: &str) -> Result<TokenClaims, libfw_core::auth::AuthError> {
Ok(TokenClaims {
sub: token.to_string(),
exp: None,
permissions: vec![Permission::Read, Permission::Write],
allowed_paths: vec!["/".to_string()],
})
}
}
let state = Arc::new(ServerState::builder()
.storage(libfw_server::FsStorage::new("/srv/files"))
.verifier(MyVerifier)
.validator(PathValidator::new())
.build());
let app: Router = router(state);
// ... serve `app` with your preferred hyper/tokio setupStructs§
- Bearer
Claims - Extracts and verifies the
Authorization: Bearer <token>header. - FsSink
- Streaming write handle for the filesystem backend.
- FsStorage
- A
StorageBackendrooted at a local directory. - Server
State - Immutable server configuration shared by all handlers.
- Server
State Builder - Builder for
ServerState.
Enums§
- Auth
Rejection - A request rejection caused by missing/invalid credentials.
- Parsed
Range - A parsed, still-unresolved range request.
- Range
Parse Error - Errors from parsing a
Rangeheader.
Constants§
- HEADER_
COMPRESS - HTTP header advertising the compression algorithm on a body stream.
- HEADER_
FILE_ META - HTTP header carrying JSON-encoded
FileMetafor an upload or download. - HEADER_
FINAL - HTTP header marking an upload request as the FINAL chunk of a file.
- HEADER_
OFFSET - HTTP header carrying the byte offset to resume an interrupted upload.
- HEADER_
SESSION - HTTP header carrying a per-upload session id.
- HEADER_
SESSION_ STATUS - HTTP header turning a session
POSTinto a status probe.
Functions§
- content_
range_ none_ value bytes */totalfor a416 Range Not Satisfiableresponse.- content_
range_ value bytes start-end/total(end inclusive) for aContent-Rangeheader.- etag_
matches_ if_ none_ match - Check
If-None-Matchagainst the current ETag (RFC 9110 §13.1.2). - if_
range_ matches - Check
If-Range(strong ETag form only, RFC 9110 §13.1.5). - parse_
range_ header - Parse a single-range
Rangeheader likebytes=0-499. - router
- Build the axum router with the libfw routes mounted.
- validate_
rel_ path - Normalize and validate a virtual path from the URL.
- ws_
handler - axum route handler for
GET /ws.