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

Fix CORS support in WHEP/WHIP API #798

Merged
merged 3 commits into from
Dec 5, 2023
Merged

Fix CORS support in WHEP/WHIP API #798

merged 3 commits into from
Dec 5, 2023

Conversation

MPTres
Copy link

@MPTres MPTres commented Dec 4, 2023

Browsers don't allow WHIP/WHEP API calls to the go2rtc server when they are directed to a different domain, even when all origins are allowed in go2rtc configuration.

api:
  origin: "*"  

The problem it that when browsers detect a POST to another domain, they usually send first a Preflight Request. This is an OPTIONS request to verify with the server if that's allowed. The server needs to reply with a 'No content' status , and some headers with information about what's allowed. Right now, go2rtc just returns a "Method not allowed" response, which prevents the browser from sending the actual POST.

This change adds an OPTIONS handler and some allowed headers, so that the cors WHEP/WHIP requests can be accepted by the browser.

@AlexxIT
Copy link
Owner

AlexxIT commented Dec 4, 2023

There you get X-PINGOTHER header?

@skrashevich
Copy link
Contributor

it's example of non-standard header from Mozilla docs :)

@MPTres
Copy link
Author

MPTres commented Dec 5, 2023

X-PINGOTHER

i saw that on the reference docs in mozilla, and added it too. I see now that it's not a standard, just an example :).
I'll remove it. The content-type is the important one in order to allow json or sdp.

@AlexxIT
Copy link
Owner

AlexxIT commented Dec 5, 2023

@MPTres also you have added unnecessary empty line after new header

@MPTres
Copy link
Author

MPTres commented Dec 5, 2023

@MPTres also you have added unnecessary empty line after new header

Fixed

@AlexxIT AlexxIT merged commit 39d8762 into AlexxIT:master Dec 5, 2023
@AlexxIT
Copy link
Owner

AlexxIT commented Dec 5, 2023

Thanks

@skrashevich
Copy link
Contributor

skrashevich commented Dec 5, 2023

The content-type is the important one in order to allow json or sdp.

nope
https://developer.mozilla.org/en-US/docs/Glossary/CORS-safelisted_request_header

@MPTres
Copy link
Author

MPTres commented Dec 5, 2023

The content-type is the important one in order to allow json or sdp.

nope https://developer.mozilla.org/en-US/docs/Glossary/CORS-safelisted_request_header

that actually says that the safelisted content values are: application/x-www-form-urlencoded, multipart/form-data, or text/plain
That is consistent with my tests with json and sdp types, where the browser refused the connection if the server did not explicitly allow the content header to be sent .

@MPTres MPTres deleted the cors branch December 5, 2023 16:34
@AlexxIT AlexxIT added this to the v1.8.5 milestone Jan 1, 2024
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.

None yet

3 participants