Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions examples/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ async fn param_example(
return Ok(Response::builder()
.status(StatusCode::UNPROCESSABLE_ENTITY)
.body(full(MISSING))
.unwrap());
.expect("constant status won't error"));
};
let number = if let Some(n) = params.get("number") {
if let Ok(v) = n.parse::<f64>() {
Expand All @@ -61,13 +61,13 @@ async fn param_example(
return Ok(Response::builder()
.status(StatusCode::UNPROCESSABLE_ENTITY)
.body(full(NOTNUMERIC))
.unwrap());
.expect("constant status won't error"));
}
} else {
return Ok(Response::builder()
.status(StatusCode::UNPROCESSABLE_ENTITY)
.body(full(MISSING))
.unwrap());
.expect("constant status won't error"));
};

// Render the response. This will often involve
Expand All @@ -86,7 +86,7 @@ async fn param_example(
return Ok(Response::builder()
.status(StatusCode::UNPROCESSABLE_ENTITY)
.body(full(MISSING))
.unwrap());
.expect("constant status won't error"));
};
let params = form_urlencoded::parse(query.as_bytes())
.into_owned()
Expand All @@ -97,15 +97,15 @@ async fn param_example(
return Ok(Response::builder()
.status(StatusCode::UNPROCESSABLE_ENTITY)
.body(full(MISSING))
.unwrap());
.expect("constant status won't error"));
};
let body = format!("You requested {}", page);
Ok(Response::new(full(body)))
}
_ => Ok(Response::builder()
.status(StatusCode::NOT_FOUND)
.body(empty())
.unwrap()),
.expect("constant status won't error")),
}
}

Expand Down
4 changes: 2 additions & 2 deletions examples/send_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ fn not_found() -> Response<BoxBody<Bytes, std::io::Error>> {
Response::builder()
.status(StatusCode::NOT_FOUND)
.body(Full::new(NOTFOUND.into()).map_err(|e| match e {}).boxed())
.unwrap()
.expect("constant status won't error")
}

async fn simple_file_send(filename: &str) -> Result<Response<BoxBody<Bytes, std::io::Error>>> {
Expand All @@ -85,7 +85,7 @@ async fn simple_file_send(filename: &str) -> Result<Response<BoxBody<Bytes, std:
let response = Response::builder()
.status(StatusCode::OK)
.body(boxed_body)
.unwrap();
.expect("constant status won't error");

Ok(response)
}
2 changes: 1 addition & 1 deletion examples/service_struct_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl Service<Request<IncomingBody>> for Svc {

fn call(&self, req: Request<IncomingBody>) -> Self::Future {
fn mk_response(s: String) -> Result<Response<Full<Bytes>>, hyper::Error> {
Ok(Response::builder().body(Full::new(Bytes::from(s))).unwrap())
Ok(Response::new(Full::new(Bytes::from(s))))
}

if req.uri().path() != "/favicon.ico" {
Expand Down
2 changes: 1 addition & 1 deletion examples/upgrades.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ async fn client_upgrade_request(addr: SocketAddr) -> Result<()> {
.uri(format!("http://{}/", addr))
.header(UPGRADE, "foobar")
.body(Empty::<Bytes>::new())
.unwrap();
.expect("uri/header parse won't error");

let stream = TcpStream::connect(addr).await?;
let io = TokioIo::new(stream);
Expand Down
8 changes: 4 additions & 4 deletions examples/web_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ async fn client_request_response() -> Result<Response<BoxBody>> {
.uri(URL)
.header(header::CONTENT_TYPE, "application/json")
.body(Full::new(Bytes::from(POST_DATA)))
.unwrap();
.expect("uri/header parse from constants won't error");

let host = req.uri().host().expect("uri has no host");
let port = req.uri().port_u16().expect("uri has no port");
Expand Down Expand Up @@ -73,11 +73,11 @@ async fn api_get_response() -> Result<Response<BoxBody>> {
Ok(json) => Response::builder()
.header(header::CONTENT_TYPE, "application/json")
.body(full(json))
.unwrap(),
.expect("header parse from constant won't error"),
Err(_) => Response::builder()
.status(StatusCode::INTERNAL_SERVER_ERROR)
.body(full(INTERNAL_SERVER_ERROR))
.unwrap(),
.expect("constant status won't error"),
};
Ok(res)
}
Expand All @@ -93,7 +93,7 @@ async fn response_examples(req: Request<IncomingBody>) -> Result<Response<BoxBod
Ok(Response::builder()
.status(StatusCode::NOT_FOUND)
.body(full(NOTFOUND))
.unwrap())
.expect("constant status won't error"))
}
}
}
Expand Down