mirror of
https://github.com/golang/go
synced 2024-11-11 23:10:23 -07:00
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
This commit is contained in:
parent
e82031618a
commit
c2b7fb3902
@ -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():]
|
||||
|
Loading…
Reference in New Issue
Block a user