You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@trafficserver.apache.org by "zwoop (via GitHub)" <gi...@apache.org> on 2025/05/08 20:57:15 UTC
[PR] Allow header_rewrite to run a compiler for HRW4u [trafficserver]
zwoop opened a new pull request, #12230:
URL: https://github.com/apache/trafficserver/pull/12230
(no 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: github-unsubscribe@trafficserver.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Allow header_rewrite to run a compiler for HRW4u [trafficserver]
Posted by "bneradt (via GitHub)" <gi...@apache.org>.
bneradt commented on code in PR #12230:
URL: https://github.com/apache/trafficserver/pull/12230#discussion_r2098993260
##########
plugins/header_rewrite/parser.cc:
##########
@@ -316,3 +318,92 @@ HRWSimpleTokenizer::HRWSimpleTokenizer(const std::string &original_line)
_tokens.push_back(line.substr(cur_token_start));
}
}
+
+// This is the universal configuration reader, which can read both
+// a raw file, as well as executing an external compiler (hrw4u) to parse
+// the configuration file.
+namespace
+{
+void
+_log_stderr(int fd)
+{
+ char buffer[512];
+ std::string partial;
+
+ while (ssize_t n = read(fd, buffer, sizeof(buffer))) {
+ if (n <= 0)
+ break;
+ partial.append(buffer, n);
+ size_t pos = 0;
+ while ((pos = partial.find('\n')) != std::string::npos) {
+ std::string line = partial.substr(0, pos);
+ TSError("[header_rewrite: hrw4u] %s", line.c_str());
+ partial.erase(0, pos + 1);
+ }
+ }
+
+ if (!partial.empty()) {
+ TSError("[hrw4u] stderr: %s", partial.c_str());
+ }
+
+ close(fd);
+}
+} // namespace
+
+std::optional<ConfReader>
+openConfig(const std::string &filename)
+{
+ namespace fs = std::filesystem;
+ const std::string suffix = ".hrw4u";
+ std::string hrw4u = Layout::get()->bindir + "/traffic_hrw4u";
+
+ static const bool has_compiler = [hrw4u]() {
+ fs::path path(hrw4u);
+ std::error_code ec;
+ auto status = fs::status(path, ec);
+ auto perms = status.permissions();
+ return fs::exists(path, ec) && fs::is_regular_file(path, ec) && (perms & fs::perms::owner_exec) != fs::perms::none;
+ }();
+
+ if (filename.ends_with(suffix) && has_compiler) {
+ int pipe_fds[2];
+ int stderr_pipe[2];
+
+ if (pipe(pipe_fds) != 0 || pipe(stderr_pipe) != 0) {
+ return std::nullopt;
+ }
+
+ pid_t pid = fork();
+ if (pid < 0) {
+ return std::nullopt;
Review Comment:
`TSError` maybe?
##########
plugins/header_rewrite/parser.cc:
##########
@@ -316,3 +318,92 @@ HRWSimpleTokenizer::HRWSimpleTokenizer(const std::string &original_line)
_tokens.push_back(line.substr(cur_token_start));
}
}
+
+// This is the universal configuration reader, which can read both
+// a raw file, as well as executing an external compiler (hrw4u) to parse
+// the configuration file.
+namespace
+{
+void
+_log_stderr(int fd)
+{
+ char buffer[512];
+ std::string partial;
+
+ while (ssize_t n = read(fd, buffer, sizeof(buffer))) {
+ if (n <= 0)
+ break;
Review Comment:
Is clang-format being applied to this? I'd expect brackets around this one-liner conditional block.
--
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: github-unsubscribe@trafficserver.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Allow header_rewrite to run a compiler for HRW4u [trafficserver]
Posted by "zwoop (via GitHub)" <gi...@apache.org>.
zwoop merged PR #12230:
URL: https://github.com/apache/trafficserver/pull/12230
--
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: github-unsubscribe@trafficserver.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Allow header_rewrite to run a compiler for HRW4u [trafficserver]
Posted by "zwoop (via GitHub)" <gi...@apache.org>.
zwoop commented on code in PR #12230:
URL: https://github.com/apache/trafficserver/pull/12230#discussion_r2131232038
##########
plugins/header_rewrite/parser.cc:
##########
@@ -316,3 +318,92 @@ HRWSimpleTokenizer::HRWSimpleTokenizer(const std::string &original_line)
_tokens.push_back(line.substr(cur_token_start));
}
}
+
+// This is the universal configuration reader, which can read both
+// a raw file, as well as executing an external compiler (hrw4u) to parse
+// the configuration file.
+namespace
+{
+void
+_log_stderr(int fd)
+{
+ char buffer[512];
+ std::string partial;
+
+ while (ssize_t n = read(fd, buffer, sizeof(buffer))) {
+ if (n <= 0)
+ break;
Review Comment:
Fixed, clang-format did not seem to catch this.
##########
plugins/header_rewrite/parser.cc:
##########
@@ -316,3 +318,92 @@ HRWSimpleTokenizer::HRWSimpleTokenizer(const std::string &original_line)
_tokens.push_back(line.substr(cur_token_start));
}
}
+
+// This is the universal configuration reader, which can read both
+// a raw file, as well as executing an external compiler (hrw4u) to parse
+// the configuration file.
+namespace
+{
+void
+_log_stderr(int fd)
+{
+ char buffer[512];
+ std::string partial;
+
+ while (ssize_t n = read(fd, buffer, sizeof(buffer))) {
+ if (n <= 0)
+ break;
+ partial.append(buffer, n);
+ size_t pos = 0;
+ while ((pos = partial.find('\n')) != std::string::npos) {
+ std::string line = partial.substr(0, pos);
+ TSError("[header_rewrite: hrw4u] %s", line.c_str());
+ partial.erase(0, pos + 1);
+ }
+ }
+
+ if (!partial.empty()) {
+ TSError("[hrw4u] stderr: %s", partial.c_str());
+ }
+
+ close(fd);
+}
+} // namespace
+
+std::optional<ConfReader>
+openConfig(const std::string &filename)
+{
+ namespace fs = std::filesystem;
+ const std::string suffix = ".hrw4u";
+ std::string hrw4u = Layout::get()->bindir + "/traffic_hrw4u";
+
+ static const bool has_compiler = [hrw4u]() {
+ fs::path path(hrw4u);
+ std::error_code ec;
+ auto status = fs::status(path, ec);
+ auto perms = status.permissions();
+ return fs::exists(path, ec) && fs::is_regular_file(path, ec) && (perms & fs::perms::owner_exec) != fs::perms::none;
+ }();
+
+ if (filename.ends_with(suffix) && has_compiler) {
+ int pipe_fds[2];
+ int stderr_pipe[2];
+
+ if (pipe(pipe_fds) != 0 || pipe(stderr_pipe) != 0) {
+ return std::nullopt;
+ }
+
+ pid_t pid = fork();
+ if (pid < 0) {
+ return std::nullopt;
Review Comment:
Added.
--
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: github-unsubscribe@trafficserver.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Allow header_rewrite to run a compiler for HRW4u [trafficserver]
Posted by "zwoop (via GitHub)" <gi...@apache.org>.
zwoop commented on PR #12230:
URL: https://github.com/apache/trafficserver/pull/12230#issuecomment-2947625026
> So this basically runs `traffic_hrw4u` from the bin dir. Are there docs on this already from a separate PR?
No, it probably should be documented as part of the HRW4U links and mentions here in the header_rewrite docs. Maybe we land hrw4u first, and then I can update the docs here to link appropriately?
--
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: github-unsubscribe@trafficserver.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Allow header_rewrite to run a compiler for HRW4u [trafficserver]
Posted by "zwoop (via GitHub)" <gi...@apache.org>.
zwoop commented on PR #12230:
URL: https://github.com/apache/trafficserver/pull/12230#issuecomment-2864945609
[approve ci autest 1]
--
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: github-unsubscribe@trafficserver.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org