Change custom headers separator
This commit is contained in:
parent
d6ad7e2e64
commit
3a99c86cb3
7 changed files with 39 additions and 28 deletions
|
@ -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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue