Commit c5287ecb authored by Petar Maymounkov's avatar Petar Maymounkov Committed by Russ Cox

http: protect io.WriteString in Request/Response.Write with error checking,

since they were causing a silent program exit (too many EPIPE's).

R=rsc
CC=golang-dev
https://golang.org/cl/204062
parent d4ad8e8c
...@@ -171,7 +171,10 @@ func (req *Request) Write(w io.Writer) os.Error { ...@@ -171,7 +171,10 @@ func (req *Request) Write(w io.Writer) os.Error {
// from Request, and introduce Request methods along the lines of // from Request, and introduce Request methods along the lines of
// Response.{GetHeader,AddHeader} and string constants for "Host", // Response.{GetHeader,AddHeader} and string constants for "Host",
// "User-Agent" and "Referer". // "User-Agent" and "Referer".
writeSortedKeyValue(w, req.Header, reqExcludeHeader) err := writeSortedKeyValue(w, req.Header, reqExcludeHeader)
if err != nil {
return err
}
io.WriteString(w, "\r\n") io.WriteString(w, "\r\n")
......
...@@ -459,7 +459,10 @@ func (resp *Response) Write(w io.Writer) os.Error { ...@@ -459,7 +459,10 @@ func (resp *Response) Write(w io.Writer) os.Error {
} }
// Rest of header // Rest of header
writeSortedKeyValue(w, resp.Header, respExcludeHeader) err := writeSortedKeyValue(w, resp.Header, respExcludeHeader)
if err != nil {
return err
}
// End-of-header // End-of-header
io.WriteString(w, "\r\n") io.WriteString(w, "\r\n")
...@@ -494,7 +497,7 @@ func (resp *Response) Write(w io.Writer) os.Error { ...@@ -494,7 +497,7 @@ func (resp *Response) Write(w io.Writer) os.Error {
return nil return nil
} }
func writeSortedKeyValue(w io.Writer, kvm map[string]string, exclude map[string]int) { func writeSortedKeyValue(w io.Writer, kvm map[string]string, exclude map[string]int) os.Error {
kva := make([]string, len(kvm)) kva := make([]string, len(kvm))
i := 0 i := 0
for k, v := range kvm { for k, v := range kvm {
...@@ -506,6 +509,9 @@ func writeSortedKeyValue(w io.Writer, kvm map[string]string, exclude map[string] ...@@ -506,6 +509,9 @@ func writeSortedKeyValue(w io.Writer, kvm map[string]string, exclude map[string]
kva = kva[0:i] kva = kva[0:i]
sort.SortStrings(kva) sort.SortStrings(kva)
for _, l := range kva { for _, l := range kva {
io.WriteString(w, l) if _, err := io.WriteString(w, l); 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