contentdisposition

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 4, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package contentdisposition creates and parses HTTP Content-Disposition headers. It is a port of the npm content-disposition package using only the Go standard library.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Format

func Format(filename string, opts ...Option) string

Format builds a Content-Disposition header value for the given filename. By default the type is "attachment". When the filename contains non-ASCII characters, both a plain ASCII fallback filename and an RFC 5987 filename* parameter are emitted.

Types

type ContentDisposition

type ContentDisposition struct {
	// Type is the disposition type, e.g. "attachment" or "inline".
	Type string
	// Filename is the decoded filename, if any (from filename* or filename).
	Filename string
	// Parameters holds all disposition parameters (including "filename").
	Parameters map[string]string
}

ContentDisposition represents a parsed Content-Disposition header.

func Parse

func Parse(s string) (ContentDisposition, error)

Parse parses a Content-Disposition header value. If no disposition type is present the default "attachment" is used. A filename* parameter takes precedence over a plain filename parameter.

type Option

type Option func(*options)

Option configures how a Content-Disposition header is formatted.

func WithFallback

func WithFallback(fallback bool) Option

WithFallback controls whether an ASCII fallback filename parameter is emitted when the filename contains non-ASCII characters. It is true by default; setting it to false suppresses the plain filename parameter.

func WithType

func WithType(t string) Option

WithType sets the disposition type (default "attachment").

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL