aboutsummaryrefslogtreecommitdiff
path: root/lib/http
diff options
context:
space:
mode:
authorShulhan <m.shulhan@gmail.com>2020-06-08 21:11:09 +0700
committerShulhan <m.shulhan@gmail.com>2020-06-08 21:11:09 +0700
commit84d22a42bb35c01431a221cd35641b2cc5115657 (patch)
treeeaddafed4aae66c20cf02ec7afc2397d25a82950 /lib/http
parent4ce1553629b9e944a0bd99b61f2c1ba545bacde0 (diff)
downloadpakakeh.go-84d22a42bb35c01431a221cd35641b2cc5115657.tar.xz
http: check the number of bytes written on ResponseWriter.Write
If number of bytes less than actual data to be written, keep writing the rest by skipping slice.
Diffstat (limited to 'lib/http')
-rw-r--r--lib/http/endpoint.go12
1 files changed, 9 insertions, 3 deletions
diff --git a/lib/http/endpoint.go b/lib/http/endpoint.go
index 36c9ed7e..40312512 100644
--- a/lib/http/endpoint.go
+++ b/lib/http/endpoint.go
@@ -148,9 +148,15 @@ func (ep *Endpoint) call(
res.Header().Set(HeaderContentType, ContentTypePlain)
}
- _, e = res.Write(rspb)
- if e != nil {
- log.Printf("endpoint.call: %s %s %s\n", req.Method, req.URL.Path, e)
+ var nwrite int
+ for nwrite < len(rspb) {
+ n, err := res.Write(rspb[nwrite:])
+ if err != nil {
+ log.Printf("endpoint.call: %s %s %s\n", req.Method,
+ req.URL.Path, e)
+ break
+ }
+ nwrite += n
}
}