Skip to content

fix(executor): add Content-Length: 0 for body-less POST requests#183

Merged
jpoehnelt merged 2 commits intogoogleworkspace:mainfrom
haunchen:fix/content-length-zero-bodyless-post
Mar 5, 2026
Merged

fix(executor): add Content-Length: 0 for body-less POST requests#183
jpoehnelt merged 2 commits intogoogleworkspace:mainfrom
haunchen:fix/content-length-zero-bodyless-post

Conversation

@haunchen
Copy link
Contributor

@haunchen haunchen commented Mar 5, 2026

Summary

  • Adds Content-Length: 0 header for POST/PUT/PATCH requests that have no request body
  • Google API servers return HTTP 411 (Length Required) when POST is sent without this header, even if the body is empty
  • Affects all Discovery API methods where httpMethod: "POST" and no requestBody is defined (e.g. gmail.users.messages.trash, gmail.users.messages.untrash, gmail.users.threads.trash)

Fixes #182

Test plan

  • Added test_post_without_body_sets_content_length_zero — verifies the fix
  • Added test_post_with_body_does_not_add_content_length_zero — no regression for normal POST
  • Added test_get_does_not_set_content_length_zero — no regression for GET
  • All 443 tests pass, clippy clean

haunchen added 2 commits March 6, 2026 00:52
…TCH requests

Google API servers return HTTP 411 (Length Required) when a POST request
is sent without a Content-Length header, even if there is no body.
This affects all Discovery API methods where httpMethod is POST but no
requestBody is defined (e.g. gmail users.messages.trash).

Fixes googleworkspace#182
@haunchen haunchen requested a review from jpoehnelt as a code owner March 5, 2026 16:54
@changeset-bot
Copy link

changeset-bot bot commented Mar 5, 2026

🦋 Changeset detected

Latest commit: a838afc

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@googleworkspace/cli Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request implements a crucial fix for handling HTTP requests, specifically by ensuring that POST, PUT, and PATCH requests without a body explicitly include a Content-Length: 0 header. This prevents HTTP 411 errors from servers, particularly Google APIs, which require this header even for empty bodies. The change improves the robustness and compatibility of the HTTP client when interacting with various API endpoints.

Highlights

  • HTTP Header Fix: Added the Content-Length: 0 header for POST, PUT, and PATCH requests that do not include a request body. This resolves HTTP 411 (Length Required) errors encountered with Google API servers.
  • Affected APIs: This change specifically addresses issues with Discovery API methods like gmail.users.messages.trash and gmail.users.messages.untrash where httpMethod: "POST" is used without a defined requestBody.
  • New Tests: Introduced three new tests (test_post_without_body_sets_content_length_zero, test_post_with_body_does_not_add_content_length_zero, test_get_does_not_set_content_length_zero) to validate the fix and ensure no regressions for other request types.
Changelog
  • .changeset/fix-content-length-bodyless-post.md
    • Added a new changeset entry documenting the fix for body-less POST/PUT/PATCH requests.
  • src/executor.rs
    • Modified the build_http_request function to conditionally add Content-Length: 0 for POST, PUT, and PATCH methods when no request body is present.
    • Added test_post_without_body_sets_content_length_zero to verify the correct header is set for body-less POST requests.
    • Added test_post_with_body_does_not_add_content_length_zero to confirm that Content-Length: 0 is not added when a body is present.
    • Added test_get_does_not_set_content_length_zero to ensure GET requests remain unaffected by the Content-Length logic.
Activity
  • The author has confirmed that the fix is verified by a new test: test_post_without_body_sets_content_length_zero.
  • Regression tests test_post_with_body_does_not_add_content_length_zero and test_get_does_not_set_content_length_zero were added and passed.
  • All 443 existing tests passed, and the code is clippy clean.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request effectively resolves an issue where body-less POST/PUT/PATCH requests failed with an HTTP 411 error by correctly adding a Content-Length: 0 header. The implementation is sound, well-tested, and no security vulnerabilities were found.

@jpoehnelt jpoehnelt merged commit cb1f988 into googleworkspace:main Mar 5, 2026
21 of 22 checks passed
@codecov
Copy link

codecov bot commented Mar 5, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 56.62%. Comparing base (473dd30) to head (a838afc).
⚠️ Report is 10 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #183      +/-   ##
==========================================
+ Coverage   56.21%   56.62%   +0.40%     
==========================================
  Files          38       38              
  Lines       13853    13923      +70     
==========================================
+ Hits         7788     7884      +96     
+ Misses       6065     6039      -26     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Gmail users.messages.trash returns 411 (Length Required) — missing Content-Length header on POST

2 participants