refactor: use JSON post instead of form-encoded payload#20
Conversation
Switch _http_post() from HTTP::Tiny::post_form() with a `payload` parameter to HTTP::Tiny::post() with a JSON body. Slack webhooks accept both formats, but the JSON approach is cleaner: - The Content-Type header in _build__http is no longer dead code (post_form always overrode it with application/x-www-form-urlencoded) - Removes the unnecessary form-encoding layer around the JSON payload - Aligns with Slack's recommended JSON content-type approach No functional change — both formats produce identical results on the Slack API side. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
atoomic
left a comment
There was a problem hiding this comment.
LGTM would like some real testing before merging
post() sends content as-is to the socket, unlike post_form() which handles encoding internally. When json->utf8(0) produces a Unicode string with wide characters (e.g. UTF-8 text), HTTP::Tiny fails with a 599 Internal Exception. Add utf8::encode() to ensure the JSON payload is bytes before posting. Update test JSON decoding to use utf8(1) to match the new byte format. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Addressed the "real testing" feedback — pushed two changes: Bug fix: Integration test (
52 tests pass (48 existing + 4 new integration tests). |
|
Re: real testing before merge — This PR includes
For manual smoke testing against a real Slack workspace, something like: use Slack::WebHook;
my $h = Slack::WebHook->new(url => $ENV{SLACK_WEBHOOK_URL});
$h->post_ok("JSON post test — café ☃");
$h->post_error("Error format test");The CI tests pass on all Perl versions (5.14–5.42). |
What
Switch
_http_post()frompost_form()with apayloadparameter topost()with a JSON body.Why
The
Content-Type: application/jsonheader set in_build__httpwas dead code —post_form()always overrides it withapplication/x-www-form-urlencoded. This confused readers (cf. PR #14). Rather than removing the header, this makes it actually effective.How
_http_post:post_form($url, { payload => $json })→post($url, { content => $json })postinstead ofpost_form, extract fromcontentinstead ofpayloadpost_formtopostBoth formats are accepted by Slack webhooks — no functional change on the API side.
Testing
All 48 tests pass locally. The mock captures
HTTP::Tiny::postcalls and verifies JSON payloads round-trip correctly, including UTF-8 attachment encoding.🤖 Generated with Claude Code
Supersedes the rationale of #14 (dead Content-Type removal) — the header is now useful.
Quality Report
Changes: 2 files changed, 13 insertions(+), 13 deletions(-)
Code scan: clean
Tests: passed (OK)
Branch hygiene: clean
Generated by Kōan post-mission quality pipeline