| 1 | # http-content-range |
| 2 | |
| 3 | [](https://github.com/nyurik/http-content-range) |
| 4 | [](https://crates.io/crates/http-content-range) |
| 5 | [](https://crates.io/crates/http-content-range) |
| 6 | [](https://docs.rs/http-content-range) |
| 7 | [](https://github.com/nyurik/http-content-range/blob/main/LICENSE-APACHE) |
| 8 | [](https://github.com/nyurik/http-content-range/actions) |
| 9 | [](https://app.codecov.io/gh/nyurik/http-content-range) |
| 10 | |
| 11 | Tiny Rust lib to decode Content-Range response headers. |
| 12 | |
| 13 | ```rust |
| 14 | use http_content_range::ContentRange; |
| 15 | |
| 16 | let value = ContentRange::parse("bytes 42-69/420"); |
| 17 | |
| 18 | match value.expect("Failed to parse Content-Range") { |
| 19 | ContentRange::Bytes(r) => { |
| 20 | println!( |
| 21 | "First_byte={}, last_byte={}, complete_length={}", |
| 22 | r.first_byte, r.last_byte, r.complete_length, |
| 23 | ); |
| 24 | } |
| 25 | ContentRange::UnboundBytes(r) => { |
| 26 | println!( |
| 27 | "First_byte={}, last_byte={}, complete_length is unknown", |
| 28 | r.first_byte, r.last_byte |
| 29 | ); |
| 30 | } |
| 31 | ContentRange::Unsatisfied(r) => { |
| 32 | println!( |
| 33 | "Unsatisfied response, complete_length={}", |
| 34 | r.complete_length |
| 35 | ); |
| 36 | } |
| 37 | }; |
| 38 | ``` |
| 39 | |
| 40 | ## Development |
| 41 | |
| 42 | * This project is easier to develop with [just](https://github.com/casey/just#readme), a modern alternative to `make`. |
| 43 | Install it with `cargo install just`. |
| 44 | * To get a list of available commands, run `just`. |
| 45 | * To run tests, use `just test`. |
| 46 | |
| 47 | ## Credits |
| 48 | |
| 49 | The code was inspired by the [rust-http-range](https://github.com/bancek/rust-http-range) crate. |
| 50 | |
| 51 | ## License |
| 52 | |
| 53 | Licensed under either of |
| 54 | |
| 55 | * Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or <https://www.apache.org/licenses/LICENSE-2.0>) |
| 56 | * MIT license ([LICENSE-MIT](LICENSE-MIT) or <https://opensource.org/licenses/MIT>) |
| 57 | at your option. |
| 58 | |
| 59 | ### Contribution |
| 60 | |
| 61 | Unless you explicitly state otherwise, any contribution intentionally |
| 62 | submitted for inclusion in the work by you, as defined in the |
| 63 | Apache-2.0 license, shall be dual-licensed as above, without any |
| 64 | additional terms or conditions. |