From 7c9e592c2d313b1d1c0eddae4c512505bcfa1e82 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Tue, 17 Nov 2020 11:23:13 -0800 Subject: [PATCH] s3: avoid nil resp when having error fix https://github.com/chrislusf/seaweedfs/issues/1622 --- weed/s3api/s3api_object_handlers.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/weed/s3api/s3api_object_handlers.go b/weed/s3api/s3api_object_handlers.go index 7ea49f2c6..fa2436f62 100644 --- a/weed/s3api/s3api_object_handlers.go +++ b/weed/s3api/s3api_object_handlers.go @@ -266,11 +266,6 @@ func (s3a *S3ApiServer) proxyToFiler(w http.ResponseWriter, r *http.Request, des resp, postErr := client.Do(proxyReq) - if (resp.ContentLength == -1 || resp.StatusCode == 404) && !strings.HasSuffix(destUrl, "/") { - writeErrorResponse(w, s3err.ErrNoSuchKey, r.URL) - return - } - if postErr != nil { glog.Errorf("post to filer: %v", postErr) writeErrorResponse(w, s3err.ErrInternalError, r.URL) @@ -278,6 +273,11 @@ func (s3a *S3ApiServer) proxyToFiler(w http.ResponseWriter, r *http.Request, des } defer util.CloseResponse(resp) + if (resp.ContentLength == -1 || resp.StatusCode == 404) && !strings.HasSuffix(destUrl, "/") { + writeErrorResponse(w, s3err.ErrNoSuchKey, r.URL) + return + } + responseFn(resp, w) }