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 {
io.WriteString(w, "\r\n")
if req.Body != nil {
buf := make([]byte, chunkSize)
Loop:
for {
var nr, nw int
var er, ew os.Error
if nr, er = req.Body.Read(buf); nr > 0 {
if er == nil || er == os.EOF {
fmt.Fprintf(w, "%x\r\n", nr)
nw, ew = w.Write(buf[0:nr])
fmt.Fprint(w, "\r\n")
}
}
switch {
case er != nil:
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")
cw := NewChunkedWriter(w)
if _, err := io.Copy(cw, req.Body); err != nil {
return err
}
if err := cw.Close(); err != nil {
return err
}
// TODO(petar): Write trailer here and append \r\n. For now, we
// simply send the final \r\n:
if _, err := fmt.Fprint(w, "\r\n"); err != nil {
return err
}
if err := req.Body.Close(); err != nil {
return err
}
}
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