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 package http | 7 package http |
8 | 8 |
9 import ( | 9 import ( |
10 "bufio" | 10 "bufio" |
(...skipping 1796 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1807 // spec as being reserved for future use), but anything | 1807 // spec as being reserved for future use), but anything |
1808 // over that is considered a waste of server resources | 1808 // over that is considered a waste of server resources |
1809 // (or an attack) and we abort and close the connection, | 1809 // (or an attack) and we abort and close the connection, |
1810 // courtesy of MaxBytesReader's EOF behavior. | 1810 // courtesy of MaxBytesReader's EOF behavior. |
1811 mb := MaxBytesReader(w, r.Body, 4<<10) | 1811 mb := MaxBytesReader(w, r.Body, 4<<10) |
1812 io.Copy(ioutil.Discard, mb) | 1812 io.Copy(ioutil.Discard, mb) |
1813 } | 1813 } |
1814 } | 1814 } |
1815 | 1815 |
1816 // eofReader is a non-nil io.ReadCloser that always returns EOF. | 1816 // eofReader is a non-nil io.ReadCloser that always returns EOF. |
1817 var eofReader = ioutil.NopCloser(strings.NewReader("")) | 1817 // It embeds a *strings.Reader so it still has a WriteTo method |
| 1818 // and io.Copy won't need a buffer. |
| 1819 var eofReader = &struct { |
| 1820 » *strings.Reader |
| 1821 » io.Closer |
| 1822 }{ |
| 1823 » strings.NewReader(""), |
| 1824 » ioutil.NopCloser(nil), |
| 1825 } |
1818 | 1826 |
1819 // initNPNRequest is an HTTP handler that initializes certain | 1827 // initNPNRequest is an HTTP handler that initializes certain |
1820 // uninitialized fields in its *Request. Such partially-initialized | 1828 // uninitialized fields in its *Request. Such partially-initialized |
1821 // Requests come from NPN protocol handlers. | 1829 // Requests come from NPN protocol handlers. |
1822 type initNPNRequest struct { | 1830 type initNPNRequest struct { |
1823 c *tls.Conn | 1831 c *tls.Conn |
1824 h serverHandler | 1832 h serverHandler |
1825 } | 1833 } |
1826 | 1834 |
1827 func (h initNPNRequest) ServeHTTP(rw ResponseWriter, req *Request) { | 1835 func (h initNPNRequest) ServeHTTP(rw ResponseWriter, req *Request) { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1872 log.Printf("%s.Read(%d) = %d, %v", c.name, len(p), n, err) | 1880 log.Printf("%s.Read(%d) = %d, %v", c.name, len(p), n, err) |
1873 return | 1881 return |
1874 } | 1882 } |
1875 | 1883 |
1876 func (c *loggingConn) Close() (err error) { | 1884 func (c *loggingConn) Close() (err error) { |
1877 log.Printf("%s.Close() = ...", c.name) | 1885 log.Printf("%s.Close() = ...", c.name) |
1878 err = c.Conn.Close() | 1886 err = c.Conn.Close() |
1879 log.Printf("%s.Close() = %v", c.name, err) | 1887 log.Printf("%s.Close() = %v", c.name, err) |
1880 return | 1888 return |
1881 } | 1889 } |
OLD | NEW |