mirror of
https://github.com/golang/go
synced 2024-11-21 20:14:52 -07:00
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
This commit is contained in:
parent
d4ad8e8ce3
commit
c5287ecb9c
@ -171,7 +171,10 @@ func (req *Request) Write(w io.Writer) os.Error {
|
||||
// from Request, and introduce Request methods along the lines of
|
||||
// Response.{GetHeader,AddHeader} and string constants for "Host",
|
||||
// "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")
|
||||
|
||||
|
@ -459,7 +459,10 @@ func (resp *Response) Write(w io.Writer) os.Error {
|
||||
}
|
||||
|
||||
// Rest of header
|
||||
writeSortedKeyValue(w, resp.Header, respExcludeHeader)
|
||||
err := writeSortedKeyValue(w, resp.Header, respExcludeHeader)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// End-of-header
|
||||
io.WriteString(w, "\r\n")
|
||||
@ -494,7 +497,7 @@ func (resp *Response) Write(w io.Writer) os.Error {
|
||||
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))
|
||||
i := 0
|
||||
for k, v := range kvm {
|
||||
@ -506,6 +509,9 @@ func writeSortedKeyValue(w io.Writer, kvm map[string]string, exclude map[string]
|
||||
kva = kva[0:i]
|
||||
sort.SortStrings(kva)
|
||||
for _, l := range kva {
|
||||
io.WriteString(w, l)
|
||||
if _, err := io.WriteString(w, l); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user