Skip to content

Commit

Permalink
Add Vary headers in responses (dutchcoders#536)
Browse files Browse the repository at this point in the history
* Add `Vary` headers in responses

* Add `Referer` to file handler `Vary`

* Fix Vary value for routes
  • Loading branch information
kotx authored Mar 16, 2023
1 parent 1fb67f4 commit 3dcbfe2
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions server/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,8 @@ func canContainsXSS(contentType string) bool {

/* The preview handler will show a preview of the content for browsers (accept type text/html), and referer is not transfer.sh */
func (s *Server) previewHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Vary", "Range, Referer, X-Decrypt-Password")

vars := mux.Vars(r)

token := vars["token"]
Expand Down Expand Up @@ -397,6 +399,7 @@ func (s *Server) viewHandler(w http.ResponseWriter, r *http.Request) {
token(s.randomTokenLength),
}

w.Header().Set("Vary", "Accept")
if acceptsHTML(r.Header) {
if err := htmlTemplates.ExecuteTemplate(w, "index.html", data); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
Expand Down Expand Up @@ -1157,6 +1160,7 @@ func (s *Server) headHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Connection", "close")
w.Header().Set("X-Remaining-Downloads", remainingDownloads)
w.Header().Set("X-Remaining-Days", remainingDays)
w.Header().Set("Vary", "Range, Referer, X-Decrypt-Password")

if s.storage.IsRangeSupported() {
w.Header().Set("Accept-Ranges", "bytes")
Expand Down Expand Up @@ -1250,6 +1254,7 @@ func (s *Server) getHandler(w http.ResponseWriter, r *http.Request) {

w.Header().Set("Content-Type", contentType)
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 {
s.logger.Printf("%s", err.Error())
Expand Down

0 comments on commit 3dcbfe2

Please sign in to comment.