mirror of
https://github.com/containous/traefik.git
synced 2024-12-22 13:34:03 +03:00
Change custom headers separator
This commit is contained in:
parent
d6ad7e2e64
commit
3a99c86cb3
@ -178,13 +178,13 @@ Labels can be used on containers to override default behaviour.
|
||||
| Label | Description |
|
||||
|----------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||
| `traefik.frontend.headers.allowedHosts=EXPR` | Provides a list of allowed hosts that requests will be processed. Format: `Host1,Host2` |
|
||||
| `traefik.frontend.headers.customrequestheaders=EXPR ` | Provides the container with custom request headers that will be appended to each request forwarded to the container. Format: `HEADER:value,HEADER2:value2` |
|
||||
| `traefik.frontend.headers.customresponseheaders=EXPR` | Appends the headers to each response returned by the container, before forwarding the response to the client. Format: `HEADER:value,HEADER2:value2` |
|
||||
| `traefik.frontend.headers.customRequestHeaders=EXPR ` | Provides the container with custom request headers that will be appended to each request forwarded to the container. Format: <code>HEADER:value||HEADER2:value2</code> |
|
||||
| `traefik.frontend.headers.customResponseHeaders=EXPR` | Appends the headers to each response returned by the container, before forwarding the response to the client. Format: <code>HEADER:value||HEADER2:value2</code> |
|
||||
| `traefik.frontend.headers.hostsProxyHeaders=EXPR ` | Provides a list of headers that the proxied hostname may be stored. Format: `HEADER1,HEADER2` |
|
||||
| `traefik.frontend.headers.SSLRedirect=true` | Forces the frontend to redirect to SSL if a non-SSL request is sent. |
|
||||
| `traefik.frontend.headers.SSLTemporaryRedirect=true` | Forces the frontend to redirect to SSL if a non-SSL request is sent, but by sending a 302 instead of a 301. |
|
||||
| `traefik.frontend.headers.SSLHost=HOST` | This setting configures the hostname that redirects will be based on. Default is "", which is the same host as the request. |
|
||||
| `traefik.frontend.headers.SSLProxyHeaders=EXPR` | Header combinations that would signify a proper SSL Request (Such as `X-Forwarded-For:https`). Format: `HEADER:value,HEADER2:value2` |
|
||||
| `traefik.frontend.headers.SSLProxyHeaders=EXPR` | Header combinations that would signify a proper SSL Request (Such as `X-Forwarded-For:https`). Format: <code>HEADER:value||HEADER2:value2</code> |
|
||||
| `traefik.frontend.headers.STSSeconds=315360000` | Sets the max-age of the STS header. |
|
||||
| `traefik.frontend.headers.STSIncludeSubdomains=true` | Adds the `IncludeSubdomains` section of the STS header. |
|
||||
| `traefik.frontend.headers.STSPreload=true` | Adds the preload flag to the STS header. |
|
||||
|
@ -139,13 +139,13 @@ The following security annotations can be applied to the ingress object to add s
|
||||
| Annotation | Description |
|
||||
|----------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||
| `ingress.kubernetes.io/allowed-hosts:EXPR` | Provides a list of allowed hosts that requests will be processed. Format: `Host1,Host2` |
|
||||
| `ingress.kubernetes.io/custom-request-headers:EXPR ` | Provides the container with custom request headers that will be appended to each request forwarded to the container. Format: `HEADER:value,HEADER2:value2` |
|
||||
| `ingress.kubernetes.io/custom-response-headers:EXPR` | Appends the headers to each response returned by the container, before forwarding the response to the client. Format: `HEADER:value,HEADER2:value2` |
|
||||
| `ingress.kubernetes.io/custom-request-headers:EXPR ` | Provides the container with custom request headers that will be appended to each request forwarded to the container. Format: <code>HEADER:value||HEADER2:value2</code> |
|
||||
| `ingress.kubernetes.io/custom-response-headers:EXPR` | Appends the headers to each response returned by the container, before forwarding the response to the client. Format: <code>HEADER:value||HEADER2:value2</code> |
|
||||
| `ingress.kubernetes.io/proxy-headers:EXPR ` | Provides a list of headers that the proxied hostname may be stored. Format: `HEADER1,HEADER2` |
|
||||
| `ingress.kubernetes.io/ssl-redirect:true` | Forces the frontend to redirect to SSL if a non-SSL request is sent. |
|
||||
| `ingress.kubernetes.io/ssl-temporary-redirect:true` | Forces the frontend to redirect to SSL if a non-SSL request is sent, but by sending a 302 instead of a 301. |
|
||||
| `ingress.kubernetes.io/ssl-host:HOST` | This setting configures the hostname that redirects will be based on. Default is "", which is the same host as the request. |
|
||||
| `ingress.kubernetes.io/ssl-proxy-headers:EXPR` | Header combinations that would signify a proper SSL Request (Such as `X-Forwarded-For:https`). Format: `HEADER:value,HEADER2:value2` |
|
||||
| `ingress.kubernetes.io/ssl-proxy-headers:EXPR` | Header combinations that would signify a proper SSL Request (Such as `X-Forwarded-For:https`). Format: <code>HEADER:value||HEADER2:value2</code> |
|
||||
| `ingress.kubernetes.io/hsts-max-age:315360000` | Sets the max-age of the HSTS header. |
|
||||
| `ngress.kubernetes.io/hsts-include-subdomains:true` | Adds the IncludeSubdomains section of the STS header. |
|
||||
| `ingress.kubernetes.io/hsts-preload:true` | Adds the preload flag to the HSTS header. |
|
||||
|
@ -86,7 +86,7 @@ type networkData struct {
|
||||
ID string
|
||||
}
|
||||
|
||||
func (p Provider) createClient() (client.APIClient, error) {
|
||||
func (p *Provider) createClient() (client.APIClient, error) {
|
||||
var httpClient *http.Client
|
||||
|
||||
if p.TLS != nil {
|
||||
@ -292,10 +292,10 @@ func (p *Provider) loadDockerConfig(containersInspected []dockerData) *types.Con
|
||||
"getServiceRedirect": getFuncServiceStringLabel(types.SuffixFrontendRedirect, defaultFrontendRedirect),
|
||||
"getWhitelistSourceRange": getFuncSliceStringLabel(types.LabelTraefikFrontendWhitelistSourceRange),
|
||||
|
||||
"hasRequestHeaders": hasLabel(types.LabelFrontendRequestHeader),
|
||||
"getRequestHeaders": getFuncMapLabel(types.LabelFrontendRequestHeader),
|
||||
"hasResponseHeaders": hasLabel(types.LabelFrontendResponseHeader),
|
||||
"getResponseHeaders": getFuncMapLabel(types.LabelFrontendResponseHeader),
|
||||
"hasRequestHeaders": hasLabel(types.LabelFrontendRequestHeaders),
|
||||
"getRequestHeaders": getFuncMapLabel(types.LabelFrontendRequestHeaders),
|
||||
"hasResponseHeaders": hasLabel(types.LabelFrontendResponseHeaders),
|
||||
"getResponseHeaders": getFuncMapLabel(types.LabelFrontendResponseHeaders),
|
||||
"hasAllowedHostsHeaders": hasLabel(types.LabelFrontendAllowedHosts),
|
||||
"getAllowedHostsHeaders": getFuncSliceStringLabel(types.LabelFrontendAllowedHosts),
|
||||
"hasHostsProxyHeaders": hasLabel(types.LabelFrontendHostsProxyHeaders),
|
||||
|
@ -2,6 +2,7 @@ package docker
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
@ -42,21 +43,30 @@ func getFuncMapLabel(labelName string) func(container dockerData) map[string]str
|
||||
}
|
||||
|
||||
func parseMapLabel(container dockerData, labelName string) map[string]string {
|
||||
customHeaders := make(map[string]string)
|
||||
if label, err := getLabel(container, labelName); err == nil {
|
||||
for _, headers := range strings.Split(label, ",") {
|
||||
pair := strings.Split(headers, ":")
|
||||
if parts, err := getLabel(container, labelName); err == nil {
|
||||
if len(parts) == 0 {
|
||||
log.Errorf("Could not load %q", labelName)
|
||||
return nil
|
||||
}
|
||||
|
||||
values := make(map[string]string)
|
||||
for _, headers := range strings.Split(parts, "||") {
|
||||
pair := strings.SplitN(headers, ":", 2)
|
||||
if len(pair) != 2 {
|
||||
log.Warnf("Could not load header %q: %v, skipping...", labelName, pair)
|
||||
log.Warnf("Could not load %q: %v, skipping...", labelName, pair)
|
||||
} else {
|
||||
customHeaders[pair[0]] = pair[1]
|
||||
values[http.CanonicalHeaderKey(strings.TrimSpace(pair[0]))] = strings.TrimSpace(pair[1])
|
||||
}
|
||||
}
|
||||
|
||||
if len(values) == 0 {
|
||||
log.Errorf("Could not load %q", labelName)
|
||||
return nil
|
||||
}
|
||||
return values
|
||||
}
|
||||
if len(customHeaders) == 0 {
|
||||
log.Errorf("Could not load %q", labelName)
|
||||
}
|
||||
return customHeaders
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func getFuncStringLabel(label string, defaultValue string) func(container dockerData) string {
|
||||
|
@ -1,6 +1,7 @@
|
||||
package kubernetes
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/containous/traefik/log"
|
||||
@ -50,12 +51,12 @@ func getMapAnnotation(meta *v1beta1.Ingress, annotName string) map[string]string
|
||||
}
|
||||
|
||||
mapValue := make(map[string]string)
|
||||
for _, parts := range strings.Split(values, ",") {
|
||||
pair := strings.Split(parts, ":")
|
||||
for _, parts := range strings.Split(values, "||") {
|
||||
pair := strings.SplitN(parts, ":", 2)
|
||||
if len(pair) != 2 {
|
||||
log.Warnf("Could not load %q: %v, skipping...", annotName, pair)
|
||||
} else {
|
||||
mapValue[pair[0]] = pair[1]
|
||||
mapValue[http.CanonicalHeaderKey(strings.TrimSpace(pair[0]))] = strings.TrimSpace(pair[1])
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -73,7 +73,7 @@ type Provider struct {
|
||||
lastConfiguration safe.Safe
|
||||
}
|
||||
|
||||
func (p Provider) newK8sClient() (Client, error) {
|
||||
func (p *Provider) newK8sClient() (Client, error) {
|
||||
withEndpoint := ""
|
||||
if p.Endpoint != "" {
|
||||
withEndpoint = fmt.Sprintf(" with endpoint %v", p.Endpoint)
|
||||
@ -356,7 +356,7 @@ func (p *Provider) loadIngresses(k8sClient Client) (*types.Configuration, error)
|
||||
return &templateObjects, nil
|
||||
}
|
||||
|
||||
func (p Provider) loadConfig(templateObjects types.Configuration) *types.Configuration {
|
||||
func (p *Provider) loadConfig(templateObjects types.Configuration) *types.Configuration {
|
||||
var FuncMap = template.FuncMap{}
|
||||
configuration, err := p.GetConfiguration("templates/kubernetes.tmpl", FuncMap, templateObjects)
|
||||
if err != nil {
|
||||
|
@ -32,8 +32,8 @@ const (
|
||||
LabelFrontendRedirect = LabelPrefix + SuffixFrontendRedirect
|
||||
LabelTraefikFrontendValue = LabelPrefix + "frontend.value"
|
||||
LabelTraefikFrontendWhitelistSourceRange = LabelPrefix + "frontend.whitelistSourceRange"
|
||||
LabelFrontendRequestHeader = LabelPrefix + "frontend.headers.customrequestheaders"
|
||||
LabelFrontendResponseHeader = LabelPrefix + "frontend.headers.customresponseheaders"
|
||||
LabelFrontendRequestHeaders = LabelPrefix + "frontend.headers.customRequestHeaders"
|
||||
LabelFrontendResponseHeaders = LabelPrefix + "frontend.headers.customResponseHeaders"
|
||||
LabelFrontendAllowedHosts = LabelPrefix + "frontend.headers.allowedHosts"
|
||||
LabelFrontendHostsProxyHeaders = LabelPrefix + "frontend.headers.hostsProxyHeaders"
|
||||
LabelFrontendSSLRedirect = LabelPrefix + "frontend.headers.SSLRedirect"
|
||||
|
Loading…
Reference in New Issue
Block a user