Skip to content

Commit

Permalink
Simple names
Browse files Browse the repository at this point in the history
  • Loading branch information
mattgathu committed Dec 29, 2023
1 parent 9529e55 commit a50b477
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 28 deletions.
24 changes: 8 additions & 16 deletions src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,8 +339,8 @@ impl HttpParser {
None => None,
};
ranges.push(BytesRange::Int {
first_pos,
last_pos,
start: first_pos,
end: last_pos,
});
}
Rule::suffix_range => {
Expand All @@ -363,27 +363,19 @@ impl HttpParser {

#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub enum BytesRange {
Int {
first_pos: usize,
last_pos: Option<usize>,
},
Suffix {
len: usize,
},
Int { start: usize, end: Option<usize> },
Suffix { len: usize },
}

impl BytesRange {
pub fn is_valid(&self, max_len: usize) -> bool {
match *self {
BytesRange::Int {
first_pos,
last_pos,
} => {
let last_pos = last_pos.unwrap_or(max_len);
if first_pos > last_pos {
BytesRange::Int { start, end } => {
let end = end.unwrap_or(max_len);
if start > end {
false
} else {
last_pos <= max_len
end <= max_len
}
}
BytesRange::Suffix { len } => len > max_len,
Expand Down
14 changes: 2 additions & 12 deletions src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,18 +256,8 @@ impl RequestHandler {
);
}
let (start, size) = match range {
crate::http::BytesRange::Int {
first_pos,
last_pos,
} => {
if let Some(lpos) = last_pos {
let delta = lpos - first_pos;
(first_pos, delta)
} else {
let delta = entry.size as usize - first_pos;

(first_pos, delta)
}
crate::http::BytesRange::Int { start, end } => {
(start, end.unwrap_or(entry.size as usize) - start)
}
crate::http::BytesRange::Suffix { len } => {
let start = entry.size as usize - len;
Expand Down

0 comments on commit a50b477

Please sign in to comment.