Forcing requests to be UTF-8
This commit is contained in:
parent
a2c80d19fb
commit
0163ea41c7
1 changed files with 4 additions and 1 deletions
|
@ -1,5 +1,7 @@
|
||||||
package com.moandjiezana.tent.essayist.config;
|
package com.moandjiezana.tent.essayist.config;
|
||||||
|
|
||||||
|
import com.google.common.base.Charsets;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
@ -17,8 +19,9 @@ public class Utf8Filter implements Filter {
|
||||||
@Override
|
@Override
|
||||||
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
|
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
|
||||||
HttpServletRequest req = (HttpServletRequest) request;
|
HttpServletRequest req = (HttpServletRequest) request;
|
||||||
|
req.setCharacterEncoding(Charsets.UTF_8.toString());
|
||||||
if (!"application/json".equals(req.getHeader("Accept"))) {
|
if (!"application/json".equals(req.getHeader("Accept"))) {
|
||||||
response.setContentType("text/html;charset=utf-8");
|
response.setContentType("text/html;charset=" + Charsets.UTF_8);
|
||||||
}
|
}
|
||||||
|
|
||||||
chain.doFilter(request, response);
|
chain.doFilter(request, response);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue