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

增强 response 函数:允许定制返回状态码和返回头,支持返回非JSON序列化类型 #140

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

edgesite
Copy link

本PR解决的问题;

  • vite-plugin-mock 的 response 函数绑定了 middleware 的 this,可以支持访问 req, resp。但这种方法不够直观,并且在箭头函数下会失效。本PR直接将 req, resp 作为参数传入到 response 函数,可以让开发更加方便
  • 在 response 函数内设置了 statusCode 的情况下,不再覆盖 statusCode
  • 支持 response 返回 Buffer | UInt8Array类型,并在未指定 Content-Type 的情况下,自动添加 application/octet-stream
  • 在 response 函数返回 undefined 时,响应 204 No Content
  • 在 response 函数返回 string 类型时,不做 JSON encode

相关Issues:
#132
#137

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.

1 participant