Skip to content

Add cors capability to http-controller #30

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

Open
wants to merge 6 commits into
base: dev
Choose a base branch
from

Conversation

fantasy0v0
Copy link

#29

@fantasy0v0
Copy link
Author

Unit tests are still missing, and I will add them when I have time.

@wkgcass
Copy link
Owner

wkgcass commented Oct 10, 2024

建议把cors做成通用功能,放到http框架里
目前http框架支持request方向的chain,可以做Origin的校验
但是不支持response方向的chain。一个比较简单的方法是,在ctx中增加一个onResponse回调chain,在request方向注册回调,然后在headers发送前调用这组回调,这样即可添加response headers

这个基础功能实现后,可以跟jsonHandler类似,加一个corsHandler,专门检查Origin、添加Access-Control-Allow-Origin、处理Option请求

然后再在命令行添加cors相关配置

那个secret也应该做成一个单独的basicAuthHandler

@fantasy0v0 fantasy0v0 force-pushed the dev branch 2 times, most recently from 32cd4ef to f4bd689 Compare October 12, 2024 07:40
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.

2 participants