diff options
author | zeripath <art27@cantab.net> | 2021-07-21 04:32:35 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-21 11:32:35 +0800 |
commit | 28f6f7bb03884dd3d2c4ff17cdc6bf8916eb441d (patch) | |
tree | ba683cace199a3aa685e1d069dada4b2ca7019ee /modules/web | |
parent | 49bd9a111125da6fd9212e41ca5473a1faff0cf2 (diff) | |
download | gitea-28f6f7bb03884dd3d2c4ff17cdc6bf8916eb441d.tar.gz gitea-28f6f7bb03884dd3d2c4ff17cdc6bf8916eb441d.zip |
Restore CORS on git smart http protocol (#16496)
Unfortunately the chi changes have resulted in the CORS headers for the
git smart http protocol going missing.
This is mostly because the OPTIONS method is not being handled by
httpBase anymore.
This PR adds a GetOptions, PostOptions and Options methods to web
handler to allow OPTIONS method requests to still reach the httpBase
function.
Fix #16350
Close #16491
Signed-off-by: Andrew Thornton <art27@cantab.net>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Diffstat (limited to 'modules/web')
-rw-r--r-- | modules/web/route.go | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/modules/web/route.go b/modules/web/route.go index 319d08f598..3c6513da62 100644 --- a/modules/web/route.go +++ b/modules/web/route.go @@ -269,6 +269,26 @@ func (r *Route) Get(pattern string, h ...interface{}) { r.R.Get(r.getPattern(pattern), Wrap(middlewares...)) } +// Options delegate options method +func (r *Route) Options(pattern string, h ...interface{}) { + var middlewares = r.getMiddlewares(h) + r.R.Options(r.getPattern(pattern), Wrap(middlewares...)) +} + +// GetOptions delegate get and options method +func (r *Route) GetOptions(pattern string, h ...interface{}) { + var middlewares = r.getMiddlewares(h) + r.R.Get(r.getPattern(pattern), Wrap(middlewares...)) + r.R.Options(r.getPattern(pattern), Wrap(middlewares...)) +} + +// PostOptions delegate post and options method +func (r *Route) PostOptions(pattern string, h ...interface{}) { + var middlewares = r.getMiddlewares(h) + r.R.Post(r.getPattern(pattern), Wrap(middlewares...)) + r.R.Options(r.getPattern(pattern), Wrap(middlewares...)) +} + // Head delegate head method func (r *Route) Head(pattern string, h ...interface{}) { var middlewares = r.getMiddlewares(h) |