summaryrefslogtreecommitdiff
path: root/service/headers/config.go
blob: f9af1df23d81c366c4e5534b42529b07bf71ef9b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package headers

import "github.com/spiral/roadrunner/service"

// Config declares headers service configuration.
type Config struct {
	// CORS settings.
	CORS *CORSConfig

	// Request headers to add to every payload send to PHP.
	Request map[string]string

	// Response headers to add to every payload generated by PHP.
	Response map[string]string
}

// CORSConfig headers configuration.
type CORSConfig struct {
	// AllowedOrigin: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Origin
	AllowedOrigin string

	// AllowedHeaders: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Headers
	AllowedHeaders string

	// AllowedMethods: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Methods
	AllowedMethods string

	// AllowCredentials https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Credentials
	AllowCredentials *bool

	// ExposeHeaders:  https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Expose-Headers
	ExposedHeaders string

	// MaxAge of CORS headers in seconds/
	MaxAge int
}

// Hydrate service config.
func (c *Config) Hydrate(cfg service.Config) error {
	return cfg.Unmarshal(c)
}