Skip to content

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

Closed

Description

@fivetaku

Bug Description

gws gmail users messages trash always fails with HTTP 411 (Length Required). The Gmail API's trash endpoint is a POST method with no request body, but gws sends the request without a Content-Length: 0 header, causing Google's servers to reject it.

Steps to Reproduce

gws auth login
gws gmail +triage --max 1 --format json  # works fine, get a message ID
gws gmail users messages trash --params '{"userId": "me", "id": "MESSAGE_ID"}'

Expected Behavior

The message should be moved to trash and the trashed message object returned.

Actual Behavior

{
  "error": {
    "code": 411,
    "message": "POST requests require a Content-length header.",
    "reason": "httpError"
  }
}

Workaround

Manually obtain an access token and use curl with explicit Content-Length: 0:

curl -s -X POST \
  "https://gmail.googleapis.com/gmail/v1/users/me/messages/MESSAGE_ID/trash" \
  -H "Authorization: Bearer ACCESS_TOKEN" \
  -H "Content-Length: 0"

This succeeds, confirming the API itself works — the issue is that gws omits the Content-Length header.

Scope

This likely affects all POST methods with no request body across all services, not just Gmail trash. Any Discovery API method where httpMethod: "POST" and no requestBody is defined will hit the same 411.

Other potentially affected methods (from schema inspection):

  • gmail.users.messages.untrash
  • gmail.users.threads.trash
  • gmail.users.threads.untrash
  • Any other body-less POST endpoint

Environment

  • gws version: 0.4.4
  • OS: macOS (Darwin 25.3.0)
  • Node.js: 22.x
  • Auth method: OAuth2 (plaintext credentials.json)

Suggested Fix

When building the HTTP request for POST methods with no request body, set Content-Length: 0 header explicitly.

Activity

  1. added a commit that references this issue on Mar 5, 2026
    3b4f9d4
  2. added a commit that references this issue on Mar 9, 2026
    c545994
  3. added a commit that references this issue on Mar 20, 2026
    40780d9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions