Skip to content

Commit

Permalink
worker: always return object etag (#732)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisSchinnerl authored Nov 13, 2023
1 parent 902fd89 commit 55b441a
Showing 1 changed file with 1 addition and 16 deletions.
17 changes: 1 addition & 16 deletions worker/serve.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package worker

import (
"encoding/hex"
"errors"
"fmt"
"io"
"net/http"

"github.com/gotd/contrib/http_range"
"go.sia.tech/core/types"
"go.sia.tech/renterd/api"
)

Expand Down Expand Up @@ -91,7 +89,7 @@ func serveContent(rw http.ResponseWriter, req *http.Request, obj api.Object, dow

// set the response headers, no need to set Last-Modified header as
// serveContent does that for us
rw.Header().Set("ETag", api.FormatETag(buildETag(req, obj.ETag)))
rw.Header().Set("ETag", api.FormatETag(obj.ETag))
rw.Header().Set("Content-Type", contentType)

http.ServeContent(rw, req, obj.Name, obj.ModTime, rs)
Expand All @@ -118,16 +116,3 @@ func parseRangeHeader(req *http.Request, obj api.Object) (int64, int64, error) {
}
return offset, length, nil
}

func buildETag(req *http.Request, objETag string) string {
rh := req.Header.Get("Range")
if rh == "" {
return objETag
}

h := types.NewHasher()
h.E.Write([]byte(rh))
h.E.Write([]byte(objETag))
sum := h.Sum()
return hex.EncodeToString(sum[:])
}

0 comments on commit 55b441a

Please sign in to comment.