Commit d2dd60a2 authored by Steven Allen's avatar Steven Allen
Browse files

reset on error in proxy example.

parent 925ac425
Showing with 4 additions and 0 deletions
+4 -0
......@@ -109,6 +109,7 @@ func streamHandler(stream inet.Stream) {
// Read the HTTP request from the buffer
req, err := http.ReadRequest(buf)
if err != nil {
stream.Reset()
log.Println(err)
return
}
......@@ -132,6 +133,7 @@ func streamHandler(stream inet.Stream) {
fmt.Printf("Making request to %s\n", req.URL)
resp, err := http.DefaultTransport.RoundTrip(outreq)
if err != nil {
stream.Reset()
log.Println(err)
return
}
......@@ -176,6 +178,7 @@ func (p *ProxyService) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// r.Write() writes the HTTP request to the stream.
err = r.Write(stream)
if err != nil {
stream.Reset()
log.Println(err)
http.Error(w, err.Error(), http.StatusServiceUnavailable)
return
......@@ -186,6 +189,7 @@ func (p *ProxyService) ServeHTTP(w http.ResponseWriter, r *http.Request) {
buf := bufio.NewReader(stream)
resp, err := http.ReadResponse(buf, r)
if err != nil {
stream.Reset()
log.Println(err)
http.Error(w, err.Error(), http.StatusServiceUnavailable)
return
......
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