-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix HTTP headers for issue attachment download #270
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,8 +5,8 @@ | |
package repo | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"path" | ||
|
||
"code.gitea.io/git" | ||
|
||
|
@@ -22,14 +22,16 @@ func ServeData(ctx *context.Context, name string, reader io.Reader) error { | |
buf = buf[:n] | ||
} | ||
|
||
if !base.IsTextFile(buf) { | ||
if !base.IsImageFile(buf) { | ||
ctx.Resp.Header().Set("Content-Disposition", "attachment; filename=\""+path.Base(ctx.Repo.TreePath)+"\"") | ||
ctx.Resp.Header().Set("Content-Transfer-Encoding", "binary") | ||
} | ||
} else if !ctx.QueryBool("render") { | ||
ctx.Resp.Header().Set("Cache-Control", "public,max-age=86400") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This cache lifetime change seems to be unrelated to the scope of this PR There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The cache was there before, I just moved it to another place There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, now I see, thanks for double-checking |
||
|
||
if base.IsTextFile(buf) || ctx.QueryBool("render") { | ||
ctx.Resp.Header().Set("Content-Type", "text/plain; charset=utf-8") | ||
} else if base.IsImageFile(buf) || base.IsPDFFile(buf) { | ||
ctx.Resp.Header().Set("Content-Disposition", fmt.Sprintf(`inline; filename="%s"`, name)) | ||
} else { | ||
ctx.Resp.Header().Set("Content-Disposition", fmt.Sprintf(`attachment; filename="%s"`, name)) | ||
} | ||
|
||
ctx.Resp.Write(buf) | ||
_, err := io.Copy(ctx.Resp, reader) | ||
return err | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this re-introduce the referenced issue ?
gogs/gogs#312
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, the quote is preserved here and here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you test the issue explained in gogits#312 ?
I'm not sure the bug was related to the quotes in Content-Disposition rather than in repo.ServeData argument
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm... In fact there's a problem, thanks for checking.
But I don't understand why it happen. I just moved the quotes, but it's there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@strk It's fixed now. It's was not actually fixed before, because the header was not actually set for these cases.