Skip to content

Commit

Permalink
feat(viz): headers v0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
fundon committed Nov 25, 2023
1 parent e6e8767 commit e81e0b6
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ path-tree = "0.7"

# http
# TODO: wait headers-v1.0
headers = { git = "https://github.com/hyperium/headers.git", rev = "4400aa9" }
headers = "0.4"
http = "1"
http-body = "1"
http-body-util = "0.1"
Expand Down
5 changes: 2 additions & 3 deletions viz-core/src/middleware/cors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,8 @@ where
type Output = Result<Response>;

async fn call(&self, req: Request) -> Self::Output {
let origin = match req.header(ORIGIN).filter(is_not_empty) {
Some(origin) => origin,
None => return self.h.call(req).await.map(IntoResponse::into_response),
let Some(origin) = req.header(ORIGIN).filter(is_not_empty) else {
return self.h.call(req).await.map(IntoResponse::into_response);
};

if !self.config.allow_origins.contains(&origin)
Expand Down
5 changes: 2 additions & 3 deletions viz-core/src/types/websocket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,8 @@ impl WebSocket {
let on_upgrade = self.on_upgrade.take().expect("missing OnUpgrade");

tokio::task::spawn(async move {
let upgraded = match on_upgrade.await {
Ok(upgraded) => upgraded,
Err(_) => return,
let Ok(upgraded) = on_upgrade.await else {
return;
};

let socket =
Expand Down
3 changes: 2 additions & 1 deletion viz-handlers/src/serve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,10 @@ fn serve(path: &Path, headers: &HeaderMap) -> Result<Response> {
last_modified.replace(LastModified::from(modified));
}

// See https://github.com/hyperium/headers/pull/155
if let Some((start, end)) = headers
.typed_get::<Range>()
.and_then(|range| range.iter().next())
.and_then(|range| range.satisfiable_ranges(100).next())
{
let start = match start {
Bound::Included(n) => n,
Expand Down

0 comments on commit e81e0b6

Please sign in to comment.