From 96ed5c7bdd89fb47cfb2f6be0c8a0e4797e65303 Mon Sep 17 00:00:00 2001 From: nanmu42 Date: Sun, 29 Nov 2020 15:44:46 +0800 Subject: [PATCH] refactor: simplify writerWrapper.enoughContentLength() --- writerwrapper.go | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/writerwrapper.go b/writerwrapper.go index 9559d3c..f8c938c 100644 --- a/writerwrapper.go +++ b/writerwrapper.go @@ -178,15 +178,10 @@ func (w *writerWrapper) writeBuffer(data []byte) (fit bool) { } func (w *writerWrapper) enoughContentLength() bool { - var ( - header = w.Header() - _, haveCl = header["Content-Length"] - contentLength int64 - ) - if haveCl { - contentLength, _ = strconv.ParseInt(header.Get("Content-Length"), 10, 64) + contentLength, err := strconv.ParseInt(w.Header().Get("Content-Length"), 10, 64) + if err != nil { + return false } - if contentLength != 0 && contentLength >= w.MinContentLength { return true }