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

Use middleware but not new routers for http cors #16566

Closed
wants to merge 5 commits into from

Conversation

lunny
Copy link
Member

@lunny lunny commented Jul 28, 2021

  • Use middlewares but not new router methods for HTTP
  • Added an extra route to ensue options will be requested to the middlewares.
  • Rename GetOptions / PostOptions back to Get / Post
  • Allow multiple websites on ACCESS_CONTROL_ALLOW_ORIGIN
  • Update the docs.

@lunny lunny added the type/refactoring Existing code has been cleaned up. There should be no new functionality. label Jul 28, 2021
@zeripath
Copy link
Contributor

You still need the OPTIONS routes in otherwise the main CORS handler will fire instead and we'll be back at the point that caused me having to add them in in the first place in #16496.

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Jul 28, 2021
@lunny
Copy link
Member Author

lunny commented Jul 29, 2021

You still need the OPTIONS routes in otherwise the main CORS handler will fire instead and we'll be back at the point that caused me having to add them in in the first place in #16496.

The middleware have checked the OPTIONS method. Why we still need the routes?

@zeripath
Copy link
Contributor

HTTPCors will never see the options request as they will not be routed to it.

@lunny
Copy link
Member Author

lunny commented Jul 29, 2021

HTTPCors will never see the options request as they will not be routed to it.

OK. You are right. It seems group middlewares will not be fired if no the method handler in this group.
As a temporory resolution, I just added a placeholder options blank handler there to ensure the middlewares will be invoked.
And to resolve the problem totally, route group should be done some adjustments.

m.Get("/objects/{head:[0-9a-f]{2}}/{hash:[0-9a-f]{38}}", repo.GetLooseObject)
m.Get("/objects/pack/pack-{file:[0-9a-f]{40}}.pack", repo.GetPackFile)
m.Get("/objects/pack/pack-{file:[0-9a-f]{40}}.idx", repo.GetIdxFile)
m.Options("/", func(ctx *context.Context) {}) // to ensure middlewares could handle options requests
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIU This isn't going to fire on OPTIONS /git-upload-pack etc.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please review again.

@lunny lunny force-pushed the lunny/http_refactor branch 2 times, most recently from f1259f3 to 8209365 Compare August 7, 2021 02:39
@wxiaoguang
Copy link
Contributor

#24303 fixed the old CORS handler.

@wxiaoguang wxiaoguang added the issue/needs-feedback For bugs, we need more details. For features, the feature must be described in more detail label Apr 26, 2023
@lunny lunny closed this Apr 26, 2023
@lunny lunny deleted the lunny/http_refactor branch April 26, 2023 03:02
@go-gitea go-gitea locked as resolved and limited conversation to collaborators Aug 1, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
issue/needs-feedback For bugs, we need more details. For features, the feature must be described in more detail lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. type/refactoring Existing code has been cleaned up. There should be no new functionality.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants