-
-
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
Fix HTTP headers for issue attachment download #270
Conversation
- Download filename was wrong for files other than images. Example: It was `download` instead of `file.pdf` - PDF was downloading instead of showing on browser
// Fix #312. Attachments with , in their name are not handled correctly by Google Chrome. | ||
// We must put the name in " manually. | ||
if err = repo.ServeData(ctx, "\""+attach.Name+"\"", fr); err != nil { | ||
if err = repo.ServeData(ctx, attach.Name, fr); err != nil { |
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.
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.
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 comment
The 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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, now I see, thanks for double-checking
ctx.Resp.Header().Set("Cache-Control", "public,max-age=86400") | ||
|
||
// Google Chrome dislike commas in filenames, so let's change it to a space | ||
name = strings.Replace(name, ",", " ", -1) |
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.
I dislike spaces in filenames, how about a dash ? :)
Actually, how about a sanitizing function to generalize the issue ? Like, I'm thinking slashes might be impractical to have...
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.
i like underscores....
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.
Actually, how about a sanitizing function to generalize the issue ? Like, I'm thinking slashes might be impractical to have...
I did research on this and tried few approaches. Unfortunately there isn't how to sanitize it, it's actually a Chrome bug. And only commas trigger this AFAIK.
I don't have strong feeling for comma vs space.
underscores work for me too, although I prefer dashes as you can
do that without holding SHIFT :)
|
LGTM - the systems I use don't choke on spaces (it's just me, but I can blame the people who attach files with spaces or commas in their filenames) |
LGTM |
This fixes:
download
instead offile.pdf