Skip to content

Commit

Permalink
remove extra as_refs
Browse files Browse the repository at this point in the history
  • Loading branch information
sansyrox committed Dec 18, 2022
1 parent ecb969e commit ba74a35
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions src/executors/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,37 +70,35 @@ pub async fn execute_http_function(request: &Request, function: FunctionInfo) ->
let output: Py<PyDict> = output.extract(py)?;

let output_type = output.as_ref(py).get_item("type");
let output = output.as_ref(py);

if let Some(output_type) = output_type {
let output_type: String = output_type.extract()?;

if output_type == "static_file" {
let file_path: String =
output.as_ref(py).get_item("file_path").unwrap().extract()?;
let file_path: String = output.get_item("file_path").unwrap().extract()?;
let contents = read_file(&file_path).unwrap();
output.as_ref(py).set_item("body", contents)?;
output.set_item("body", contents)?;
}
};

let status_code = output.as_ref(py).get_item("status_code").unwrap();
let status_code = output.get_item("status_code").unwrap();
let status_code: u16 = status_code.extract().unwrap();

let body = output.as_ref(py).get_item("body").unwrap();
let body = output.get_item("body").unwrap();
let body: String = body.extract().unwrap();

let headers = output.as_ref(py).get_item("headers");
let headers = output.get_item("headers");

let not_none_headers = if headers.is_some() {
let some_headers: HashMap<String, String> = headers
.unwrap()
.extract::<HashMap<String, String>>()
.unwrap();
let headers = if let Some(headers) = headers {
let some_headers: HashMap<String, String> =
headers.extract::<HashMap<String, String>>().unwrap();
some_headers
} else {
HashMap::new()
};

Ok(Response::new(status_code, not_none_headers, body))
Ok(Response::new(status_code, headers, body))
})?;

debug!("This is the result of the code {:?}", output);
Expand Down

0 comments on commit ba74a35

Please sign in to comment.