Commit c2b7fb39 authored by Dmitry Chestnykh's avatar Dmitry Chestnykh Committed by Brad Fitzpatrick

net/http: send correct time in Date header.

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
parent e8203161
......@@ -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()
......
......@@ -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()
......
......@@ -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():]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment