8000 Implement encoding of request bodies as `json` or `x-www-form-urlencoded` by raxyte · Pull Request #5305 · tenzir/tenzir · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Implement encoding of request bodies as json or x-www-form-urlencoded #5305

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

raxyte
Copy link
Member
@raxyte raxyte commented Jun 27, 2025

Additionally, rename payload to body, deprecating the former.

@raxyte raxyte added the feature New functionality label Jun 27, 2025
Copy link
github-actions bot commented Jun 27, 2025

Note

🎉 Great work! This PR already includes 1 changelog entry.

If you need to add additional changelog entries, you can use the links below or run ./changelog/add.py change|bugfix|feature on the command-line.

📝 Changelog Entries

Type Description Link
🔄 Change Modifications to existing functionality Add Change
🐛 Bugfix Fixes for bugs or issues Add Bugfix
Feature New functionality or enhancements Add Feature

📚 Documentation Preview

Docs preview is ready!

🔗 Preview Docs: https://tenzir-tenzir-preview-5305.surge.sh

The preview will be updated automatically when you push new commits to this PR.

@raxyte raxyte force-pushed the topic/http-encode branch 16 times, most recently from 7266405 to d8447a6 Compare July 2, 2025 14:01
@raxyte raxyte marked this pull request as ready for review July 2, 2025 14:01
@raxyte raxyte requested review from Copilot and jachris July 2, 2025 14:01
Copy link
Contributor
@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Adds support for user-specified request body encoding (json or x-www-form-urlencoded), renames the payload parameter to body (while still accepting the old name), and updates decompression and header handling to match the new API.

  • Rename payloadbody across operators and helpers
  • Introduce encode option to control record serialization (json vs form)
  • Update try_decompress_*, header construction, and code paths to use body

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
libtenzir/builtins/operators/http.cpp Core operator logic: renamed payload→body, added encode, refactored header/content-type logic, new eval_body helper
docs/operators/http.md Updated http operator docs with body and encode parameters and defaults
docs/operators/from_http.md Updated from_http docs to match new body/encode API and fixed typos
changelog/changes/portal-mother-stand.md Added release notes and examples for body encoding feature
Comments suppressed due to low confidence (1)

libtenzir/builtins/operators/http.cpp:1946

  • The new eval_body helper handles multiple types and encoding paths but there are no accompanying unit tests. Consider adding tests for JSON serialization, form encoding, and edge cases (null, blob, missing body).
  auto eval_body(const table_slice& slice, diagnostic_handler& dh) const

Comment on lines +868 to +872
if (headers) {
for (const auto& [k, v] : headers->inner) {
insert_content_type &= caf::icase_equal(k, "content-type");
Copy link
Preview
Copilot AI Jul 2, 2025

Choose a reason for hiding this comment

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

The logic uses an AND-reduction over all header keys, so if there are multiple headers and none is content-type, insert_content_type becomes false and no Content-Type is added. Consider tracking has_content_type separately (e.g., if (caf::icase_equal(k, "content-type")) has_content_type = true;) and then adding Content-Type when !has_content_type.

Suggested change
if (headers) {
for (const auto& [k, v] : headers->inner) {
insert_content_type &= caf::icase_equal(k, "content-type");
bool has_content_type = false;
if (headers) {
for (const auto& [k, v] : headers->inner) {
if (caf::icase_equal(k, "content-type")) {
has_content_type = true;
}

Copilot uses AI. Check for mistakes.

@@ -607,7 +611,8 @@ struct from_http_args {
auto add_to(argument_parser2& p) {
p.positional("url", url);
p.named("method", method);
p.named("payload", payload);
p.named("body|payload", body);
Copy link
Preview
Copilot AI Jul 2, 2025

Choose a reason for hiding this comment

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

[nitpick] You’ve aliased payload to body but haven’t emitted a deprecation warning when a user still passes payload. Consider detecting the old name and emitting a diagnostic hinting that payload is deprecated in favor of body.

Suggested change
p.named("body|payload", body);
p.named("body|payload", body);
if (p.has_named("payload")) {
std::cerr << "Warning: 'payload' is deprecated. Please use 'body' instead." << std::endl;
}

Copilot uses AI. Check for mistakes.

return failure::promise();
}
if (encode->inner != "form") {
diagnostic::error("unsupported encoding: `{}`", encode->inner)
Copy link
Preview
Copilot AI Jul 2, 2025

Choose a reason for hiding this comment

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

The error message reports an unsupported encoding but doesn’t list supported values. Enhance it with a hint like "supported values are json or form" to guide users.

Suggested change
diagnostic::error("unsupported encoding: `{}`", encode->inner)
diagnostic::error("unsupported encoding: `{}`. Supported values are: `form`.", encode->inner)

Copilot uses AI. Check for mistakes.

…ded`

Additionally, rename `payload` to `body`, deprecating the former.
@raxyte raxyte force-pushed the topic/http-encode branch from d8447a6 to c2d8263 Compare July 3, 2025 12:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant
0