server: adding no-store header (#476)
In order to prevent viewing content, which max-download rate has been reached, we need to ensure the data is not stored locally in a browser cache. To achieve this, we set the Cache-Control Setting to "no-store" according to: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control fixes #470
This commit is contained in:
@ -781,8 +781,7 @@ func (s *Server) zipHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
zipfilename := fmt.Sprintf("transfersh-%d.zip", uint16(time.Now().UnixNano()))
|
zipfilename := fmt.Sprintf("transfersh-%d.zip", uint16(time.Now().UnixNano()))
|
||||||
|
|
||||||
w.Header().Set("Content-Type", "application/zip")
|
w.Header().Set("Content-Type", "application/zip")
|
||||||
w.Header().Set("Content-Disposition", fmt.Sprintf("attachment; filename=\"%s\"", zipfilename))
|
commonHeader(w, zipfilename)
|
||||||
w.Header().Set("Connection", "close")
|
|
||||||
|
|
||||||
zw := zip.NewWriter(w)
|
zw := zip.NewWriter(w)
|
||||||
|
|
||||||
@ -848,8 +847,7 @@ func (s *Server) tarGzHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
tarfilename := fmt.Sprintf("transfersh-%d.tar.gz", uint16(time.Now().UnixNano()))
|
tarfilename := fmt.Sprintf("transfersh-%d.tar.gz", uint16(time.Now().UnixNano()))
|
||||||
|
|
||||||
w.Header().Set("Content-Type", "application/x-gzip")
|
w.Header().Set("Content-Type", "application/x-gzip")
|
||||||
w.Header().Set("Content-Disposition", fmt.Sprintf("attachment; filename=\"%s\"", tarfilename))
|
commonHeader(w, tarfilename)
|
||||||
w.Header().Set("Connection", "close")
|
|
||||||
|
|
||||||
gw := gzip.NewWriter(w)
|
gw := gzip.NewWriter(w)
|
||||||
defer CloseCheck(gw.Close)
|
defer CloseCheck(gw.Close)
|
||||||
@ -910,8 +908,7 @@ func (s *Server) tarHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
tarfilename := fmt.Sprintf("transfersh-%d.tar", uint16(time.Now().UnixNano()))
|
tarfilename := fmt.Sprintf("transfersh-%d.tar", uint16(time.Now().UnixNano()))
|
||||||
|
|
||||||
w.Header().Set("Content-Type", "application/x-tar")
|
w.Header().Set("Content-Type", "application/x-tar")
|
||||||
w.Header().Set("Content-Disposition", fmt.Sprintf("attachment; filename=\"%s\"", tarfilename))
|
commonHeader(w, tarfilename)
|
||||||
w.Header().Set("Connection", "close")
|
|
||||||
|
|
||||||
zw := tar.NewWriter(w)
|
zw := tar.NewWriter(w)
|
||||||
defer CloseCheck(zw.Close)
|
defer CloseCheck(zw.Close)
|
||||||
@ -1037,6 +1034,7 @@ func (s *Server) getHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
w.Header().Set("Content-Length", strconv.FormatUint(contentLength, 10))
|
w.Header().Set("Content-Length", strconv.FormatUint(contentLength, 10))
|
||||||
w.Header().Set("Content-Disposition", fmt.Sprintf("%s; filename=\"%s\"", disposition, filename))
|
w.Header().Set("Content-Disposition", fmt.Sprintf("%s; filename=\"%s\"", disposition, filename))
|
||||||
w.Header().Set("Connection", "keep-alive")
|
w.Header().Set("Connection", "keep-alive")
|
||||||
|
w.Header().Set("Cache-Control", "no-store")
|
||||||
w.Header().Set("X-Remaining-Downloads", remainingDownloads)
|
w.Header().Set("X-Remaining-Downloads", remainingDownloads)
|
||||||
w.Header().Set("X-Remaining-Days", remainingDays)
|
w.Header().Set("X-Remaining-Days", remainingDays)
|
||||||
|
|
||||||
@ -1072,6 +1070,12 @@ func (s *Server) getHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func commonHeader(w http.ResponseWriter, filename string) {
|
||||||
|
w.Header().Set("Content-Disposition", fmt.Sprintf("attachment; filename=\"%s\"", filename))
|
||||||
|
w.Header().Set("Connection", "close")
|
||||||
|
w.Header().Set("Cache-Control", "no-store")
|
||||||
|
}
|
||||||
|
|
||||||
// RedirectHandler handles redirect
|
// RedirectHandler handles redirect
|
||||||
func (s *Server) RedirectHandler(h http.Handler) http.HandlerFunc {
|
func (s *Server) RedirectHandler(h http.Handler) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
@ -25,39 +25,34 @@ THE SOFTWARE.
|
|||||||
package server
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
crypto_rand "crypto/rand"
|
crypto_rand "crypto/rand"
|
||||||
|
"crypto/tls"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"errors"
|
"errors"
|
||||||
gorillaHandlers "github.com/gorilla/handlers"
|
|
||||||
"log"
|
"log"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"mime"
|
"mime"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
_ "net/http/pprof"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
context "golang.org/x/net/context"
|
|
||||||
|
|
||||||
"github.com/PuerkitoBio/ghost/handlers"
|
"github.com/PuerkitoBio/ghost/handlers"
|
||||||
"github.com/VojtechVitek/ratelimit"
|
"github.com/VojtechVitek/ratelimit"
|
||||||
"github.com/VojtechVitek/ratelimit/memory"
|
"github.com/VojtechVitek/ratelimit/memory"
|
||||||
|
gorillaHandlers "github.com/gorilla/handlers"
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
|
"golang.org/x/crypto/acme/autocert"
|
||||||
// import pprof
|
|
||||||
_ "net/http/pprof"
|
|
||||||
|
|
||||||
"crypto/tls"
|
|
||||||
|
|
||||||
web "github.com/dutchcoders/transfer.sh-web"
|
web "github.com/dutchcoders/transfer.sh-web"
|
||||||
assetfs "github.com/elazarl/go-bindata-assetfs"
|
assetfs "github.com/elazarl/go-bindata-assetfs"
|
||||||
|
|
||||||
autocert "golang.org/x/crypto/acme/autocert"
|
|
||||||
"path/filepath"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// parse request with maximum memory of _24Kilobits
|
// parse request with maximum memory of _24Kilobits
|
||||||
|
Reference in New Issue
Block a user