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

Only sets req.raw.body if body defined, aligning behaviour with node:http #201

Merged
merged 2 commits into from
May 1, 2024

Conversation

didley
Copy link
Contributor

@didley didley commented Apr 27, 2024

Currently Middie's undefined req.body handling does not align with node:http and express. Their behaviour, If the body has not been parsed with a body parser and is undefined, the body key will not be present within the request. Maddie includes the body key with an undefined value.

I've created this PR as the library @octokit/webhooks does not currently work with Middie[0] because of this issue. I also feel it would be beneficial to align the behaviour where possible.

Apologies, I haven't run the benchmark script, I don't see it available on main. Have I missed something?

[0] octokit/webhooks.js#1009

Checklist

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also skip Mac on v14 and v16?

index.js Outdated Show resolved Hide resolved
@didley didley force-pushed the align-undefined-body-handling branch from 7fe79ed to 1cdeca2 Compare April 28, 2024 03:55
@didley
Copy link
Contributor Author

didley commented Apr 28, 2024

Thanks for the review @mcollina, I've made the v8 change. Regarding skipping Mac on v14 and v16, do I just need to upgrade the fastify workflow version? Comparing the difference between previous CI jobs I'm assuming that's why it was skipped in this PR[0]

[0] https://github.com/fastify/middie/pull/199/files#diff-b803fcb7f17ed9235f1e5cb1fcd2f5d3b2838429d4368ae4c57ce4436577f03f

@didley didley requested a review from mcollina April 28, 2024 05:03
@@ -17,7 +17,7 @@ on:

jobs:
test:
uses: fastify/workflows/.github/workflows/plugins-ci.yml@v3
uses: fastify/workflows/.github/workflows/plugins-ci.yml@v4.1.0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert this.

Suggested change
uses: fastify/workflows/.github/workflows/plugins-ci.yml@v4.1.0
uses: fastify/workflows/.github/workflows/plugins-ci.yml@v3

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Aras, that's now been reverted. This allowed the previous CI run to pass without running on Mac v14 and v16, I'm expecting it will fail again as CI will run again on Mac for these versions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's wild out of anyone to review this to be you @Uzlopak, this relates to a change you made in the @octokit/webhooks library, in the issue I linked above[0] that I've also created an issue and PR there for.

[0] octokit/webhooks.js#1009

@didley didley force-pushed the align-undefined-body-handling branch from 5c1df04 to 53811a7 Compare April 28, 2024 14:05
Copy link
Member

@gurgunday gurgunday left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

I suppose this is a bug fix and does not require a major bump?

@didley
Copy link
Contributor Author

didley commented Apr 28, 2024

Thanks @gurgunday, yes I would assume it would just be a minor bump.

@didley didley force-pushed the align-undefined-body-handling branch from 53811a7 to 4ccea86 Compare April 29, 2024 10:30
Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@didley
Copy link
Contributor Author

didley commented Apr 29, 2024

I've just tightened the conditional from if(req.body) to if(req.body !== undefined) as this issue only affects the undefined case. '' and null would indicate parsing of the body.

@didley
Copy link
Contributor Author

didley commented May 1, 2024

Is there anything else required to get this merged?

From my understanding CI will fail unless I include the next branch CI config (Fastify workflow v4.1.0), if we don't want to include that change within this PR and require CI to pass I could base this PR to the next branch instead?

@gurgunday
Copy link
Member

It should be good now, sorry for the intervention, had to trigger the ci

Copy link
Member

@gurgunday gurgunday left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@didley
Copy link
Contributor Author

didley commented May 1, 2024

Excellent! Thank you @gurgunday. I'm ready for it to be merged from my side.

@mcollina mcollina merged commit 8c7508e into fastify:master May 1, 2024
17 checks passed
@gurgunday
Copy link
Member

I'll release a new version

@didley
Copy link
Contributor Author

didley commented May 2, 2024

Amazing! Thank you all for your assistance with this and your contributions to OSS

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.

None yet

4 participants