Some of the HTTP requests being sent to one of my webhooks are being returned with 400 errors. From what I can tell on the client of these requests, it seems like the request body might be getting cut short, or that the Content-Length of the requests doesn’t match the POST body.
For you admins on our hosted instance, you can see the webhook deliveries here.
I cannot tell why some of these requests are valid and some are not. The same logic is processes each request and just logging it to console. From inspecting them in the UI, they all look good, but some of them returned 400. The server logs show SyntaxError: Unexpected end of input which leads me to believe the JSON is possibly invalid because the POST body was cut short?
So I just replicated this error locally with curl based upon the last failing webhook I saw. I extracted the JSON POST body, minified it, and sent it along with the headers Discourse used when sending the data. I saw that upon minifying the JSON POST body, it was not the same size in bytes as the Content-Length header used by Discourse, so my curl command failed. When I changed the Content-Length to match the number of bytes actually in the POST body, it worked.
So the problem is that the Content-Lengthsometimes does not match the number of bytes in the POST body, causing JSON parsing to fail because the entirely of the JSON CLOB was not loaded.