"fmt"
"io"
"net/http"
+ "net/url"
"strings"
"sync"
"time"
// Handle implements RouteAction
func (a *S3Action) Handle(w http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
+ if r.Method != "HEAD" && r.Method != "GET" {
+ http.Error(w, fmt.Sprintf("Method not allowed: %s", r.Method), http.StatusMethodNotAllowed)
+ return
+ }
+
mc, err := a.minioClient()
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
}
reqPath := strings.TrimPrefix(r.URL.Path, a.StripPrefix)
- objPath := "/" + strings.Trim(strings.Join(
+ reqPath, err = url.PathUnescape(reqPath)
+ if err != nil {
+ w.WriteHeader(http.StatusBadRequest)
+ w.Write([]byte(fmt.Sprintf("failed decoding path: %+v", err)))
+ return
+ }
+ objPath := strings.Trim(strings.Join(
[]string{
strings.Trim(a.ObjectPrefix, "/"),
strings.Trim(reqPath, "/"),
}
w.Header().Set("last-modified", stat.LastModified.Format(http.TimeFormat))
- if stat.ChecksumSHA1 != "" {
+ if stat.ETag != "" {
if inm := r.Header.Get("if-none-match"); inm != "" {
- if inm == stat.ChecksumSHA1 {
+ if inm == stat.ETag {
w.WriteHeader(http.StatusNotModified)
return
}
}
- w.Header().Set("ETag", stat.ChecksumSHA1)
+ w.Header().Set("ETag", stat.ETag)
}
var seek int64
w.Header().Set("content-type", stat.ContentType)
w.WriteHeader(rc)
+ if r.Method == "HEAD" {
+ return
+ }
+
io.CopyN(w, object, size)
}