committed by
Andrea Spacca
parent
a640bcf707
commit
8df04e3440
@ -791,9 +791,37 @@ func (s *Server) tarHandler(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Server) headHandler(w http.ResponseWriter, r *http.Request) {
|
||||
vars := mux.Vars(r)
|
||||
|
||||
token := vars["token"]
|
||||
filename := vars["filename"]
|
||||
|
||||
if err := s.CheckMetadata(token, filename); err != nil {
|
||||
log.Printf("Error metadata: %s", err.Error())
|
||||
http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
|
||||
contentType, contentLength, err := s.storage.Head(token, filename)
|
||||
if s.storage.IsNotExist(err) {
|
||||
http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound)
|
||||
return
|
||||
} else if err != nil {
|
||||
log.Printf("%s", err.Error())
|
||||
http.Error(w, "Could not retrieve file.", 500)
|
||||
return
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", contentType)
|
||||
w.Header().Set("Content-Length", strconv.FormatUint(contentLength, 10))
|
||||
w.Header().Set("Connection", "close")
|
||||
}
|
||||
|
||||
func (s *Server) getHandler(w http.ResponseWriter, r *http.Request) {
|
||||
vars := mux.Vars(r)
|
||||
|
||||
action := vars["action"]
|
||||
token := vars["token"]
|
||||
filename := vars["filename"]
|
||||
|
||||
@ -815,10 +843,18 @@ func (s *Server) getHandler(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
defer reader.Close()
|
||||
|
||||
var disposition string
|
||||
|
||||
if action == "inline" {
|
||||
disposition = "inline"
|
||||
} else {
|
||||
disposition = "attachment"
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", contentType)
|
||||
w.Header().Set("Content-Length", strconv.FormatUint(contentLength, 10))
|
||||
w.Header().Set("Content-Disposition", fmt.Sprintf("attachment; filename=\"%s\"", filename))
|
||||
w.Header().Set("Connection", "close")
|
||||
w.Header().Set("Content-Disposition", fmt.Sprintf("%s; filename=\"%s\"", disposition, filename))
|
||||
w.Header().Set("Connection", "keep-alive")
|
||||
|
||||
if _, err = io.Copy(w, reader); err != nil {
|
||||
log.Printf("%s", err.Error())
|
||||
|
@ -324,6 +324,9 @@ func (s *Server) Run() {
|
||||
r.HandleFunc("/({files:.*}).tar", s.tarHandler).Methods("GET")
|
||||
r.HandleFunc("/({files:.*}).tar.gz", s.tarGzHandler).Methods("GET")
|
||||
|
||||
r.HandleFunc("/{token}/{filename}", s.headHandler).Methods("HEAD")
|
||||
r.HandleFunc("/{action:(?:download|get|inline)}/{token}/{filename}", s.headHandler).Methods("HEAD")
|
||||
|
||||
r.HandleFunc("/{token}/{filename}", s.previewHandler).MatcherFunc(func(r *http.Request, rm *mux.RouteMatch) (match bool) {
|
||||
match = false
|
||||
|
||||
@ -352,8 +355,7 @@ func (s *Server) Run() {
|
||||
}
|
||||
|
||||
r.HandleFunc("/{token}/{filename}", getHandlerFn).Methods("GET")
|
||||
r.HandleFunc("/get/{token}/{filename}", getHandlerFn).Methods("GET")
|
||||
r.HandleFunc("/download/{token}/{filename}", getHandlerFn).Methods("GET")
|
||||
r.HandleFunc("/{action:(?:download|get|inline)}/{token}/{filename}", getHandlerFn).Methods("GET")
|
||||
|
||||
r.HandleFunc("/{filename}/virustotal", s.virusTotalHandler).Methods("PUT")
|
||||
r.HandleFunc("/{filename}/scan", s.scanHandler).Methods("PUT")
|
||||
|
Reference in New Issue
Block a user