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 // cgi support | 9 // cgi support |
10 // post support | 10 // post support |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 ecr.conn.buf.Flush() | 94 ecr.conn.buf.Flush() |
95 } | 95 } |
96 } | 96 } |
97 return ecr.readCloser.Read(p) | 97 return ecr.readCloser.Read(p) |
98 } | 98 } |
99 | 99 |
100 func (ecr *expectContinueReader) Close() os.Error { | 100 func (ecr *expectContinueReader) Close() os.Error { |
101 return ecr.readCloser.Close() | 101 return ecr.readCloser.Close() |
102 } | 102 } |
103 | 103 |
| 104 // TimeFormat is the time format to use with |
| 105 // time.Parse and time.Time.Format when parsing |
| 106 // or generating times in HTTP headers. |
| 107 // It is like time.RFC1123 but hard codes GMT as the time zone. |
| 108 const TimeFormat = "Mon, 02 Jan 2006 15:04:05 GMT" |
| 109 |
104 // Read next request from connection. | 110 // Read next request from connection. |
105 func (c *Conn) readRequest() (req *Request, err os.Error) { | 111 func (c *Conn) readRequest() (req *Request, err os.Error) { |
106 if c.hijacked { | 112 if c.hijacked { |
107 return nil, ErrHijacked | 113 return nil, ErrHijacked |
108 } | 114 } |
109 if req, err = ReadRequest(c.buf.Reader); err != nil { | 115 if req, err = ReadRequest(c.buf.Reader); err != nil { |
110 return nil, err | 116 return nil, err |
111 } | 117 } |
112 | 118 |
113 // Reset per-request connection state. | 119 // Reset per-request connection state. |
114 c.header = make(map[string]string) | 120 c.header = make(map[string]string) |
115 c.wroteHeader = false | 121 c.wroteHeader = false |
116 c.wroteContinue = false | 122 c.wroteContinue = false |
117 c.Req = req | 123 c.Req = req |
118 | 124 |
119 // Expect 100 Continue support | 125 // Expect 100 Continue support |
120 if req.expectsContinue() { | 126 if req.expectsContinue() { |
121 // Wrap the Body reader with one that replies on the connection | 127 // Wrap the Body reader with one that replies on the connection |
122 req.Body = &expectContinueReader{readCloser: req.Body, conn: c} | 128 req.Body = &expectContinueReader{readCloser: req.Body, conn: c} |
123 } | 129 } |
124 | 130 |
125 // Default output is HTML encoded in UTF-8. | 131 // Default output is HTML encoded in UTF-8. |
126 c.SetHeader("Content-Type", "text/html; charset=utf-8") | 132 c.SetHeader("Content-Type", "text/html; charset=utf-8") |
| 133 c.SetHeader("Date", time.UTC().Format(TimeFormat)) |
127 | 134 |
128 if req.ProtoAtLeast(1, 1) { | 135 if req.ProtoAtLeast(1, 1) { |
129 // HTTP/1.1 or greater: use chunked transfer encoding | 136 // HTTP/1.1 or greater: use chunked transfer encoding |
130 // to avoid closing the connection at EOF. | 137 // to avoid closing the connection at EOF. |
131 c.chunking = true | 138 c.chunking = true |
132 c.SetHeader("Transfer-Encoding", "chunked") | 139 c.SetHeader("Transfer-Encoding", "chunked") |
133 } else { | 140 } else { |
134 // HTTP version < 1.1: cannot do chunked transfer | 141 // HTTP version < 1.1: cannot do chunked transfer |
135 // encoding, so signal EOF by closing connection. | 142 // encoding, so signal EOF by closing connection. |
136 // Could avoid closing the connection if there is | 143 // Could avoid closing the connection if there is |
(...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
683 } | 690 } |
684 | 691 |
685 conn, err := net.Listen("tcp", addr) | 692 conn, err := net.Listen("tcp", addr) |
686 if err != nil { | 693 if err != nil { |
687 return err | 694 return err |
688 } | 695 } |
689 | 696 |
690 tlsListener := tls.NewListener(conn, config) | 697 tlsListener := tls.NewListener(conn, config) |
691 return Serve(tlsListener, handler) | 698 return Serve(tlsListener, handler) |
692 } | 699 } |
OLD | NEW |