MCPcopy
hub / github.com/gofiber/fiber / Attachment

Method Attachment

res.go:207–228  ·  view source on GitHub ↗

Attachment sets the HTTP response Content-Disposition header field to attachment.

(filename ...string)

Source from the content-addressed store, hash-verified

205
206// Attachment sets the HTTP response Content-Disposition header field to attachment.
207func (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.

Callers 1

SendFileMethod · 0.95

Calls 7

TypeMethod · 0.95
setCanonicalMethod · 0.95
sanitizeFilenameFunction · 0.85
isASCIIMethod · 0.80
quoteStringMethod · 0.80
quoteRawStringMethod · 0.80

Tested by

no test coverage detected