-
Notifications
You must be signed in to change notification settings - Fork 709
[CORE-15023] Cloud Storage Clients: Add util::find_multipart_boundary #29166
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -512,4 +512,66 @@ multipart_subresponse::iobuf_to_constbufseq(const iobuf& buf) { | |
| return seq; | ||
| }; | ||
|
|
||
| std::expected<std::string_view, std::exception_ptr> | ||
| find_multipart_boundary(const http::client::response_header& headers) { | ||
| constexpr std::string_view boundary_name{"boundary"}; | ||
| constexpr std::string_view content_type_multipart{"multipart/mixed"}; | ||
|
|
||
| auto content_type_it = headers.find( | ||
| boost::beast::http::field::content_type); | ||
| std::string_view boundary; | ||
| if (content_type_it == headers.end()) { | ||
| return std::unexpected( | ||
| std::make_exception_ptr( | ||
| std::runtime_error( | ||
| "find_multipart_boundary: Content-Type missing"))); | ||
| } | ||
| std::string_view content_type{content_type_it->value()}; | ||
| if (auto pos = content_type.find(content_type_multipart); | ||
| pos == content_type.npos) { | ||
| return std::unexpected( | ||
| std::make_exception_ptr( | ||
| std::runtime_error( | ||
| fmt::format( | ||
| "find_multipart_boundary: Expected multipart Content-Type: {}", | ||
| content_type)))); | ||
| } | ||
| if (auto boundary_pos = content_type.find(boundary_name); | ||
| boundary_pos != content_type.npos) { | ||
| boundary = content_type.substr(boundary_pos + boundary_name.size()); | ||
| // remove whitespace (if present) and find exactly one equals sign | ||
| int n_eq = 0; | ||
| while (!boundary.empty()) { | ||
| auto c = boundary.front(); | ||
| bool is_eq = c == '='; | ||
| bool is_whitespace = (c == ' ' || c == '\t'); | ||
| if (!is_eq && !is_whitespace) { | ||
| break; | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we have
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
correct, but a few lines down we blow away the string view if we didn't find exactly one This function could use some documentation. If the diff looks ok to you aside from that, I'll add a nice block comment in the next PR.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh yeh makes sense i was thinking those checks were inside the while loop |
||
| n_eq += is_eq; | ||
| boundary = boundary.substr(1); | ||
| } | ||
| if (n_eq != 1) { | ||
| boundary = {}; | ||
| } | ||
| // Remove quotes if present | ||
| if (!boundary.empty() && boundary.front() == '"') { | ||
| boundary = boundary.substr(1); | ||
| } | ||
| if (!boundary.empty() && boundary.back() == '"') { | ||
| boundary = boundary.substr(0, boundary.size() - 1); | ||
| } | ||
| } | ||
| if (boundary.empty()) { | ||
| return std::unexpected( | ||
| std::make_exception_ptr( | ||
| std::runtime_error( | ||
| fmt::format( | ||
| "find_multipart_boundary: Boundary missing from multipart " | ||
| "response Content-Type: {}", | ||
| content_type)))); | ||
| } | ||
| return boundary; | ||
| } | ||
|
|
||
| } // namespace cloud_storage_clients::util | ||
Uh oh!
There was an error while loading. Please reload this page.