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

fix(readBody, readRawBody): handle raw body as buffer #366

Merged
merged 4 commits into from
Mar 28, 2023
Merged

fix(readBody, readRawBody): handle raw body as buffer #366

merged 4 commits into from
Mar 28, 2023

Conversation

johannschopplich
Copy link
Contributor

@johannschopplich johannschopplich commented Mar 24, 2023

I'm not sure if this implementation is enough. For my use-case in nuxt-api-party:

// https://github.com/johannschopplich/nuxt-api-party/blob/main/src/runtime/server.ts#L26
let _body = await readBody<EndpointFetchOptions>(event)

// Inconsistent `readBody` behavior in some Nitro presets
// https://github.com/unjs/nitro/issues/912
if (Buffer.isBuffer(_body))
  _body = destr((_body as Buffer).toString())

… this change fixed handling Buffer requests, e.g. when sending POST requests in a Cloudflare Nitro worker.

@pi0 pi0 changed the title fix: handle Buffer in readBody fix(readBody): handle raw body as buffer Mar 28, 2023
@pi0 pi0 changed the title fix(readBody): handle raw body as buffer fix(readBody, readRawBody): handle raw body as buffer Mar 28, 2023
@pi0
Copy link
Member

pi0 commented Mar 28, 2023

Thanks for the PR. I have pushed couple of changes to handle it also for readRawBody consistently + tests

@codecov
Copy link

codecov bot commented Mar 28, 2023

Codecov Report

Merging #366 (cb7a486) into main (ba64f60) will increase coverage by 0.19%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main     #366      +/-   ##
==========================================
+ Coverage   74.57%   74.77%   +0.19%     
==========================================
  Files          26       26              
  Lines        2407     2406       -1     
  Branches      380      381       +1     
==========================================
+ Hits         1795     1799       +4     
+ Misses        612      607       -5     
Impacted Files Coverage Δ
src/utils/body.ts 92.62% <100.00%> (+4.00%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@pi0 pi0 merged commit 74a2e6d into unjs:main Mar 28, 2023
1 check passed
@pi0
Copy link
Member

pi0 commented Mar 28, 2023

Related fix 19d133d

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.

readBody needs to handle Buffer
2 participants