Hello,
We want to change the value of an incoming header in case it matches a specific value.
And we have tried a few things but we were not succesfull.
In our last tries we have used a goto template like:
ex:
apiVersion: traefik.containo.us/v1alpha1
kind: Middleware
metadata:
name: api-version-header
spec:
headers:
customRequestHeaders:
User-Agent: |-
{{ if eq .Request.Header.Get "Content-Type" "My Custom User Agent" }}
custom-value-1
{{ else }}
custom-value-2
{{ end }}
But when we are trying requests we are getting a 500 error message.
{"level":"debug","msg":"'500 Internal Server Error' caused by: net/http: invalid header field value "{{ if eq .Request.Header.Get \"Content-Type\" \"My Custom User Agent\" }}\n custom-value-1\n{{ else }}\n custom-value-2\n{{ end }}" for key User-Agent","time":"2023-02-22T15:03:10Z"}
But if put only the value without the if , then it works, ex:
apiVersion: traefik.containo.us/v1alpha1
kind: Middleware
metadata:
name: api-version-header
spec:
headers:
customRequestHeaders:
User-Agent: |-
custom-value-1
Can't we add logical conditions like if in the temaplate ?
If not , is there is any other way to set a specific value on a request header depending on the value of the request header ?
Thanks.