-
Notifications
You must be signed in to change notification settings - Fork 12
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
Locale Handler #126
Locale Handler #126
Conversation
Cool. Thanks for the enhancement. I got a couple of (small) things:
Thanks. |
@@ -4,86 +4,88 @@ | |||
* Default application values |
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.
Why did you re-order the Default enums? Makes it hard so seet, what was changed.
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 can undo it, but there seemed to be no particularly logical order. If you want I can put them back
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.
Would be nice to only see, what you have changed.
I have already done the Default value ( Later I'll move the setting key to be under Application and update the docs (and add a unit test). |
Sorry, missed that. |
Maybe it would also be nice to add a different create() method on the CookieBuilder class in such way the developer doesn't have to bother getting the right configured cookie name; public static CookieBuilder createLocale() {
String name = Application.getInstance(Config.class).getLocaleCookieName();
return new CookieBuilder(name);
} In controller; Cookie cookie = CookieBuilder.createLocale().value('NL').build();
return Response.withOk().andCookie(cookie).andEmptyBody(); |
That was the next thing I was going to work on, along with automatically |
@MarkVink +1 |
I wanted to create an integration test the LocaleHandler, but that's |
Also; I need to get better at checking before I commit |
I'm not sure if I agree on the changes on CookieBuilder.java;
|
In that case would you not set your host as the domain? I don't know much about using reverse-proxies. Either way it's a default, and in your situation would you not be manually overriding it yourself anyway?
Yeah I think your way was better, I'll do that. |
Oh I didn't notice your first implementation didn't follow the builder pattern by not returning I would prefer one of these; public static CookieBuilder createLocale() {
String name = Application.getInstance(Config.class).getLocaleCookieName();
return new CookieBuilder(name);
}
//CookieBuilder.createLocale().value('NL').build(); public static CookieBuilder createLocale(Locale locale) {
String name = Application.getInstance(Config.class).getLocaleCookieName();
return new CookieBuilder(name).value(locale.getISO3Language);
}
//CookieBuilder.createLocale(Locale.CHINA).build(); |
@@ -3,20 +3,26 @@ | |||
import java.time.LocalDateTime; | |||
import java.time.ZoneId; | |||
import java.util.Date; | |||
import java.util.Locale; |
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.
We do not need this import since Locale isn't used in CookieHandler (anymore).
By using the test utilities you could easily create a cookie and add it to the request and checking if the response has the correct language. I have added a method for adding a custom cookie in the lastest master push. |
@svenkubiak What are your thoughts on setting the cookie domain by default with the application host value? |
@MarkVink, @WilliamDunne
See: https://en.wikipedia.org/wiki/HTTP_cookie#Domain_and_Path Besides that, running a mangoo I/O application in the recommended way (behind a reverse-proxy) will result in errors if domains are not set correctly in prod/test and dev mode. |
I have moved this to 2.4.0 for now as I want to upgrade to undertow 1.3.15.Final (https://issues.jboss.org/projects/UNDERTOW/versions/12329419) as soon as it is released as it fixes some majob bugs. If we got this PR working in time, I will add it to 2.3.0 of course. |
Working? The only thing wrong is the default (didn't realize about the cookie domain, but it make sense). |
"Working" like "ready to merge". Build passing etc ;-) |
@MarkVink still used for creating locale cookie. I'll look at the build. |
@WilliamDunne I mean, its not necessary to instantiate it as a field in the CookieBuilder, since its only used one time, and only in the case the developer wants to set a language cookie. Move it to the createLocale method. |
Pull-able? |
@@ -403,6 +403,14 @@ public boolean isAuthenticationCookieSecure() { | |||
} | |||
|
|||
/** | |||
* @return i18n.cookie.name from application.yaml or default value if undefined |
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.
would be application.i18n.cookie.name, right?
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.
Done
I made some comments on the files. Also we still need that unit test for the locale cookie. If you need any help on that, just let me know. |
I could use some help with the unit test, not something I've done a large amount of |
No Problem. I look into it asap. |
I'll merge this and make some minor changes and add the unit test in the master. |
I have made some minor refactorings and added a unit test. Nothing fancy. However, I did remove the getLocaleCookie method from the CookieBuilder. I don't think it is a good idea, to have a builder within a builder just to have a short way of
We could introduce a CookieUtils class, but IMHO this fits most needs for now. |
Updated the LocaleHandler to use a cookie which can be
defined in the config file