poem-web / poem

A full-featured and easy-to-use web framework with the Rust programming language.
Apache License 2.0
3.62k stars 295 forks source link

Allow access to headers in poem::web::Field #906

Open Bednys94 opened 3 weeks ago

Bednys94 commented 3 weeks ago

Description of the feature

Hi, would be possible to access headers for poem::web::Field? Due to limited resources on the device, when handling large file uploads, we need to write the multipart file stream to disk rather than loading it entirely into RAM. Ideally, we would like to make this decision based on the Content-Length header to determine whether the file can be temporarily stored in RAM or should be written directly to disk. However, since headers are private, we are unable to access the Content-Length directly.

Thank you

Code example (if possible)


async fn parse_from_multipart(field: Option<poem::web::Field>) -> ParseResult<Self> {
    match field {
        Some(field) => {
            let content_length = field.headers().get("Content-Length"); // or field.get_header(header::CONTENT_LENGTH)
            // ... rest of code ...
        }
        _ => {
            // Handle None case if necessary
        }
    }
}