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
enable updating of publicHost through server config #712
Conversation
Would you be able to build a local image and test it locally with testContainers-go? (sorry not totally familiar with that library) |
Yeah looking at the code I think this won't be enough because the publicHost is used once during the server initialization: fake-gcs-server/fakestorage/server.go Lines 215 to 269 in 71fdd6b
I think we'll need to use gorilla's MatcherFunc instead of |
Yeah, I was just doing that and unfortunately, this change alone isn't going be sufficient, because the server and muxer won't pick it up. I'll look into how to do that. edit: matcherfunc, ok, thanks! |
fba1be0
to
d23a4c5
Compare
d23a4c5
to
910e099
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you very much for contributing, just one question about a test to check the behavior.
s.mux.Path("/batch/storage/v1").Methods(http.MethodPost).HandlerFunc(s.handleBatchCall) | ||
|
||
s.mux.Host(s.publicHost).Path("/{bucketName}/{objectName:.+}").Methods(http.MethodGet, http.MethodHead).HandlerFunc(s.downloadObject) | ||
s.mux.MatcherFunc(s.publicHostMatcher).Path("/{bucketName}/{objectName:.+}").Methods(http.MethodGet, http.MethodHead).HandlerFunc(s.downloadObject) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we extend one of the tests for these routes to test this scenario where the publicHost changes after the server is instantiated? (no need to invoke the internal config endpoint, we can simply mutate it directly in the test)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a new test, TestDownloadAfterPublicHostChange.
I think this PR introduced a change in route matching behaviour which broke a couple of implementations (amongst them ours). The original host matcher from gorilla/mux: original host matcher enabled adding only the host (without port) as the public-host (and still matching on it) when starting the fake server, example: This seems to be because the new matcher is looking for an exact match, while the original one used a regexp matcher (from the documentation: "{name} matches anything until the next dot."). It can be that this new behaviour is the only originally intended one too, however I wanted to point this out. |
Oh interesting, I didn't realize gorilla/mux treated the string as a regexp. Thank you very much for pointing that out! I guess we can fix that to keep the previous behavior. I'll send a change and make sure we have a test to prevent regressions in the future. |
Sorry about the trouble, folks 😬 |
Potentially fixes #711