blob: 15c0707f3e027c92b7237f7098d7075ad0bebc5e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package http
import (
"io";
"bufio";
"http";
"os"
)
// Active HTTP connection (server side).
export type Conn struct {
rwc io.ReadWriteClose;
br *bufio.BufRead;
bw *bufio.BufWrite;
close bool;
chunking bool;
}
// Create new connection from rwc.
export func NewConn(rwc io.ReadWriteClose) (c *Conn, err *os.Error) {
c = new(Conn);
c.rwc = rwc;
if c.br, err = bufio.NewBufRead(rwc); err != nil {
return nil, err
}
if c.bw, err = bufio.NewBufWrite(rwc); err != nil {
return nil, err
}
return c, nil
}
// Read next request from connection.
func (c *Conn) ReadRequest() (req *Request, err *os.Error) {
if req, err = ReadRequest(c.br); err != nil {
return nil, err
}
// TODO: Proper handling of (lack of) Connection: close,
// and chunked transfer encoding on output.
c.close = true;
return req, nil
}
// Close the connection.
func (c *Conn) Close() {
c.bw.Flush();
c.rwc.Close();
}
|