Skip to content
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

Handle both JSON and urlencoded requests. #139

Merged
merged 1 commit into from
Jul 22, 2024

Conversation

ltratt
Copy link
Member

@ltratt ltratt commented Jul 22, 2024

I singularly failed to realise that GitHub requests can come with a Content-Type of JSON or urlencoded: previously snare only handled the latter. Handling both automatically is fairly easily, but doing so highlighted that the tests incorrectly said they had JSON content-type but were actually urlencoded. Since JSON content-type is easier to understand, the tests now consistently use that, except for a (new) test to ensure that we really handle urlencoded correctly.

@mweitzel Does this work for your repo(s) on both JSON and urlencoded webhooks?

I singularly failed to realise that GitHub requests can come with a
Content-Type of JSON or urlencoded: previously snare only handled the
latter. Handling both automatically is fairly easily, but doing so
highlighted that the tests incorrectly said they had JSON content-type
but were actually urlencoded. Since JSON content-type is easier to
understand, the tests now consistently use that, except for a (new) test
to ensure that we really handle urlencoded correctly.
@mweitzel
Copy link

mweitzel commented Jul 22, 2024

Oh man, this is great! Pulled/built/tested, all works quite well with both webhook configurations. Thank you.

FYI, using the json content type also resolve some percent-encoding vs url-encoding headaches. Where you get + instead of %20 so just a "percent decode" misses it. E.g.

$ diff json-webhook.json form-encode-webhook.json 
+  "title": "Create asdf",
-  "title": "Create+asdf",
...
+  "description": "test webhooks and whatnot",
-  "description": "test+webhooks+and+whatnot",

This patch is great, IMO. It now supports json webhooks which it did not before, and the behavior for form-encoded webhooks is entirely consistent with what it was before.

@ltratt
Copy link
Member Author

ltratt commented Jul 22, 2024

Thanks for testing! It was a good bug report which made the fix obvious -- my favourite :)

@vext01
Copy link
Member

vext01 commented Jul 22, 2024

LGTM

@vext01 vext01 added this pull request to the merge queue Jul 22, 2024
Merged via the queue into softdevteam:master with commit e348342 Jul 22, 2024
2 checks passed
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.

3 participants