Skip to content

fix: always close multipart form writer to write closing boundary#265

Open
sylas00 wants to merge 1 commit intogo-telegram:mainfrom
sylas00:fix/empty-multipart-body-for-no-params-methods
Open

fix: always close multipart form writer to write closing boundary#265
sylas00 wants to merge 1 commit intogo-telegram:mainfrom
sylas00:fix/empty-multipart-body-for-no-params-methods

Conversation

@sylas00
Copy link

@sylas00 sylas00 commented Mar 17, 2026

When a method has no parameters (e.g. getMe, getMyCommands), form.Close() was skipped because it was inside the params nil-check block. This left the request body empty while the Content-Type header still declared a multipart boundary, producing a malformed request.

Strict self-hosted Bot API servers reject such requests with HTTP 400 and an empty response body, causing the client to fail with:
"error decode response body for method getMe, , unexpected end of JSON input"

Move form.Close() outside the nil-check so the closing boundary (--boundary--) is always written, regardless of whether there are any form fields.

When a method has no parameters (e.g. getMe, getMyCommands), form.Close()
was skipped because it was inside the params nil-check block. This left
the request body empty while the Content-Type header still declared a
multipart boundary, producing a malformed request.

Strict self-hosted Bot API servers reject such requests with HTTP 400
and an empty response body, causing the client to fail with:
  "error decode response body for method getMe, , unexpected end of JSON input"

Move form.Close() outside the nil-check so the closing boundary
(--boundary--) is always written, regardless of whether there are
any form fields.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant