Attachment sets the HTTP response Content-Disposition header field to attachment.
(filename ...string)
| 205 | |
| 206 | // Attachment sets the HTTP response Content-Disposition header field to attachment. |
| 207 | func (r *DefaultRes) Attachment(filename ...string) { |
| 208 | if len(filename) > 0 { |
| 209 | fname := filepath.Base(filename[0]) |
| 210 | fname = sanitizeFilename(fname) |
| 211 | fname = fallbackFilenameIfInvalid(fname) |
| 212 | r.Type(filepath.Ext(fname)) |
| 213 | app := r.c.app |
| 214 | var quoted string |
| 215 | if app.isASCII(fname) { |
| 216 | quoted = app.quoteString(fname) |
| 217 | } else { |
| 218 | quoted = app.quoteRawString(fname) |
| 219 | } |
| 220 | disp := `attachment; filename="` + quoted + `"` |
| 221 | if !app.isASCII(fname) { |
| 222 | disp += `; filename*=UTF-8''` + url.PathEscape(fname) |
| 223 | } |
| 224 | r.setCanonical(HeaderContentDisposition, disp) |
| 225 | return |
| 226 | } |
| 227 | r.setCanonical(HeaderContentDisposition, "attachment") |
| 228 | } |
| 229 | |
| 230 | // ClearCookie expires a specific cookie by key on the client side. |
| 231 | // If no key is provided it expires all cookies that came with the request. |
no test coverage detected