twitter / finatra

Fast, testable, Scala services built on TwitterServer and Finagle
https://twitter.github.io/finatra/
Apache License 2.0
2.27k stars 408 forks source link

date from http header is incorrect in 2.4 #351

Closed odinliu closed 7 years ago

odinliu commented 8 years ago

fix HttpHeaders's Date locale problem

It comes again in v2.4. I think this could fix this problem:

diff --git a/http/src/main/scala/com/twitter/finatra/http/filters/HttpResponseFilter.scala b/http/src/main/scala/com/twitter/finatra/http/filters/HttpResponseFilter.scala
index 2ef3126..21e8b51 100644
--- a/http/src/main/scala/com/twitter/finatra/http/filters/HttpResponseFilter.scala
+++ b/http/src/main/scala/com/twitter/finatra/http/filters/HttpResponseFilter.scala
@@ -6,6 +6,7 @@ import com.twitter.finagle.{Service, SimpleFilter}
 import com.twitter.finatra.http.HttpHeaders
 import com.twitter.finatra.http.request.RequestUtils
 import com.twitter.util.{ScheduledThreadPoolTimer, Future}
+import java.util.Locale
 import java.util.TimeZone
 import javax.inject.Singleton
 import org.apache.commons.lang.time.FastDateFormat
@@ -19,7 +20,8 @@ import org.apache.commons.lang.time.FastDateFormat
 class HttpResponseFilter[R <: Request] extends SimpleFilter[R, Response] {

   // optimized
-  private val dateFormat = FastDateFormat.getInstance(HttpHeaders.RFC7231DateFormat, TimeZone.getTimeZone("GMT"))
+  private val dateFormat = FastDateFormat.getInstance(
+    HttpHeaders.RFC7231DateFormat, TimeZone.getTimeZone("GMT"), Locale.US)
   @volatile private var currentDateValue: String = getCurrentDateValue()
   new ScheduledThreadPoolTimer(
     poolSize = 1,
cacoco commented 8 years ago

@odinliu 👍

odinliu commented 7 years ago

@cacoco Submit a pr yet. Hopes this can be fixed in next release.