google / volley

https://google.github.io/volley
Apache License 2.0
3.37k stars 751 forks source link

Volley unable to parse dateStr #436

Closed alexfu2011 closed 2 years ago

alexfu2011 commented 2 years ago

E/Volley: [631] HttpHeaderParser.parseDateAsEpoch: Unable to parse dateStr: Thu, 10 Feb 2022 12:05:37 Asia/Shanghai, falling back to 0 java.text.ParseException: Unparseable date: "Thu, 10 Feb 2022 12:05:37 Asia/Shanghai" at java.text.DateFormat.parse(DateFormat.java:362) at com.android.volley.toolbox.HttpHeaderParser.parseDateAsEpoch(HttpHeaderParser.java:135) at com.android.volley.toolbox.HttpHeaderParser.parseCacheHeaders(HttpHeaderParser.java:102) at com.android.volley.toolbox.StringRequest.parseNetworkResponse(StringRequest.java:98) at com.android.volley.NetworkDispatcher.processRequest(NetworkDispatcher.java:143) at com.android.volley.NetworkDispatcher.processRequest(NetworkDispatcher.java:111) at com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:90)

jpd236 commented 2 years ago

This is a non-fatal error logged when the server returns an invalid Date/Expires/Last-Modified header. As best as I can tell, RFC1123 states that it uses RFC822 (with minor tweaks), which does not permit "Asia/Shanghai" to be used as a timezone.

In this case, Volley logs a warning, but assumes the dates are all "0", which means the responses won't be cached at all, but otherwise wouldn't impact your application. The server should be fixed to follow HTTP specifications. That said, I'm open to a general workaround which makes Volley's parser more flexible around timezones if there's evidence that this is a common problem.