diff options
| author | Chris Lu <chris.lu@gmail.com> | 2018-07-21 19:12:44 -0700 |
|---|---|---|
| committer | Chris Lu <chris.lu@gmail.com> | 2018-07-21 19:12:44 -0700 |
| commit | 49375d603177e4134d0cb4128324a2dd70521290 (patch) | |
| tree | cc72caa73fadbdb81659c1f13bb87f33c502fbc1 | |
| parent | 5068b6ae7d52f00d9846207ea57e76e345ea36d5 (diff) | |
| download | seaweedfs-49375d603177e4134d0cb4128324a2dd70521290.tar.xz seaweedfs-49375d603177e4134d0cb4128324a2dd70521290.zip | |
adjust DELETE response to S3 format
| -rw-r--r-- | weed/s3api/s3api_object_handlers.go | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/weed/s3api/s3api_object_handlers.go b/weed/s3api/s3api_object_handlers.go index 41820667c..6c1895cbc 100644 --- a/weed/s3api/s3api_object_handlers.go +++ b/weed/s3api/s3api_object_handlers.go @@ -95,7 +95,7 @@ func (s3a *S3ApiServer) GetObjectHandler(w http.ResponseWriter, r *http.Request) destUrl := fmt.Sprintf("http://%s%s%s", s3a.option.Filer, s3a.option.BucketsPath, r.RequestURI) - s3a.proxyToFiler(w, r, destUrl) + s3a.proxyToFiler(w, r, destUrl, passThroghResponse) } @@ -104,7 +104,7 @@ func (s3a *S3ApiServer) HeadObjectHandler(w http.ResponseWriter, r *http.Request destUrl := fmt.Sprintf("http://%s%s%s", s3a.option.Filer, s3a.option.BucketsPath, r.RequestURI) - s3a.proxyToFiler(w, r, destUrl) + s3a.proxyToFiler(w, r, destUrl, passThroghResponse) } @@ -113,11 +113,16 @@ func (s3a *S3ApiServer) DeleteObjectHandler(w http.ResponseWriter, r *http.Reque destUrl := fmt.Sprintf("http://%s%s%s", s3a.option.Filer, s3a.option.BucketsPath, r.RequestURI) - s3a.proxyToFiler(w, r, destUrl) + s3a.proxyToFiler(w, r, destUrl, func(proxyResonse *http.Response, w http.ResponseWriter) { + for k, v := range proxyResonse.Header { + w.Header()[k] = v + } + w.WriteHeader(http.StatusNoContent) + }) } -func (s3a *S3ApiServer) proxyToFiler(w http.ResponseWriter, r *http.Request, destUrl string) { +func (s3a *S3ApiServer) proxyToFiler(w http.ResponseWriter, r *http.Request, destUrl string, responseFn func(proxyResonse *http.Response, w http.ResponseWriter)) { glog.V(2).Infof("s3 proxying %s to %s", r.Method, destUrl) @@ -147,9 +152,12 @@ func (s3a *S3ApiServer) proxyToFiler(w http.ResponseWriter, r *http.Request, des } defer resp.Body.Close() - for k, v := range resp.Header { + responseFn(resp, w) +} +func passThroghResponse(proxyResonse *http.Response, w http.ResponseWriter) { + for k, v := range proxyResonse.Header { w.Header()[k] = v } - w.WriteHeader(resp.StatusCode) - io.Copy(w, resp.Body) + w.WriteHeader(proxyResonse.StatusCode) + io.Copy(w, proxyResonse.Body) } |
