Skip to content

Commit 90fde85

Browse files
committed
feat(content): set error only if needed for HEAD req
1 parent 91c11db commit 90fde85

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/serverHandler/content.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,18 @@ func (h *aliasHandler) content(w http.ResponseWriter, r *http.Request, data *res
3737
return
3838
}
3939

40-
ctype, err := util.GetContentType(item.Name(), file)
41-
if err == nil {
42-
header.Set("Accept-Ranges", "bytes")
43-
if len(header.Values("Content-Type")) == 0 {
40+
header.Set("Accept-Ranges", "bytes")
41+
if len(header.Values("Content-Type")) == 0 {
42+
ctype, err := util.GetContentType(item.Name(), file)
43+
if err == nil {
4444
header.Set("Content-Type", ctype)
45+
} else if data.Status == http.StatusOK {
46+
data.Status = http.StatusInternalServerError
4547
}
46-
header.Set("Content-Length", strconv.FormatInt(item.Size(), 10))
47-
header.Set("Date", time.Now().UTC().Format(http.TimeFormat))
48-
header.Set("Last-Modified", item.ModTime().UTC().Format(http.TimeFormat))
49-
} else if data.Status == http.StatusOK {
50-
data.Status = http.StatusInternalServerError
5148
}
49+
header.Set("Content-Length", strconv.FormatInt(item.Size(), 10))
50+
header.Set("Date", time.Now().UTC().Format(http.TimeFormat))
51+
header.Set("Last-Modified", item.ModTime().UTC().Format(http.TimeFormat))
5252

5353
w.WriteHeader(data.Status)
5454
}

0 commit comments

Comments
 (0)