Skip to content

Conversation

@nekishdev
Copy link

No description provided.

#include "runtime-common/core/runtime-core.h"
#include "runtime-common/core/std/containers.h"
#include "runtime-common/stdlib/server/url-functions.h"
#include "runtime-common/stdlib/string/string-functions.h"
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like these includes are actually unused

f$parse_str(body_str, superglobals.v$_POST);
} else if (content_type.starts_with(CONTENT_TYPE_MULTIPART_FORM_DATA)) {
kphp::log::error("unsupported content-type: {}", CONTENT_TYPE_MULTIPART_FORM_DATA);
std::string_view boundary = parse_boundary(content_type);
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor comments:

  1. We use braced initialization throughout the codebase. Please, update the initialization to use braces: std::string_view boundary{parse_boundary};.
  2. Ensure consistency in namespace usage by either consistently applying the kphp::http:: prefix or omitting it across the codebase. Let's only use single approach for clarity and maintainability.

Copy link
Contributor

Choose a reason for hiding this comment

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

Please, add missing copyright header


namespace kphp::http {

void parse_multipart(const std::string_view &body, const std::string_view &boundary, mixed &v$_POST, mixed &v$_FILES);
Copy link
Contributor

Choose a reason for hiding this comment

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

Actually, there is no need to passing a std::string_view object by reference as it's quite small. Passing by reference introduces an indirection on the other hand


void parse_multipart(const std::string_view &body, const std::string_view &boundary, mixed &v$_POST, mixed &v$_FILES);

std::string_view parse_boundary(const std::string_view &content_type);
Copy link
Contributor

Choose a reason for hiding this comment

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

Please, mark all functions noexcept

constexpr std::string_view HEADER_CONTENT_DISPOSITION_FORM_DATA = "form-data;";
constexpr std::string_view MULTIPART_BOUNDARY_EQ = "boundary=";

struct Header {
Copy link
Contributor

Choose a reason for hiding this comment

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

Just to follow the code style of the runtime-light, let's name types in lowercase

struct Header {
std::string_view header_str, name, value;

Header() {}
Copy link
Contributor

Choose a reason for hiding this comment

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

Please, use = default if you want a trivial constructor

: header_str{header_str_} {}

void parse() {
char delim = ':';
Copy link
Contributor

Choose a reason for hiding this comment

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

There is vk::split_string_view function. Here is the usage reference: runtime-light/server/http/init-functions.cpp:119

}

size_t
attrStart = header.find_first_not_of(' ', pos),
Copy link
Contributor

Choose a reason for hiding this comment

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

Please, use separate lines to initialize/assign multiple variables

file[string("size")].push_back(file_size);
file[string("tmp_name")].push_back(string(tmp_name.data(), tmp_name.size()));
file[string("error")].push_back(0);
} else {
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 really possible that file_size < 0?

@nekishdev nekishdev force-pushed the ngoryanoy/k2/http-multipart branch 2 times, most recently from 75a4ad4 to 9a96972 Compare October 15, 2025 15:44
@nekishdev nekishdev force-pushed the ngoryanoy/k2/http-multipart branch from 9a96972 to e22a5e9 Compare October 15, 2025 15:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants