Commit 15da069a authored by Petar Maymounkov's avatar Petar Maymounkov Committed by Russ Cox

http: use ChunkWriter in Request.Write

R=rsc
CC=golang-dev
https://golang.org/cl/196079
parent 43d2e59a
...@@ -181,33 +181,21 @@ func (req *Request) Write(w io.Writer) os.Error { ...@@ -181,33 +181,21 @@ func (req *Request) Write(w io.Writer) os.Error {
io.WriteString(w, "\r\n") io.WriteString(w, "\r\n")
if req.Body != nil { if req.Body != nil {
buf := make([]byte, chunkSize) cw := NewChunkedWriter(w)
Loop: if _, err := io.Copy(cw, req.Body); err != nil {
for { return err
var nr, nw int }
var er, ew os.Error if err := cw.Close(); err != nil {
if nr, er = req.Body.Read(buf); nr > 0 { return err
if er == nil || er == os.EOF { }
fmt.Fprintf(w, "%x\r\n", nr) // TODO(petar): Write trailer here and append \r\n. For now, we
nw, ew = w.Write(buf[0:nr]) // simply send the final \r\n:
fmt.Fprint(w, "\r\n") if _, err := fmt.Fprint(w, "\r\n"); err != nil {
} return err
} }
switch { if err := req.Body.Close(); err != nil {
case er != nil: return err
if er == os.EOF { }
break Loop
}
return er
case ew != nil:
return ew
case nw < nr:
return io.ErrShortWrite
}
}
req.Body.Close()
// last-chunk CRLF
fmt.Fprint(w, "0\r\n\r\n")
} }
return nil return nil
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment