]> Cypherpunks repositories - gostls13.git/commitdiff
net/http: send correct time in Date header.
authorDmitry Chestnykh <dchest@gmail.com>
Mon, 23 Sep 2013 02:53:55 +0000 (19:53 -0700)
committerBrad Fitzpatrick <bradfitz@golang.org>
Mon, 23 Sep 2013 02:53:55 +0000 (19:53 -0700)
Date header indicated that it contained GMT time,
however it actually sent local time. Fixed by
converting time to UTC.

Also fixes incorrect comment in appendTime().

Regression since CL 9432046.

R=golang-dev, dave, bradfitz
CC=golang-dev
https://golang.org/cl/13386047

src/pkg/net/http/export_test.go
src/pkg/net/http/serve_test.go
src/pkg/net/http/server.go

index 271ff4df9c3f0eb5eb46e314f0b4dd7d41ebef72..22b7f279689bccdb78e1aa3233ae4b366a84d50e 100644 (file)
@@ -16,6 +16,8 @@ func NewLoggingConn(baseName string, c net.Conn) net.Conn {
        return newLoggingConn(baseName, c)
 }
 
+var ExportAppendTime = appendTime
+
 func (t *Transport) NumPendingRequestsForTesting() int {
        t.reqMu.Lock()
        defer t.reqMu.Unlock()
index c7c842b2fdb7e4b759c6cf272ea4bc319c4f42eb..d5ee6e0e8af5f4fd1523b9a7df332b5c1199ea0f 100644 (file)
@@ -2080,6 +2080,19 @@ func TestResponseWriterWriteStringAllocs(t *testing.T) {
        }
 }
 
+func TestAppendTime(t *testing.T) {
+       var b [len(TimeFormat)]byte
+       t1 := time.Date(2013, 9, 21, 15, 41, 0, 0, time.FixedZone("CEST", 2*60*60))
+       res := ExportAppendTime(b[:0], t1)
+       t2, err := ParseTime(string(res))
+       if err != nil {
+               t.Fatalf("Error parsing time: %s", err)
+       }
+       if !t1.Equal(t2) {
+               t.Fatalf("Times differ; expected: %v, got %v (%s)", t1, t2, string(res))
+       }
+}
+
 func BenchmarkClientServer(b *testing.B) {
        b.ReportAllocs()
        b.StopTimer()
index 67f175fd6e6487ba3167a73c64957f2ae4948bdc..cc0b4e237b0d263f2015df1276c6c756225faafc 100644 (file)
@@ -530,11 +530,12 @@ func (ecr *expectContinueReader) Close() error {
 // It is like time.RFC1123 but hard codes GMT as the time zone.
 const TimeFormat = "Mon, 02 Jan 2006 15:04:05 GMT"
 
-// appendTime is a non-allocating version of []byte(time.Now().UTC().Format(TimeFormat))
+// appendTime is a non-allocating version of []byte(t.UTC().Format(TimeFormat))
 func appendTime(b []byte, t time.Time) []byte {
        const days = "SunMonTueWedThuFriSat"
        const months = "JanFebMarAprMayJunJulAugSepOctNovDec"
 
+       t = t.UTC()
        yy, mm, dd := t.Date()
        hh, mn, ss := t.Clock()
        day := days[3*t.Weekday():]