Skip to content

Commit 607ac8a

Browse files
committed
Add Etag and X-Repo-Commit headers in redirect for huggingface.co requests
1 parent aeccd3b commit 607ac8a

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

mirror.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,25 @@ func (m *MirrorHandler) redirect(rw http.ResponseWriter, r *http.Request, file s
220220
expires := m.LinkExpires
221221
var url string
222222
var err error
223+
224+
if sys := info.Sys(); sys != nil {
225+
if resp, ok := sys.(sss.FileInfoExpansion); ok {
226+
if etag := resp.ETag; etag != nil && *etag != "" {
227+
rw.Header().Set("Etag", *etag)
228+
}
229+
}
230+
}
231+
232+
// Special handling for huggingface.co to add X-Repo-Commit header with HF_ENDPOINT
233+
if r.Host == "huggingface.co" {
234+
sl := strings.SplitN(r.URL.Path, "/", 6)
235+
if len(sl) == 6 &&
236+
sl[3] == "resolve" &&
237+
len(sl[4]) == 40 {
238+
rw.Header().Set("X-Repo-Commit", sl[4])
239+
}
240+
}
241+
223242
if r.Method == http.MethodHead {
224243
if info == nil {
225244
info, err = m.RemoteCache.Stat(r.Context(), file)

0 commit comments

Comments
 (0)