headers

package module
v5.1.9 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2025 License: MIT Imports: 12 Imported by: 2

README

Documentation

Index

Constants

View Source
const (
	RootPluginName string = "http"
	PluginName     string = "headers"
)

PluginName contains default service name.

Variables

This section is empty.

Functions

This section is empty.

Types

type CORSConfig

type CORSConfig struct {
	// AllowedOrigin: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Origin
	AllowedOrigin      string `mapstructure:"allowed_origin"`
	AllowedOriginRegex string `mapstructure:"allowed_origin_regex"`
	// AllowedHeaders: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Headers
	AllowedHeaders string `mapstructure:"allowed_headers"`
	// AllowedMethods: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Methods
	AllowedMethods string `mapstructure:"allowed_methods"`
	// AllowCredentials https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Credentials
	AllowCredentials bool `mapstructure:"allow_credentials"`
	// ExposeHeaders:  https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Expose-Headers
	ExposedHeaders string `mapstructure:"exposed_headers"`
	// MaxAge of CORS headers in seconds/
	MaxAge int `mapstructure:"max_age"`
	// Status code to use for successful OPTIONS requests. Default value is http.StatusOK (200).
	OptionsSuccessStatus int `mapstructure:"options_success_status"`
	// Debug CORS requests
	Debug bool `mapstructure:"debug"`
}

CORSConfig headers configuration.

type Config

type Config struct {
	// CORS settings.
	CORS *CORSConfig `mapstructure:"cors"`
	// Request headers to add to every payload send to PHP.
	Request map[string]string `mapstructure:"request"`
	// Response headers to add to every payload generated by PHP.
	Response map[string]string `mapstructure:"response"`
}

Config declares headers service configuration.

type Configurer

type Configurer interface {
	// UnmarshalKey takes a single key and unmarshal it into a Struct.
	UnmarshalKey(name string, out any) error
	// Has checks if a config section exists.
	Has(name string) bool
}

type Plugin

type Plugin struct {
	// contains filtered or unexported fields
}

Plugin serves header files. Potentially convert into middleware?

func (*Plugin) Init

func (p *Plugin) Init(cfg Configurer) error

Init must return configure service and return true if the service has Status=enabled. Must return an error in case of misconfiguration. Services must not be used without proper configuration pushed first.

func (*Plugin) Middleware

func (p *Plugin) Middleware(next http.Handler) http.Handler

Middleware is HTTP plugin middleware to serve headers

func (*Plugin) Name

func (p *Plugin) Name() string

Jump to

Keyboard shortcuts

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