Skip to content

Commit

Permalink
Fixed SimpleDateFormat bug. Should use new SimpleDateFormat(HTTP_DATE…
Browse files Browse the repository at this point in the history
…_FORMAT, Locale.US), otherwise when running on for example Japanese OS, the resulting date would contains Japanese characters, and the browser would not be able to parse!
  • Loading branch information
veebs authored and trustin committed Apr 18, 2011
1 parent a85249c commit eb6ec29
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Locale;
import java.util.TimeZone;

import javax.activation.MimetypesFileTypeMap;
Expand Down Expand Up @@ -128,7 +129,7 @@ public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Ex
String ifModifiedSince = request.getHeader(HttpHeaders.Names.IF_MODIFIED_SINCE);
if (ifModifiedSince != null && !ifModifiedSince.equals(""))
{
SimpleDateFormat dateFormatter = new SimpleDateFormat(HTTP_DATE_FORMAT);
SimpleDateFormat dateFormatter = new SimpleDateFormat(HTTP_DATE_FORMAT, Locale.US);
Date ifModifiedSinceDate = dateFormatter.parse(ifModifiedSince);
if (ifModifiedSinceDate.getTime() == file.lastModified())
{
Expand Down Expand Up @@ -264,7 +265,7 @@ private void sendNotModified(ChannelHandlerContext ctx) {
* file to extract content type
*/
private void setDateHeader(HttpResponse response) {
SimpleDateFormat dateFormatter = new SimpleDateFormat(HTTP_DATE_FORMAT);
SimpleDateFormat dateFormatter = new SimpleDateFormat(HTTP_DATE_FORMAT, Locale.US);
dateFormatter.setTimeZone(TimeZone.getTimeZone(HTTP_DATE_GMT_TIMEZONE));

Calendar time = new GregorianCalendar();
Expand All @@ -280,7 +281,7 @@ private void setDateHeader(HttpResponse response) {
* file to extract content type
*/
private void setDateAndCacheHeaders(HttpResponse response, File filetoCache) {
SimpleDateFormat dateFormatter = new SimpleDateFormat(HTTP_DATE_FORMAT);
SimpleDateFormat dateFormatter = new SimpleDateFormat(HTTP_DATE_FORMAT, Locale.US);
dateFormatter.setTimeZone(TimeZone.getTimeZone(HTTP_DATE_GMT_TIMEZONE));

// Date header
Expand Down

0 comments on commit eb6ec29

Please sign in to comment.