Skip to content

Fix handling of default CorsOptions.allowed_headers#24703

Merged
spytheman merged 4 commits into
vlang:masterfrom
einar-hjortdal:veb_cors
Jun 13, 2025
Merged

Fix handling of default CorsOptions.allowed_headers#24703
spytheman merged 4 commits into
vlang:masterfrom
einar-hjortdal:veb_cors

Conversation

@einar-hjortdal

Copy link
Copy Markdown
Contributor

veb dev forgot about checking for default case

@huly-for-github

Copy link
Copy Markdown

Connected to Huly®: V_0.6-23058

@einar-hjortdal

Copy link
Copy Markdown
Contributor Author

Accidentally fixed another bug while I was at it

@spytheman

spytheman commented Jun 12, 2025

Copy link
Copy Markdown
Contributor

Please, add a test, to prevent future silent regressions.

@einar-hjortdal

Copy link
Copy Markdown
Contributor Author

Please, add a test, to prevent future silent regressions.

I am on it.
Do you have any idea why cors_test.v and cors_2_test.v are seemingly identical?

@JalonSolov

Copy link
Copy Markdown
Collaborator

Weird... they are identical, except for ctx vs context in a couple of places... neither would affect the tests.

@spytheman

Copy link
Copy Markdown
Contributor

vlib/veb/tests/cors_2_test.v was added in #23107 , which made sure, that if the context is passed explicitly, veb will still work, even though Alex added an edge case for implicitly passing context as an experiment (breaking compatibility with older veb apps).

TLDR: do not mind cors_2_test.v, it is unrelated, but needed to prevent regressions.
When you add your test, add it as a new file, or in cors_test.v, which uses mut ctx Context.

@einar-hjortdal

einar-hjortdal commented Jun 12, 2025

Copy link
Copy Markdown
Contributor Author

So, the test is a WIP: I recycled some code from the other test. It looks like the app instances created with a test do not exit fast enough for the next test. However, when running them individually, these tests do pass. I don't really know how to make it work, I would like suggestions or help.

Regarding changes:
I just removed the default allowed_headers ['*']. The wildcard does not work when requests have credentials, and checking for the default needlessly complicated the logic. If a user really wants the wildcard he can just set it, to me it seems a much more obvious choice than setting a wildcard as default and expecting users to provide an empty array if they do not want a wildcard instead.

Instead of calculating the cors_safelisted_response_headers.join(',') at every request, I made it a const. No other code used that.

Comment thread vlib/veb/tests/cors_regression_test.v Outdated
@einar-hjortdal

Copy link
Copy Markdown
Contributor Author

I'm using v compiled with these changes to develop an actual application and it works as expected.

@spytheman spytheman merged commit 6a3f12d into vlang:master Jun 13, 2025
64 checks passed
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.

3 participants