Skip to content

Commit

Permalink
Fix response status and headers (#245)
Browse files Browse the repository at this point in the history
* Added additional logging to the response handler

* Fixed a bug from the hyper upgrade

- We were using hyper Response::new to just copy the body when we should've been using Response::from_parts which keeps the headers and status when converting from Incoming to BoxBody

* Updated the Cargo.lock file to latest
  • Loading branch information
tkmcmaster authored Aug 13, 2024
1 parent b58e703 commit 031c07d
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 65 deletions.
116 changes: 53 additions & 63 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions src/request/request_maker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ impl RequestMaker {
headers.insert(CONTENT_LENGTH, content_length.into());
}
debug!("final headers={:?}", headers);
info!("RequestMaker method=\"{}\" url=\"{}\" request_headers={:?} tags={:?}", method, url.as_str(), headers, tags);
info!("RequestMaker::send_request method=\"{}\" url=\"{}\" request_headers={:?} tags={:?}", method, url.as_str(), headers, tags);
let mut request_provider = json::json!({});
let request_obj = request_provider
.as_object_mut()
Expand Down Expand Up @@ -318,8 +318,12 @@ impl RequestMaker {
stats_tx,
tags,
};
debug!("RequestMaker::send_request Response<Incoming>={:?}", response);
// Convert from a Response<Incoming> to a Response<BoxBody> to pass to handle()
rh.handle(hyper::Response::new(response.into_body().boxed().map_err(std::io::Error::other).boxed()), auto_returns)
let (head, body) = response.into_parts();
let response = hyper::Response::from_parts(head, body.boxed().map_err(std::io::Error::other).boxed());
debug!("RequestMaker::send_request Response<BoxBody>={:?}", response);
rh.handle(response, auto_returns)
.map_err(TestError::from)
})
.or_else(move |r| {
Expand Down
9 changes: 9 additions & 0 deletions src/request/response_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,16 @@ impl ResponseHandler {
where
F: Future<Output = ()> + Send,
{
log::debug!("ResponseHandler::handle response=\"{:?}\"", response);
let status_code = response.status();
let status = status_code.as_u16();
let headers = response.headers().clone(); // For logging
log::debug!(
"ResponseHandler::handle status_code=\"{}\", status=\"{}\", headers={:?}",
status_code,
status,
headers
);
let response_provider = json::json!({ "status": status });
let mut template_values = self.template_values;
template_values.insert("response".into(), response_provider);
Expand Down Expand Up @@ -124,6 +132,7 @@ impl ResponseHandler {
let tags = self.tags;
body_future
.then(move |body_value| {
log::info!("ResponseHandler::handle status={:?} headers={:?} tags={:?} body_value=\"{:?}\"", status, headers, tags, body_value);
let bh = BodyHandler {
included_outgoing_indexes,
now,
Expand Down

0 comments on commit 031c07d

Please sign in to comment.