Skip to content

Commit 8f58704

Browse files
authored
Add support for Transfer-Encoding header for GCP Go Gen 1 Cloud Functions (#18)
* Add support for Transfer-Encoding header for GCP Go Gen 1 Cloud Functions * update tests * update format * revert cargo * update LICENSE-3rdparty.csv * add debug log * cargo fmt * remove log::debug
1 parent b1583da commit 8f58704

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

crates/datadog-trace-agent/src/http_utils.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ pub fn log_and_create_traces_success_http_response(
5656
.body(hyper_migration::Body::from(body))
5757
}
5858

59-
/// Takes a request's header map, and verifies that the "content-length" header is present, valid,
60-
/// and less than the given max_content_length.
59+
/// Takes a request's header map, and verifies that the "content-length" and/or "Transfer-Encoding" header
60+
/// is present, valid, and less than the given max_content_length.
6161
///
6262
/// Will return None if no issues are found. Otherwise logs an error (with the given prefix) and
6363
/// returns and HTTP Response with the appropriate error status code.
@@ -69,8 +69,17 @@ pub fn verify_request_content_length(
6969
let content_length_header = match header_map.get(header::CONTENT_LENGTH) {
7070
Some(res) => res,
7171
None => {
72+
if let Some(transfer_encoding_header) = header_map.get(header::TRANSFER_ENCODING) {
73+
debug!(
74+
"Transfer-Encoding header is present: {:?}",
75+
transfer_encoding_header
76+
);
77+
return None;
78+
}
7279
return Some(log_and_create_http_response(
73-
&format!("{error_message_prefix}: Missing Content-Length header"),
80+
&format!(
81+
"{error_message_prefix}: Missing Content-Length and Transfer-Encoding header"
82+
),
7483
StatusCode::LENGTH_REQUIRED,
7584
));
7685
}
@@ -134,7 +143,8 @@ mod tests {
134143
assert_eq!(response.status(), StatusCode::LENGTH_REQUIRED);
135144
assert_eq!(
136145
get_response_body_as_string(response).await,
137-
"{\"message\":\"Test Prefix: Missing Content-Length header\"}".to_string()
146+
"{\"message\":\"Test Prefix: Missing Content-Length and Transfer-Encoding header\"}"
147+
.to_string()
138148
);
139149
}
140150

crates/datadog-trace-agent/src/trace_processor.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,14 @@ impl TraceProcessor for ServerlessTraceProcessor {
9696
}
9797
};
9898

99+
// double check content length is < max request content length in case transfer encoding is used
100+
if body_size > config.max_request_content_length {
101+
return log_and_create_http_response(
102+
&format!("Error processing traces: Payload too large"),
103+
StatusCode::PAYLOAD_TOO_LARGE,
104+
);
105+
}
106+
99107
let payload = match trace_utils::collect_pb_trace_chunks(
100108
traces,
101109
&tracer_header_tags,

0 commit comments

Comments
 (0)