-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Allows to change the default ErrorHandler response type #11522
Conversation
I think URI Violations happen after all of the headers are fully parsed, and before the dispatch to the handler tree. |
@joakime But for some reason in the ErrorHandler the request headers are empty. I created an issue with test case for that. However, independently of that, I thought it would be great to be able to change the default response content type for the error handler, in case a client does not specify any Accept header. |
protected Type defaultResponseMimeType() { | ||
return Type.TEXT_HTML; | ||
} | ||
|
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 don't mind the idea of being able to configure a default response content type.
Please:
- Make a field
defaultResponseContentType
, withpublic
getters and setters (so there is no need to extendErrorHandler
). - Write a test case in
org.eclipse.jetty.server.ErrorHandlerTest
.
Let us know if you are willing to do the above.
Thanks!
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.
Sounds good. I can look into that.
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.
@sbordet I applied & pushed the changes. Hope that is what you meant :)
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.
@dhs3000 just a couple more changes and we should be good.
@@ -74,6 +74,7 @@ public class ErrorHandler implements Request.Handler | |||
|
|||
boolean _showStacks = true; | |||
boolean _showMessageInTitle = true; | |||
Type _defaultResponseMimeType = Type.TEXT_HTML; |
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.
Please use String
, so that it will be easier to configure also from XML.
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.
Type is changed to String
*/ | ||
public void setDefaultResponseMimeType(Type defaultResponseMimeType) | ||
{ | ||
_defaultResponseMimeType = defaultResponseMimeType; |
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.
_defaultResponseMimeType = defaultResponseMimeType; | |
_defaultResponseMimeType = Objects.requireNonNull(defaultResponseMimeType); |
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.
Type is changed to String and also uses the requireNonNull
helper now
"GET / HTTP/1.1\r\n" + | ||
"Host: Localhost\r\n" + | ||
"\r\n"); |
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.
Use a text block here 😃
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.
Haven't used Java in years ;-) Nice that that is possible. I updated the test.
… it can be configured through XML
@sbordet I applied the requested changes, let me know if anything else :) |
@dhs3000 Thanks! |
Currently, the server returns HTML responses by default. It would be great to easily change this without having to overwrite the whole error handler.
The error handler tries to find the right/accepted response type using the
ACCEPT
header, but in some cases the header is not yet there when an error happens, e.g. with an URI violation, it seems the request is not yet fully parsed and therefore the requested content type not recognised.