-
Notifications
You must be signed in to change notification settings - Fork 110
[k2] add support multipart/form-data to HTTP server #1423
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
base: master
Are you sure you want to change the base?
Conversation
| #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" |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor comments:
- We use braced initialization throughout the codebase. Please, update the initialization to use braces:
std::string_view boundary{parse_boundary};. - 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.
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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() {} |
There was a problem hiding this comment.
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 = ':'; |
There was a problem hiding this comment.
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), |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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?
75a4ad4 to
9a96972
Compare
9a96972 to
e22a5e9
Compare
No description provided.