Skip to content

Commit

Permalink
call WriteHeader after last change to header map (#542)
Browse files Browse the repository at this point in the history
* call WriteHeader after last change to header map

* fix reader/decryptionReader
  • Loading branch information
aspacca authored Apr 5, 2023
1 parent 3dcbfe2 commit a5dacb3
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions server/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -1232,16 +1232,8 @@ func (s *Server) getHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("X-Remaining-Downloads", remainingDownloads)
w.Header().Set("X-Remaining-Days", remainingDays)

if rng != nil && rng.ContentRange() != "" {
w.WriteHeader(http.StatusPartialContent)
}

if disposition == "inline" && canContainsXSS(contentType) {
reader = io.NopCloser(bluemonday.UGCPolicy().SanitizeReader(reader))
}

password := r.Header.Get("X-Decrypt-Password")
decryptionReader, err := attachDecryptionReader(reader, password)
reader, err = attachDecryptionReader(reader, password)
if err != nil {
http.Error(w, "Could not decrypt file", http.StatusInternalServerError)
return
Expand All @@ -1256,7 +1248,15 @@ func (s *Server) getHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Length", strconv.FormatUint(contentLength, 10))
w.Header().Set("Vary", "Range, Referer, X-Decrypt-Password")

if _, err = io.Copy(w, decryptionReader); err != nil {
if rng != nil && rng.ContentRange() != "" {
w.WriteHeader(http.StatusPartialContent)
}

if disposition == "inline" && canContainsXSS(contentType) {
reader = io.NopCloser(bluemonday.UGCPolicy().SanitizeReader(reader))
}

if _, err = io.Copy(w, reader); err != nil {
s.logger.Printf("%s", err.Error())
http.Error(w, "Error occurred copying to output stream", http.StatusInternalServerError)
return
Expand Down

0 comments on commit a5dacb3

Please sign in to comment.