matrix-org / dendrite

Dendrite is a second-generation Matrix homeserver written in Go!
https://matrix-org.github.io/dendrite/
Apache License 2.0
5.74k stars 678 forks source link

Make OPTIONS method on MSC3916 endpoints available without auth #3431

Closed arenekosreal closed 2 months ago

arenekosreal commented 2 months ago

OPTIONS method is usually sent by browser in preflight requests, most of the time we cannot control preflight request to add auth header.

Synapse will return a 204 response directly without authentication for those OPTIONS method.

According to firefox's documentation, both 200 and 204 are acceptable so I think there is no need to change handler in dendrite.

This closes https://github.com/matrix-org/dendrite/issues/3424

No need to add a test because this is just a fix and I have tested on my Cinny Web client personally.

Pull Request Checklist

Signed-off-by: arenekosreal <17194552+arenekosreal@users.noreply.github.com>

arenekosreal commented 2 months ago

I have changed the code to check OPTIONS in MakeHTTPAPI, I must say the diff is much cleaner than the old one.

codecov[bot] commented 2 months ago

Codecov Report

Attention: Patch coverage is 0% with 4 lines in your changes missing coverage. Please review.

Project coverage is 68.36%. Comparing base (f2db7cb) to head (29028d7). Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
internal/httputil/httpapi.go 0.00% 4 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #3431 +/- ## ========================================== + Coverage 68.34% 68.36% +0.02% ========================================== Files 513 513 Lines 47026 47030 +4 ========================================== + Hits 32138 32153 +15 + Misses 10896 10886 -10 + Partials 3992 3991 -1 ``` | [Flag](https://app.codecov.io/gh/matrix-org/dendrite/pull/3431/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=matrix-org) | Coverage Δ | | |---|---|---| | [unittests](https://app.codecov.io/gh/matrix-org/dendrite/pull/3431/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=matrix-org) | `53.35% <0.00%> (+0.03%)` | :arrow_up: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=matrix-org#carryforward-flags-in-the-pull-request-comment) to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.