Issue #29: use time.UTC instead of time.LoadLocation, since this call may fail on systems without certain config files

This commit is contained in:
Aliaksandr Valialkin
2016-01-04 15:55:30 +02:00
parent a89d890c8c
commit 4bca54c0bb
4 changed files with 6 additions and 11 deletions
+3 -9
View File
@@ -12,14 +12,6 @@ import (
"unsafe"
)
var gmtLocation = func() *time.Location {
x, err := time.LoadLocation("GMT")
if err != nil {
panic(fmt.Sprintf("cannot load GMT location: %s", err))
}
return x
}()
// AppendIPv4 appends string representation of the given ip v4 to dst
// and returns the extended dst.
func AppendIPv4(dst []byte, ip net.IP) []byte {
@@ -78,7 +70,9 @@ func ParseIPv4(dst net.IP, ipStr []byte) (net.IP, error) {
// AppendHTTPDate appends HTTP-compliant (RFC1123) representation of date
// to dst and returns the extended dst.
func AppendHTTPDate(dst []byte, date time.Time) []byte {
return date.In(gmtLocation).AppendFormat(dst, time.RFC1123)
dst = date.In(time.UTC).AppendFormat(dst, time.RFC1123)
copy(dst[len(dst)-3:], strGMT)
return dst
}
// ParseHTTPDate parses HTTP-compliant (RFC1123) date.
+1 -1
View File
@@ -218,7 +218,7 @@ func (c *Cookie) ParseBytes(src []byte) error {
switch {
case bytes.Equal(strCookieExpires, kv.key):
v := unsafeBytesToStr(kv.value)
exptime, err := time.ParseInLocation(time.RFC1123, v, gmtLocation)
exptime, err := time.ParseInLocation(time.RFC1123, v, time.UTC)
if err != nil {
return err
}
+1 -1
View File
@@ -938,7 +938,7 @@ func fsLastModified(path string) (time.Time, error) {
}
func fsModTime(t time.Time) time.Time {
return t.In(gmtLocation).Truncate(time.Second)
return t.In(time.UTC).Truncate(time.Second)
}
var (
+1
View File
@@ -18,6 +18,7 @@ var (
strHTTP11 = []byte("HTTP/1.1")
strColonSlashSlash = []byte("://")
strColonSpace = []byte(": ")
strGMT = []byte("GMT")
strResponseContinue = []byte("HTTP/1.1 100 Continue\r\n\r\n")