OLD | NEW |
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 // HTTP server. See RFC 2616. | 5 // HTTP server. See RFC 2616. |
6 | 6 |
7 // TODO(rsc): | 7 // TODO(rsc): |
8 // logging | 8 // logging |
9 | 9 |
10 package http | 10 package http |
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 log.Printf("http: invalid Content-Length of %q sent", cl
enStr) | 296 log.Printf("http: invalid Content-Length of %q sent", cl
enStr) |
297 w.header.Del("Content-Length") | 297 w.header.Del("Content-Length") |
298 } | 298 } |
299 } | 299 } |
300 | 300 |
301 if w.req.wantsHttp10KeepAlive() && (w.req.Method == "HEAD" || hasCL) { | 301 if w.req.wantsHttp10KeepAlive() && (w.req.Method == "HEAD" || hasCL) { |
302 _, connectionHeaderSet := w.header["Connection"] | 302 _, connectionHeaderSet := w.header["Connection"] |
303 if !connectionHeaderSet { | 303 if !connectionHeaderSet { |
304 w.header.Set("Connection", "keep-alive") | 304 w.header.Set("Connection", "keep-alive") |
305 } | 305 } |
306 » } else if !w.req.ProtoAtLeast(1, 1) { | 306 » } else if !w.req.ProtoAtLeast(1, 1) || w.req.wantsClose() { |
307 » » // Client did not ask to keep connection alive. | |
308 w.closeAfterReply = true | 307 w.closeAfterReply = true |
309 } | 308 } |
310 | 309 |
311 if w.header.Get("Connection") == "close" { | 310 if w.header.Get("Connection") == "close" { |
312 w.closeAfterReply = true | 311 w.closeAfterReply = true |
313 } | 312 } |
314 | 313 |
315 // Per RFC 2616, we should consume the request body before | 314 // Per RFC 2616, we should consume the request body before |
316 // replying, if the handler hasn't already done so. But we | 315 // replying, if the handler hasn't already done so. But we |
317 // don't want to do an unbounded amount of reading here for | 316 // don't want to do an unbounded amount of reading here for |
(...skipping 909 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1227 func (tw *timeoutWriter) WriteHeader(code int) { | 1226 func (tw *timeoutWriter) WriteHeader(code int) { |
1228 tw.mu.Lock() | 1227 tw.mu.Lock() |
1229 if tw.timedOut || tw.wroteHeader { | 1228 if tw.timedOut || tw.wroteHeader { |
1230 tw.mu.Unlock() | 1229 tw.mu.Unlock() |
1231 return | 1230 return |
1232 } | 1231 } |
1233 tw.wroteHeader = true | 1232 tw.wroteHeader = true |
1234 tw.mu.Unlock() | 1233 tw.mu.Unlock() |
1235 tw.w.WriteHeader(code) | 1234 tw.w.WriteHeader(code) |
1236 } | 1235 } |
OLD | NEW |