Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(6)

Side by Side Diff: src/pkg/http/server.go

Issue 2051041: code review 2051041: http: add Date to server, Last-Modified and If-Modified... (Closed)
Patch Set: code review 2051041: http: add Date to server, Last-Modified and If-Modified... Created 14 years, 6 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/pkg/http/fs.go ('k') | src/pkg/http/triv.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 }
OLDNEW
« no previous file with comments | « src/pkg/http/fs.go ('k') | src/pkg/http/triv.go » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b