Skip to content
Permalink
Browse files

Fix headers for "force download" mode

Adds the Content-Disposition: attachment keyword for forced downloads
and also fixes a bug where the headers returned by HEAD would miss the
Content-Type header from GET in encrypted mode.
  • Loading branch information
tribut committed Feb 16, 2018
1 parent 6547519 commit e798337db4657efe920c5b93f959459ec92a422b
Showing with 15 additions and 4 deletions.
  1. +9 −2 server/views/resources.go
  2. +6 −2 server/views/unencrypted.go
@@ -121,8 +121,10 @@ func ViewC(c *gin.Context) {
reader := &cipher.StreamReader{S: stream, R: f}
if conf.C.AlwaysDownload {
c.Header("Content-Type", "application/octet-stream")
c.Header("Content-Disposition", "attachment; filename=\""+re.Name+"\"")
} else {
c.Header("Content-Disposition", "filename=\""+re.Name+"\"")
}
c.Header("Content-Disposition", "filename=\""+re.Name+"\"")
io.Copy(c.Writer, reader)
if re.Once {
re.Delete()
@@ -215,6 +217,11 @@ func HeadC(c *gin.Context) {
var iv [aes.BlockSize]byte
stream := cipher.NewCFBDecrypter(block, iv[:])
reader := &cipher.StreamReader{S: stream, R: f}
c.Header("Content-Disposition", "filename=\""+re.Name+"\"")
if conf.C.AlwaysDownload {
c.Header("Content-Type", "application/octet-stream")
c.Header("Content-Disposition", "attachment; filename=\""+re.Name+"\"")
} else {
c.Header("Content-Disposition", "filename=\""+re.Name+"\"")
}
io.Copy(c.Writer, reader)
}
@@ -116,8 +116,10 @@ func View(c *gin.Context) {
}
if conf.C.AlwaysDownload {
c.Header("Content-Type", "application/octet-stream")
c.Header("Content-Disposition", "attachment; filename=\""+re.Name+"\"")
} else {
c.Header("Content-Disposition", "filename=\""+re.Name+"\"")
}
c.Header("Content-Disposition", "filename=\""+re.Name+"\"")
io.Copy(c.Writer, f)
if re.Once {
re.Delete()
@@ -146,8 +148,10 @@ func Head(c *gin.Context) {
}
if conf.C.AlwaysDownload {
c.Header("Content-Type", "application/octet-stream")
c.Header("Content-Disposition", "attachment; filename=\""+re.Name+"\"")
} else {
c.Header("Content-Disposition", "filename=\""+re.Name+"\"")
}
c.Header("Content-Disposition", "filename=\""+re.Name+"\"")
io.Copy(c.Writer, f)
}

0 comments on commit e798337

Please sign in to comment.
You can’t perform that action at this time.