andrebsguedes commented on code in PR #5681:
URL: https://github.com/apache/arrow-rs/pull/5681#discussion_r1695837668
##########
object_store/src/azure/client.rs:
##########
@@ -240,6 +268,157 @@ impl<'a> PutRequest<'a> {
}
}
+#[inline]
+fn extend(dst: &mut Vec<u8>, data: &[u8]) {
+ dst.extend_from_slice(data);
+}
+
+// Write header names as title case. The header name is assumed to be ASCII.
+fn title_case(dst: &mut Vec<u8>, name: &[u8]) {
+ dst.reserve(name.len());
+
+ // Ensure first character is uppercased
+ let mut prev = b'-';
+ for &(mut c) in name {
+ if prev == b'-' {
+ c.make_ascii_uppercase();
+ }
+ dst.push(c);
+ prev = c;
+ }
+}
+
+fn write_headers(headers: &HeaderMap, dst: &mut Vec<u8>) {
+ for (name, value) in headers {
+ if name == "content-id" {
+ extend(dst, b"Content-ID");
+ } else {
+ title_case(dst, name.as_str().as_bytes());
+ }
+ extend(dst, b": ");
+ extend(dst, value.as_bytes());
+ extend(dst, b"\r\n");
+ }
+}
+
+fn serialize_part_request(
+ dst: &mut Vec<u8>,
+ boundary: &str,
+ idx: usize,
+ request: reqwest::Request,
+ relative_url: String,
+) {
+ // Encode start marker for part
+ extend(dst, b"--");
+ extend(dst, boundary.as_bytes());
+ extend(dst, b"\r\n");
+
+ // Encode part headers
+ let mut part_headers = HeaderMap::new();
+ part_headers.insert(CONTENT_TYPE, "application/http".parse().unwrap());
+ part_headers.insert("Content-Transfer-Encoding",
"binary".parse().unwrap());
+ part_headers.insert("Content-ID", HeaderValue::from(idx));
+ write_headers(&part_headers, dst);
+ extend(dst, b"\r\n");
+
+ // Encode the subrequest request-line
+ extend(dst, b"DELETE ");
+ extend(dst, format!("/{} ", relative_url).as_bytes());
+ extend(dst, b"HTTP/1.1");
+ extend(dst, b"\r\n");
+
+ // Encode subrequest headers
+ write_headers(request.headers(), dst);
+ extend(dst, b"\r\n");
+ extend(dst, b"\r\n");
+}
+
+fn parse_response_part(
+ remaining: &mut &[u8],
+ results: &mut [Result<Path>],
+ paths: &[Path],
+) -> Result<()> {
+ let invalid_response = |msg: &str| Error::InvalidBulkDeleteResponse {
+ reason: msg.to_string(),
+ };
+
+ // Parse part headers and retrieve part id
+ let mut headers = [httparse::EMPTY_HEADER; 4];
+ let id = match httparse::parse_headers(remaining, &mut headers) {
+ Ok(httparse::Status::Complete((pos, headers))) => {
+ *remaining = &remaining[pos..];
+ headers
+ .iter()
+ .find(|h| h.name.to_lowercase() == "content-id")
+ .and_then(|h| std::str::from_utf8(h.value).ok())
+ .and_then(|v| v.parse::<usize>().ok())
+ }
+ _ => return Err(invalid_response("unable to parse parse
headers").into()),
+ };
+
+ // Parse part response headers
+ let mut headers = [httparse::EMPTY_HEADER; 10];
Review Comment:
`httparse` expects a slice of headers and does not attempt to grow it, so we
would need to make the code more complex to support arbitrary headers. I chose
to increase the amount to a more conservative one and explain it in a comment
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]