-
Notifications
You must be signed in to change notification settings - Fork 38.5k
Allow adding registration directly in ResourceHandlerRegistry #34967
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
Allow adding registration directly in ResourceHandlerRegistry #34967
Conversation
Signed-off-by: 秦利斌 <[email protected]>
9188348
to
50d7a11
Compare
Signed-off-by: 秦利斌 <[email protected]>
protected @Nullable MediaType getMediaType(HttpServletRequest request, Resource resource) { | ||
String filename = resource.getFilename(); | ||
String ext = StringUtils.getFilenameExtension(filename); | ||
if (!StringUtils.hasText(ext)) { |
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.
Suggestion:
Currently, the custom handler assumes that resources without a file extension are of type text/html. However may not work well for different context type. To make it more flexible, maybe allowing the user to configure the type gives more control/flexibility and can support many use cases.
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.
Suggestion: Currently, the custom handler assumes that resources without a file extension are of type text/html. However may not work well for different context type. To make it more flexible, maybe allowing the user to configure the type gives more control/flexibility and can support many use cases.
This is just an example to illustrate its use case.
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.
- This PR adds a new method to ResourceHandlerRegistry that lets developers add a fully customised ResourceHandlerRegistration instances directly.
- Improves flexibility and reduces boilerplate config without altering the existing API.
- Clean and useful edition for users that want more control.
- Introduces overloaded addResourceHandler(ResourceHandlerRegistration registration) method that extends the API.
Suggestions
- Currently the custom handler assumes resources without a file extension are of type text/html hence possible solutions:
- Allowing the default type to be configurable helps support different use cases.
- Look for a file with .html extension, serving if that is found or responding with a 404 error.
- Log for a warning
Thanks for the proposal but I don't think this is needed. Registering a custom |
Allow to add
ResourceHandlerRegistration
directly toResourceHandlerRegistry
.That allows to add subtypes of
ResourceHandlerRegistration
to create custom instance ofResourceHttpRequestHandler
.For example, we can add a custom registration which creates a custom handler reolving media type of resources without filename extension to "text/html".