Skip to content

Conversation

@yusukebe
Copy link
Member

@yusukebe yusukebe commented Jun 7, 2025

Fixes #4031

This PR introduces a new option getBody for ETag middleware.

This will help customize the function to get the content to generate a hash in such a way on the AWS Lambda, which can't use c.res.clone().

The author should do the following, if applicable

  • Add tests
  • Run tests
  • bun run format:fix && bun run lint:fix to format the code
  • Add TSDoc/JSDoc to document the code

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@codecov
Copy link

codecov bot commented Jun 7, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.32%. Comparing base (4a1dd5f) to head (27bead1).

Additional details and impacted files
@@           Coverage Diff            @@
##             main    #4201    +/-   ##
========================================
  Coverage   91.31%   91.32%            
========================================
  Files         168      168            
  Lines       10791    10796     +5     
  Branches     3186     3070   -116     
========================================
+ Hits         9854     9859     +5     
  Misses        936      936            
  Partials        1        1            

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@yusukebe yusukebe added the v4.8 label Jun 7, 2025
@github-actions
Copy link

github-actions bot commented Jun 7, 2025

Bundle size check

main (4a1dd5f) #4201 (6baa461) +/-
Bundle Size (B) 19,027B 19,027B 0B
Bundle Size (KB) 18.58K 18.58K 0K

Compiler Diagnostics (typescript-go)

main (4a1dd5f) #4201 (6baa461) +/-
Files 231 231 0
Lines 106,340 106,340 0
Identifiers 106,183 106,183 0
Symbols 371,551 371,551 0
Types 293,004 293,004 0
Instantiations 3,568,489 3,568,489 0
Memory used 229,864K 229,718K -146K
Memory allocs 10,003,691 10,003,595 -96
Parse time 0.066s 0.071s 0.005s
Bind time 0.014s 0.041s 0.027s
Check time 1.343s 1.392s 0.049s
Emit time 0s 0s 0s
Total time 1.425s 1.508s 0.083s

Reported by octocov

@github-actions
Copy link

github-actions bot commented Jun 7, 2025

Bundle size check

main (4a1dd5f) #4201 (6baa461) +/-
Bundle Size (B) 19,027B 19,027B 0B
Bundle Size (KB) 18.58K 18.58K 0K

Compiler Diagnostics (tsc)

main (4a1dd5f) #4201 (6baa461) +/-
Files 261 261 0
Lines 116,441 116,441 0
Identifiers 114,443 114,443 0
Symbols 259,900 259,900 0
Types 162,567 162,567 0
Instantiations 3,039,293 3,039,293 0
Memory used 272,070K 272,866K 796K
I/O read 0.02s 0.02s 0s
I/O write 0s 0s 0s
Parse time 0.65s 0.65s 0s
Bind time 0.27s 0.27s 0s
Check time 3.74s 3.8s 0.06s
Emit time 0s 0s 0s
Total time 4.66s 4.72s 0.06s

Reported by octocov

@yusukebe
Copy link
Member Author

yusukebe commented Jun 7, 2025

@cjnoname Can you review this?

@cjnoname
Copy link

cjnoname commented Jun 7, 2025

@cjnoname Can you review this?

Hey mate,

It doesn't work because once you consume the ArrayBuffer, the stream is no longer available—you'll need to recreate the request at that point.

This will work:

      let body: ArrayBuffer | ReadableStream<Uint8Array<ArrayBufferLike>> | null;
      if (options?.arrayBuffer) {
        body = await res.arrayBuffer();
        c.res = new Response(body, {
          status: res.status,
          statusText: res.statusText,
          headers: new Headers(res.headers)
        });
      } else {
        body = res.clone().body;
      }

@yusukebe yusukebe self-assigned this Jun 8, 2025
@yusukebe yusukebe removed the v4.8 label Jun 8, 2025
@yusukebe yusukebe marked this pull request as draft June 16, 2025 02:28
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.

ERROR: Body is unusable: Body has already been read

3 participants