Left: | ||
Right: |
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 // cgi support | 9 // cgi support |
10 // post support | 10 // post support |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
74 | 74 |
75 // WriteHeader sends an HTTP response header with status code. | 75 // WriteHeader sends an HTTP response header with status code. |
76 // If WriteHeader is not called explicitly, the first call to Write | 76 // If WriteHeader is not called explicitly, the first call to Write |
77 // will trigger an implicit WriteHeader(http.StatusOK). | 77 // will trigger an implicit WriteHeader(http.StatusOK). |
78 // Thus explicit calls to WriteHeader are mainly used to | 78 // Thus explicit calls to WriteHeader are mainly used to |
79 // send error codes. | 79 // send error codes. |
80 WriteHeader(int) | 80 WriteHeader(int) |
81 | 81 |
82 // Flush sends any buffered data to the client. | 82 // Flush sends any buffered data to the client. |
83 Flush() | 83 Flush() |
84 | 84 } |
85 | |
86 // A Hijacker is an HTTP request which be taken over by an HTTP handler. | |
jnw
2011/03/07 17:35:03
A Hijacker is not a request, which already has qui
| |
87 type Hijacker interface { | |
85 // Hijack lets the caller take over the connection. | 88 // Hijack lets the caller take over the connection. |
86 // After a call to Hijack(), the HTTP server library | 89 // After a call to Hijack(), the HTTP server library |
87 // will not do anything else with the connection. | 90 // will not do anything else with the connection. |
88 // It becomes the caller's responsibility to manage | 91 // It becomes the caller's responsibility to manage |
89 // and close the connection. | 92 // and close the connection. |
90 Hijack() (io.ReadWriteCloser, *bufio.ReadWriter, os.Error) | 93 Hijack() (io.ReadWriteCloser, *bufio.ReadWriter, os.Error) |
gburd
2011/03/07 19:02:08
How about returning (conn net.Conn, bufferedData [
bradfitzgoog
2011/03/07 19:06:39
Works for me. Russ?
| |
91 } | 94 } |
92 | 95 |
93 // A conn represents the server side of an HTTP connection. | 96 // A conn represents the server side of an HTTP connection. |
94 type conn struct { | 97 type conn struct { |
95 remoteAddr string // network address of remote side | 98 remoteAddr string // network address of remote side |
96 handler Handler // request handler | 99 handler Handler // request handler |
97 rwc io.ReadWriteCloser // i/o connection | 100 rwc io.ReadWriteCloser // i/o connection |
98 buf *bufio.ReadWriter // buffered rwc | 101 buf *bufio.ReadWriter // buffered rwc |
99 hijacked bool // connection has been hijacked by handler | 102 hijacked bool // connection has been hijacked by handler |
100 usingTLS bool // a flag indicating connection over TLS | 103 usingTLS bool // a flag indicating connection over TLS |
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
462 return | 465 return |
463 } | 466 } |
464 w.finishRequest() | 467 w.finishRequest() |
465 if w.closeAfterReply { | 468 if w.closeAfterReply { |
466 break | 469 break |
467 } | 470 } |
468 } | 471 } |
469 c.close() | 472 c.close() |
470 } | 473 } |
471 | 474 |
472 // Hijack impements the ResponseWriter.Hijack method. | 475 // Hijack impements the ResponseWriter.Hijack method. |
jnw
2011/03/07 17:35:03
Hijack implements the Hijacker.Hijack method
| |
473 func (w *response) Hijack() (rwc io.ReadWriteCloser, buf *bufio.ReadWriter, err os.Error) { | 476 func (w *response) Hijack() (rwc io.ReadWriteCloser, buf *bufio.ReadWriter, err os.Error) { |
474 if w.conn.hijacked { | 477 if w.conn.hijacked { |
475 return nil, nil, ErrHijacked | 478 return nil, nil, ErrHijacked |
476 } | 479 } |
477 w.conn.hijacked = true | 480 w.conn.hijacked = true |
478 rwc = w.conn.rwc | 481 rwc = w.conn.rwc |
479 buf = w.conn.buf | 482 buf = w.conn.buf |
480 w.conn.rwc = nil | 483 w.conn.rwc = nil |
481 w.conn.buf = nil | 484 w.conn.buf = nil |
482 return | 485 return |
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
855 } | 858 } |
856 | 859 |
857 conn, err := net.Listen("tcp", addr) | 860 conn, err := net.Listen("tcp", addr) |
858 if err != nil { | 861 if err != nil { |
859 return err | 862 return err |
860 } | 863 } |
861 | 864 |
862 tlsListener := tls.NewListener(conn, config) | 865 tlsListener := tls.NewListener(conn, config) |
863 return Serve(tlsListener, handler) | 866 return Serve(tlsListener, handler) |
864 } | 867 } |
LEFT | RIGHT |