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

feat!: pass-through response status and headers to client #44

Merged

Conversation

mattmess1221
Copy link
Contributor

Breaking Change

πŸ”— Linked issue

Resolves #25 and #41

❓ Type of change

  • πŸ“– Documentation (updates to the documentation, readme or JSDoc annotations)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

This change forwards the status code and headers from the API to the client. It also ensures any api errors are forwarded to the client as is.

Since ofetch always reads the body no matter what, it has to be read in as an ArrayBuffer then converted to an Uint8Array.

An additional side-effect of this is the decoded body is forwarded instead of raw, which means if a content-encoding response header is set, it will be wrong. Removing this header corrects that.

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@netlify
Copy link

netlify bot commented Aug 30, 2023

βœ… Deploy Preview for nuxt-api-party ready!

Name Link
πŸ”¨ Latest commit 2c7f1c0
πŸ” Latest deploy log https://app.netlify.com/sites/nuxt-api-party/deploys/64f0e8e18c7a6c0008a9445e
😎 Deploy Preview https://deploy-preview-44--nuxt-api-party.netlify.app
πŸ“± Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@johannschopplich
Copy link
Owner

I love this approach. It should suit most use-cases and is worth a breaking change. Well done. πŸ‘

@johannschopplich
Copy link
Owner

Have you tested $fetch.raw behaves the same in other environments, like Cloudflare? Will test it a bit myself as well.

@mattmess1221
Copy link
Contributor Author

I don't see why it would behave differently. If anything, putting it behind cloudflare would either suppress or expose the issue if it re-compresses the response. Honestly, the only reason I noticed this was because jsonplaceholder comments had the header content-encoding: br

@johannschopplich johannschopplich changed the title feat: pass-through response status and headers to client feat!: pass-through response status and headers to client Aug 30, 2023
@johannschopplich johannschopplich merged commit 5a76bda into johannschopplich:main Aug 31, 2023
@mattmess1221 mattmess1221 deleted the feature/response-headers branch March 18, 2024 16:35
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.

Allow headers to pass-through to the response on the client
2 participants