Skip to content

[k2] add support http multipart content-type#1545

Open
astrophysik wants to merge 26 commits intomasterfrom
vsadokhov/k2-http-multipart
Open

[k2] add support http multipart content-type#1545
astrophysik wants to merge 26 commits intomasterfrom
vsadokhov/k2-http-multipart

Conversation

@astrophysik
Copy link
Contributor

No description provided.

@astrophysik astrophysik added this to the next milestone Mar 6, 2026
@astrophysik astrophysik self-assigned this Mar 6, 2026
@astrophysik astrophysik added the k2 k2 related label Mar 6, 2026

auto tmp_name_opt{generate_temporary_name()};
if (!tmp_name_opt.has_value()) {
kphp::log::warning("cannot generate unique name for multipart temporary file");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't it dangerous that we can't create a file and just emit a warning? It looks like this may lead to some state corruption

@astrophysik astrophysik added the enhancement New feature or request label Mar 13, 2026

inline auto parse_multipart_parts(std::string_view body, std::string_view boundary) noexcept {
return std::views::split(body, std::views::join(std::array{std::string_view{"--"}, boundary})) |
std::views::filter([](auto raw_part) noexcept { return !std::string_view(raw_part).empty(); }) |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it OK to return view that contains temporary array?

auto tmp_name_opt{generate_temporary_name()};
kphp::log::assertion(tmp_name_opt.has_value());
auto tmp_name{*tmp_name_opt};
auto write_res{write_temporary_file(tmp_name, {reinterpret_cast<const std::byte*>(part.body.data()), part.body.size()})};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: span_of_char.as_bytes() is better here imho

auto tmp_name{*tmp_name_opt};
auto write_res{write_temporary_file(tmp_name, {reinterpret_cast<const std::byte*>(part.body.data()), part.body.size()})};

if (write_res.has_value() || write_res.error() != UPLOAD_ERR_NO_FILE) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we keep files that've been uploaded partially?

boundary_end = content_type.size();
}

std::string_view boundary_view{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, take a look at runtime/interface.cpp:1307. It looks like you forgot some validation steps

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request k2 k2 related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants