55 "fmt"
66 "io"
77 "net/http"
8- "net/url"
98 "os"
109 "strconv"
1110 "strings"
@@ -15,18 +14,6 @@ import (
1514 log "github.com/sjqzhang/seelog"
1615)
1716
18- func (c * Server ) SetDownloadHeader (w http.ResponseWriter , r * http.Request ) {
19- w .Header ().Set ("Content-Type" , "application/octet-stream" )
20- if name , ok := r .URL .Query ()["name" ]; ok {
21- if v , err := url .QueryUnescape (name [0 ]); err == nil {
22- name [0 ] = c .TrimFileNameSpecialChar (v )
23- }
24- w .Header ().Set ("Content-Disposition" , fmt .Sprintf ("attachment;filename=%s" , name [0 ]))
25- } else {
26- w .Header ().Set ("Content-Disposition" , "attachment" )
27- }
28- }
29-
3017func (c * Server ) ConsumerDownLoad () {
3118 ConsumerFunc := func () {
3219 for {
@@ -324,7 +311,7 @@ func (c *Server) DownloadSmallFileByURI(w http.ResponseWriter, r *http.Request)
324311 _ = notFound
325312 if data != nil && string (data [0 ]) == "1" {
326313 if isDownload {
327- c .SetDownloadHeader (w , r )
314+ c .SetDownloadHeader (w , r , true )
328315 }
329316 if imgWidth != 0 || imgHeight != 0 {
330317 c .ResizeImageByBytes (w , data [1 :], uint (imgWidth ), uint (imgHeight ))
@@ -374,7 +361,7 @@ func (c *Server) DownloadNormalFileByURI(w http.ResponseWriter, r *http.Request)
374361 }
375362 }
376363 if isDownload {
377- c .SetDownloadHeader (w , r )
364+ c .SetDownloadHeader (w , r , false )
378365 }
379366 fullpath , _ := c .GetFilePathFromRequest (w , r )
380367 if imgWidth != 0 || imgHeight != 0 {
@@ -417,7 +404,7 @@ func (c *Server) DownloadNotFound(w http.ResponseWriter, r *http.Request) {
417404 go c .DownloadFromPeer (peer , fileInfo )
418405 //http.Redirect(w, r, peer+r.RequestURI, 302)
419406 if isDownload {
420- c .SetDownloadHeader (w , r )
407+ c .SetDownloadHeader (w , r , false )
421408 }
422409 c .DownloadFileToResponse (peer + r .RequestURI , w , r )
423410 return
0 commit comments