diff options
| author | Shulhan <m.shulhan@gmail.com> | 2020-06-08 21:11:09 +0700 |
|---|---|---|
| committer | Shulhan <m.shulhan@gmail.com> | 2020-06-08 21:11:09 +0700 |
| commit | 84d22a42bb35c01431a221cd35641b2cc5115657 (patch) | |
| tree | eaddafed4aae66c20cf02ec7afc2397d25a82950 /lib/http | |
| parent | 4ce1553629b9e944a0bd99b61f2c1ba545bacde0 (diff) | |
| download | pakakeh.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.go | 12 |
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 } } |
