Skip to main content

Crate libfw_server

Crate libfw_server 

Source
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 setup

Structs§

BearerClaims
Extracts and verifies the Authorization: Bearer <token> header.
FsSink
Streaming write handle for the filesystem backend.
FsStorage
A StorageBackend rooted at a local directory.
ServerState
Immutable server configuration shared by all handlers.
ServerStateBuilder
Builder for ServerState.

Enums§

AuthRejection
A request rejection caused by missing/invalid credentials.
ParsedRange
A parsed, still-unresolved range request.
RangeParseError
Errors from parsing a Range header.

Constants§

HEADER_COMPRESS
HTTP header advertising the compression algorithm on a body stream.
HEADER_FILE_META
HTTP header carrying JSON-encoded FileMeta for 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 POST into a status probe.

Functions§

content_range_none_value
bytes */total for a 416 Range Not Satisfiable response.
content_range_value
bytes start-end/total (end inclusive) for a Content-Range header.
etag_matches_if_none_match
Check If-None-Match against 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 Range header like bytes=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.