Webhook delivery errors when length is incorrect

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?

Any ideas?

1 Like

Does your server log all requests that it receives? That’ll help us determine if the request or its body is invalid or not.

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-Length sometimes 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.

6 Likes

@rhyolight Can you provide me with the curl command to reproduce the issue? :slight_smile: Thanks!

2 Likes

Everything is working properly since 2016-09-21, so no need to continue with this thread. :slight_smile:

5 Likes