Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Address clippy lints #89

Merged
merged 1 commit into from
Oct 3, 2021
Merged
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
29 changes: 11 additions & 18 deletions src/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,18 @@ pub async fn handle_request(
payload: &mut web::Payload,
req: &HttpRequest,
) -> HttpResponse {
let contents = match execute_function(function, payload, &headers, req).await {
let contents = match execute_function(function, payload, headers, req).await {
Ok(res) => res,
Err(err) => {
println!("Error: {:?}", err);
let mut response = HttpResponse::InternalServerError();
apply_headers(&mut response, &headers);
apply_headers(&mut response, headers);
return response.finish();
}
};

let mut response = HttpResponse::Ok();
apply_headers(&mut response, &headers);
apply_headers(&mut response, headers);
SanchithHegde marked this conversation as resolved.
Show resolved Hide resolved
response.body(contents)
}

Expand Down Expand Up @@ -106,13 +106,10 @@ async fn execute_function(
let output = Python::with_gil(|py| {
let handler = handler.as_ref(py);

match data {
Some(res) => {
let data = res.into_py(py);
request.insert("body", data);
request.insert("headers", headers_python.into_py(py));
}
None => {}
if let Some(res) = data {
let data = res.into_py(py);
request.insert("body", data);
request.insert("headers", headers_python.into_py(py));
};

// this makes the request object to be accessible across every route
Expand All @@ -135,25 +132,21 @@ async fn execute_function(
if response_type == "static_file" {
// static file here and serve string
let file_path = res.get_item("file_path").unwrap().extract()?;
return Ok(read_file(file_path));
Ok(read_file(file_path))
} else {
return Err(PyErr::from_instance(
"Server Error".into_py(py).as_ref(py),
));
Err(PyErr::from_instance("Server Error".into_py(py).as_ref(py)))
}
}
false => {
return Err(PyErr::from_instance(
"Server Error".into_py(py).as_ref(py),
));
Err(PyErr::from_instance("Server Error".into_py(py).as_ref(py)))
}
}
}
Err(_) => {
// this means that this is basic string output
// and a json serialized string will be parsed here
let contents: &str = string_contents.extract(py)?;
return Ok(contents.to_string());
Ok(contents.to_string())
}
}
})?;
Expand Down
6 changes: 6 additions & 0 deletions src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,12 @@ impl Server {
}
}

impl Default for Server {
fn default() -> Self {
Self::new()
}
}

/// This is our service handler. It receives a Request, routes on it
/// path, and returns a Future of a Response.
async fn index(
Expand Down