MCPcopy Index your code
hub / github.com/NativeScript/SimDeck / decode_chunked_body

Function decode_chunked_body

packages/server/src/devtools.rs:1129–1151  ·  view source on GitHub ↗
(mut body: &[u8])

Source from the content-addressed store, hash-verified

1127}
1128
1129fn decode_chunked_body(mut body: &[u8]) -> Result<Vec<u8>, String> {
1130 let mut decoded = Vec::new();
1131 loop {
1132 let line_end = body
1133 .windows(2)
1134 .position(|window| window == b"\r\n")
1135 .ok_or_else(|| "Metro returned malformed chunked HTTP.".to_owned())?;
1136 let size_line = std::str::from_utf8(&body[..line_end])
1137 .map_err(|_| "Metro returned non-UTF-8 chunk metadata.".to_owned())?;
1138 let size_text = size_line.split(';').next().unwrap_or("").trim();
1139 let size = usize::from_str_radix(size_text, 16)
1140 .map_err(|_| "Metro returned invalid chunk size.".to_owned())?;
1141 body = &body[line_end + 2..];
1142 if size == 0 {
1143 return Ok(decoded);
1144 }
1145 if body.len() < size + 2 || body.get(size..size + 2) != Some(b"\r\n") {
1146 return Err("Metro returned truncated chunked HTTP.".to_owned());
1147 }
1148 decoded.extend_from_slice(&body[..size]);
1149 body = &body[size + 2..];
1150 }
1151}
1152
1153fn split_path_query(value: &str) -> (&str, Option<&str>) {
1154 match value.split_once('?') {

Callers 1

decoded_http_bodyFunction · 0.70

Calls 2

windowsMethod · 0.80
getMethod · 0.65

Tested by

no test coverage detected