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

Unified Diff: src/pkg/http/request.go

Issue 196079: code review 196079: Replace the manual body chunk writer code in Request, with (Closed)
Patch Set: code review 196079: Replace the manual body chunk writer code in Request, with Created 15 years, 1 month ago
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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/pkg/http/request.go
===================================================================
--- a/src/pkg/http/request.go
+++ b/src/pkg/http/request.go
@@ -128,7 +128,7 @@
// Write writes an HTTP/1.1 request -- header and body -- in wire format.
// This method consults the following fields of req:
-// Host
+// Host
// URL
// Method (defaults to "GET")
// UserAgent (defaults to defaultUserAgent)
@@ -181,33 +181,21 @@
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
- }
+ cw := NewChunkedWriter(w)
+ if _, err := io.Copy(cw, req.Body); err != nil {
+ return err
}
- req.Body.Close()
- // last-chunk CRLF
- fmt.Fprint(w, "0\r\n\r\n")
+ 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »

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