LEFT | RIGHT |
(no file at all) | |
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 // post support | 9 // post support |
10 | 10 |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 header Header // reply header parameters | 110 header Header // reply header parameters |
111 written int64 // number of bytes written in body | 111 written int64 // number of bytes written in body |
112 contentLength int64 // explicitly-declared Content-Length; or -1 | 112 contentLength int64 // explicitly-declared Content-Length; or -1 |
113 status int // status code passed to WriteHeader | 113 status int // status code passed to WriteHeader |
114 | 114 |
115 // close connection after this reply. set on request and | 115 // close connection after this reply. set on request and |
116 // updated after response from handler if there's a | 116 // updated after response from handler if there's a |
117 // "Connection: keep-alive" response header and a | 117 // "Connection: keep-alive" response header and a |
118 // Content-Length. | 118 // Content-Length. |
119 closeAfterReply bool | 119 closeAfterReply bool |
| 120 } |
| 121 |
| 122 func (r *response) ReadFrom(src io.Reader) (int64, os.Error) { |
| 123 if !r.chunking { |
| 124 if rf, ok := r.conn.rwc.(io.ReaderFrom); ok { |
| 125 r.Flush() |
| 126 return rf.ReadFrom(src) |
| 127 } |
| 128 } |
| 129 return io.BufferedCopy(r, src) |
| 130 } |
| 131 |
| 132 func (r *response) ReadNFrom(src io.Reader, n int64) (int64, os.Error) { |
| 133 if !r.chunking { |
| 134 if rf, ok := r.conn.rwc.(io.ReaderNFrom); ok { |
| 135 r.Flush() |
| 136 return rf.ReadNFrom(src, n) |
| 137 } |
| 138 } |
| 139 return io.BufferedCopyn(r, src, n) |
120 } | 140 } |
121 | 141 |
122 // Create new connection from rwc. | 142 // Create new connection from rwc. |
123 func newConn(rwc net.Conn, handler Handler) (c *conn, err os.Error) { | 143 func newConn(rwc net.Conn, handler Handler) (c *conn, err os.Error) { |
124 c = new(conn) | 144 c = new(conn) |
125 c.remoteAddr = rwc.RemoteAddr().String() | 145 c.remoteAddr = rwc.RemoteAddr().String() |
126 c.handler = handler | 146 c.handler = handler |
127 c.rwc = rwc | 147 c.rwc = rwc |
128 br := bufio.NewReader(rwc) | 148 br := bufio.NewReader(rwc) |
129 bw := bufio.NewWriter(rwc) | 149 bw := bufio.NewWriter(rwc) |
(...skipping 857 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
987 func (tw *timeoutWriter) WriteHeader(code int) { | 1007 func (tw *timeoutWriter) WriteHeader(code int) { |
988 tw.mu.Lock() | 1008 tw.mu.Lock() |
989 if tw.timedOut || tw.wroteHeader { | 1009 if tw.timedOut || tw.wroteHeader { |
990 tw.mu.Unlock() | 1010 tw.mu.Unlock() |
991 return | 1011 return |
992 } | 1012 } |
993 tw.wroteHeader = true | 1013 tw.wroteHeader = true |
994 tw.mu.Unlock() | 1014 tw.mu.Unlock() |
995 tw.w.WriteHeader(code) | 1015 tw.w.WriteHeader(code) |
996 } | 1016 } |
LEFT | RIGHT |