-
Notifications
You must be signed in to change notification settings - Fork 87
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
Wrong Content-Length header when event has Content-Length header and its payload contains whitespace #5
Comments
I have a few options for solving this:
Any thoughts or preferences? I can make a PR for any of the options that you feel is the best way to solve the problem. Here's also a test to show the issue: it('message payload length matches content-length header', async (done) => {
const payload = '{ "payload": true }'
await request(server).post(channel)
.set('content-type', 'application/json')
.set('content-length', payload.length)
.send(payload)
events.addEventListener('message', (msg) => {
const data = JSON.parse(msg.data)
const msgPayload = msg.data.match(/"body":(\{.*?\})/)[1]
const contentLength = Number(data['content-length'])
expect(msgPayload.length).toEqual(contentLength)
done()
})
}) Running it gives the output:
|
This is also one way to fix the issue: probot/smee-client#122 |
I had the same problem. Using the test from @niutski I could verify that adding |
I have to correct the solution of my last comment. You should not use the string length like this |
would you like to send a pull request to fix it? |
I'm trying to use Smee.io to use webhooks from Bitbucket Cloud to our Jenkins behind a firewall. Bitbucket sends webhook events with content-length header, but the body it sends contains whitespace. smee.io server correctly parses the incoming JSON, but then it implicitly removes whitespace but does not change the content-length header when it forwards the event to the client. This causes Jenkins to fail in parsing the request body because the
Content-Length
header does not match the actual length of the content.To test:
node testserver.js
smee.js --port 3000
(copy the channel ID from the output)curl -X POST --data '{ "ok": true }' -H "Content-Length: 14" -H "Content-Type: application/json" https://smee.io/[YOUR_CHANNEL_HERE]
curl -X POST --data '{"ok":true}' -H "Content-Length: 11" -H "Content-Type: application/json" https://smee.io/[YOUR_CHANNEL_HERE]
things work as expectedThe text was updated successfully, but these errors were encountered: