fix(server/files): fix Content-Disposition is not set (#46)
* fix(server/files): fix Content-Disposition is not set * test(header): check content disposition header
This commit is contained in:
parent
a9ccb4506c
commit
8b5a80f766
6 changed files with 23 additions and 7 deletions
|
@ -396,9 +396,13 @@ func (h *FileHandlers) Download(c *gin.Context) {
|
|||
}
|
||||
// reader will be closed by multipart response writer
|
||||
|
||||
extraHeaders := map[string]string{
|
||||
"Content-Disposition": fmt.Sprintf(`attachment; filename="%s"`, info.Name()),
|
||||
}
|
||||
|
||||
// respond to normal requests
|
||||
if ifRangeVal != "" || rangeVal == "" {
|
||||
c.DataFromReader(200, info.Size(), contentType, r, map[string]string{})
|
||||
c.DataFromReader(200, info.Size(), contentType, r, extraHeaders)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -417,9 +421,6 @@ func (h *FileHandlers) Download(c *gin.Context) {
|
|||
|
||||
go mw.Write()
|
||||
|
||||
extraHeaders := map[string]string{
|
||||
"Content-Disposition": fmt.Sprintf(`attachment; filename="%s"`, info.Name()),
|
||||
}
|
||||
// it takes the \r\n before body into account, so contentLength+2
|
||||
c.DataFromReader(206, contentLength+2, contentType, mw, extraHeaders)
|
||||
}
|
||||
|
|
|
@ -135,7 +135,7 @@ func initHandlers(router *gin.Engine, cfg gocfg.ICfg, deps *depidx.Deps) (*gin.E
|
|||
return nil, err
|
||||
}
|
||||
|
||||
deps.Log().Info("user (%s) is created\n", adminName)
|
||||
deps.Log().Infof("user (%s) is created\n", adminName)
|
||||
}
|
||||
|
||||
fileHdrs, err := fileshdr.NewFileHandlers(cfg, deps)
|
||||
|
|
|
@ -98,13 +98,21 @@ func TestFileHandlers(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
fileName := path.Base(filePath)
|
||||
contentDispositionHeader := res.Header.Get("Content-Disposition")
|
||||
if len(errs) > 0 {
|
||||
t.Error(errs)
|
||||
return false
|
||||
} else if res.StatusCode != 200 && res.StatusCode != 206 {
|
||||
}
|
||||
if res.StatusCode != 200 && res.StatusCode != 206 {
|
||||
t.Error(res.StatusCode)
|
||||
return false
|
||||
}
|
||||
if contentDispositionHeader != fmt.Sprintf(`attachment; filename="%s"`, fileName) {
|
||||
t.Errorf("incorrect Content-Disposition header: %s", contentDispositionHeader)
|
||||
return false
|
||||
}
|
||||
|
||||
switch rd {
|
||||
case 0:
|
||||
if body != content {
|
||||
|
|
|
@ -38,7 +38,7 @@ func waitForReady(addr string) bool {
|
|||
for retry > 0 {
|
||||
_, _, errs := setCl.Health()
|
||||
if len(errs) > 0 {
|
||||
time.Sleep(100)
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
} else {
|
||||
return true
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue