Revert "Backport of NET-5530 Support response header modifiers on http-route config entry into release/1.16.x" (#18770)

Revert "Backport of NET-5530 Support response header modifiers on http-route config entry into release/1.16.x (#18725)"

This reverts commit b8a0e849832378b63732b40f6ea849b9c6c35803.
This commit is contained in:
Nathan Coleman 2023-09-12 15:58:24 -04:00 committed by GitHub
parent 1be813033f
commit f77e477ebe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 648 additions and 1035 deletions

View File

@ -1,3 +0,0 @@
```release-note:feature
api-gateway: Add support for response header modifiers on http-route configuration entry
```

View File

@ -29,7 +29,6 @@ type GatewayChainSynthesizer struct {
type hostnameMatch struct { type hostnameMatch struct {
match structs.HTTPMatch match structs.HTTPMatch
filters structs.HTTPFilters filters structs.HTTPFilters
responseFilters structs.HTTPResponseFilters
services []structs.HTTPService services []structs.HTTPService
} }
@ -90,7 +89,6 @@ func initHostMatches(hostname string, route *structs.HTTPRouteConfigEntry, curre
matches = append(matches, hostnameMatch{ matches = append(matches, hostnameMatch{
match: match, match: match,
filters: rule.Filters, filters: rule.Filters,
responseFilters: rule.ResponseFilters,
services: rule.Services, services: rule.Services,
}) })
} }
@ -230,7 +228,6 @@ func consolidateHTTPRoutes(matchesByHostname map[string][]hostnameMatch, listene
route.Rules = append(route.Rules, structs.HTTPRouteRule{ route.Rules = append(route.Rules, structs.HTTPRouteRule{
Matches: []structs.HTTPMatch{rule.match}, Matches: []structs.HTTPMatch{rule.match},
Filters: rule.filters, Filters: rule.filters,
ResponseFilters: rule.responseFilters,
Services: rule.services, Services: rule.services,
}) })
} }

View File

@ -79,8 +79,7 @@ func httpRouteToDiscoveryChain(route structs.HTTPRouteConfigEntry) (*structs.Ser
var defaults []*structs.ServiceConfigEntry var defaults []*structs.ServiceConfigEntry
for idx, rule := range route.Rules { for idx, rule := range route.Rules {
requestModifier := httpRouteFiltersToServiceRouteHeaderModifier(rule.Filters.Headers) modifier := httpRouteFiltersToServiceRouteHeaderModifier(rule.Filters.Headers)
responseModifier := httpRouteFiltersToServiceRouteHeaderModifier(rule.ResponseFilters.Headers)
prefixRewrite := httpRouteFiltersToDestinationPrefixRewrite(rule.Filters.URLRewrite) prefixRewrite := httpRouteFiltersToDestinationPrefixRewrite(rule.Filters.URLRewrite)
var destination structs.ServiceRouteDestination var destination structs.ServiceRouteDestination
@ -91,29 +90,16 @@ func httpRouteToDiscoveryChain(route structs.HTTPRouteConfigEntry) (*structs.Ser
if service.Filters.URLRewrite == nil { if service.Filters.URLRewrite == nil {
servicePrefixRewrite = prefixRewrite servicePrefixRewrite = prefixRewrite
} }
serviceModifier := httpRouteFiltersToServiceRouteHeaderModifier(service.Filters.Headers)
// Merge service request header modifier(s) onto route rule modifiers modifier.Add = mergeMaps(modifier.Add, serviceModifier.Add)
// Note: Removals for the same header may exist on the rule + the service and modifier.Set = mergeMaps(modifier.Set, serviceModifier.Set)
// will result in idempotent duplicate values in the modifier w/ service coming last modifier.Remove = append(modifier.Remove, serviceModifier.Remove...)
serviceRequestModifier := httpRouteFiltersToServiceRouteHeaderModifier(service.Filters.Headers)
requestModifier.Add = mergeMaps(requestModifier.Add, serviceRequestModifier.Add)
requestModifier.Set = mergeMaps(requestModifier.Set, serviceRequestModifier.Set)
requestModifier.Remove = append(requestModifier.Remove, serviceRequestModifier.Remove...)
// Merge service response header modifier(s) onto route rule modifiers
// Note: Removals for the same header may exist on the rule + the service and
// will result in idempotent duplicate values in the modifier w/ service coming last
serviceResponseModifier := httpRouteFiltersToServiceRouteHeaderModifier(service.ResponseFilters.Headers)
responseModifier.Add = mergeMaps(responseModifier.Add, serviceResponseModifier.Add)
responseModifier.Set = mergeMaps(responseModifier.Set, serviceResponseModifier.Set)
responseModifier.Remove = append(responseModifier.Remove, serviceResponseModifier.Remove...)
destination.Service = service.Name destination.Service = service.Name
destination.Namespace = service.NamespaceOrDefault() destination.Namespace = service.NamespaceOrDefault()
destination.Partition = service.PartitionOrDefault() destination.Partition = service.PartitionOrDefault()
destination.PrefixRewrite = servicePrefixRewrite destination.PrefixRewrite = servicePrefixRewrite
destination.RequestHeaders = requestModifier destination.RequestHeaders = modifier
destination.ResponseHeaders = responseModifier
// since we have already validated the protocol elsewhere, we // since we have already validated the protocol elsewhere, we
// create a new service defaults here to make sure we pass validation // create a new service defaults here to make sure we pass validation
@ -129,8 +115,7 @@ func httpRouteToDiscoveryChain(route structs.HTTPRouteConfigEntry) (*structs.Ser
destination.Namespace = route.NamespaceOrDefault() destination.Namespace = route.NamespaceOrDefault()
destination.Partition = route.PartitionOrDefault() destination.Partition = route.PartitionOrDefault()
destination.PrefixRewrite = prefixRewrite destination.PrefixRewrite = prefixRewrite
destination.RequestHeaders = requestModifier destination.RequestHeaders = modifier
destination.ResponseHeaders = responseModifier
splitter := &structs.ServiceSplitterConfigEntry{ splitter := &structs.ServiceSplitterConfigEntry{
Kind: structs.ServiceSplitter, Kind: structs.ServiceSplitter,

View File

@ -518,70 +518,8 @@ func TestGatewayChainSynthesizer_Synthesize(t *testing.T) {
Kind: structs.HTTPRoute, Kind: structs.HTTPRoute,
Name: "http-route", Name: "http-route",
Rules: []structs.HTTPRouteRule{{ Rules: []structs.HTTPRouteRule{{
Filters: structs.HTTPFilters{
Headers: []structs.HTTPHeaderFilter{
{
Add: map[string]string{"add me to the rule request": "present"},
Set: map[string]string{"set me on the rule request": "present"},
Remove: []string{"remove me from the rule request"},
},
{
Add: map[string]string{"add me to the rule and service request": "rule"},
Set: map[string]string{"set me on the rule and service request": "rule"},
},
{
Remove: []string{"remove me from the rule and service request"},
},
},
},
ResponseFilters: structs.HTTPResponseFilters{
Headers: []structs.HTTPHeaderFilter{{
Add: map[string]string{
"add me to the rule response": "present",
"add me to the rule and service response": "rule",
},
Set: map[string]string{
"set me on the rule response": "present",
"set me on the rule and service response": "rule",
},
Remove: []string{
"remove me from the rule response",
"remove me from the rule and service response",
},
}},
},
Services: []structs.HTTPService{{ Services: []structs.HTTPService{{
Name: "foo", Name: "foo",
Filters: structs.HTTPFilters{
Headers: []structs.HTTPHeaderFilter{
{
Add: map[string]string{"add me to the service request": "present"},
},
{
Set: map[string]string{"set me on the service request": "present"},
Remove: []string{"remove me from the service request"},
},
{
Add: map[string]string{"add me to the rule and service request": "service"},
Set: map[string]string{"set me on the rule and service request": "service"},
Remove: []string{"remove me from the rule and service request"},
},
},
},
ResponseFilters: structs.HTTPResponseFilters{
Headers: []structs.HTTPHeaderFilter{
{
Add: map[string]string{"add me to the service response": "present"},
Set: map[string]string{"set me on the service response": "present"},
Remove: []string{"remove me from the service response"},
},
{
Add: map[string]string{"add me to the rule and service response": "service"},
Set: map[string]string{"set me on the rule and service response": "service"},
Remove: []string{"remove me from the rule and service response"},
},
},
},
}}, }},
}}, }},
}, },
@ -619,40 +557,8 @@ func TestGatewayChainSynthesizer_Synthesize(t *testing.T) {
Partition: "default", Partition: "default",
Namespace: "default", Namespace: "default",
RequestHeaders: &structs.HTTPHeaderModifiers{ RequestHeaders: &structs.HTTPHeaderModifiers{
Add: map[string]string{ Add: make(map[string]string),
"add me to the rule request": "present", Set: make(map[string]string),
"add me to the service request": "present",
"add me to the rule and service request": "service",
},
Set: map[string]string{
"set me on the rule request": "present",
"set me on the service request": "present",
"set me on the rule and service request": "service",
},
Remove: []string{
"remove me from the rule request",
"remove me from the rule and service request",
"remove me from the service request",
"remove me from the rule and service request",
},
},
ResponseHeaders: &structs.HTTPHeaderModifiers{
Add: map[string]string{
"add me to the rule response": "present",
"add me to the service response": "present",
"add me to the rule and service response": "service",
},
Set: map[string]string{
"set me on the rule response": "present",
"set me on the service response": "present",
"set me on the rule and service response": "service",
},
Remove: []string{
"remove me from the rule response",
"remove me from the rule and service response",
"remove me from the service response",
"remove me from the rule and service response",
},
}, },
}, },
}, },
@ -757,10 +663,6 @@ func TestGatewayChainSynthesizer_Synthesize(t *testing.T) {
Add: make(map[string]string), Add: make(map[string]string),
Set: make(map[string]string), Set: make(map[string]string),
}, },
ResponseHeaders: &structs.HTTPHeaderModifiers{
Add: make(map[string]string),
Set: make(map[string]string),
},
}, },
}, },
NextNode: "resolver:foo-2.default.default.dc2", NextNode: "resolver:foo-2.default.default.dc2",
@ -948,10 +850,6 @@ func TestGatewayChainSynthesizer_ComplexChain(t *testing.T) {
Add: make(map[string]string), Add: make(map[string]string),
Set: make(map[string]string), Set: make(map[string]string),
}, },
ResponseHeaders: &structs.HTTPHeaderModifiers{
Add: make(map[string]string),
Set: make(map[string]string),
},
}, },
}, },
NextNode: "splitter:splitter-one.default.default", NextNode: "splitter:splitter-one.default.default",

View File

@ -421,12 +421,6 @@ type HTTPFilters struct {
URLRewrite *URLRewrite URLRewrite *URLRewrite
} }
// HTTPResponseFilters specifies a list of filters used to modify the
// response returned by an upstream
type HTTPResponseFilters struct {
Headers []HTTPHeaderFilter
}
// HTTPHeaderFilter specifies how HTTP headers should be modified. // HTTPHeaderFilter specifies how HTTP headers should be modified.
type HTTPHeaderFilter struct { type HTTPHeaderFilter struct {
Add map[string]string Add map[string]string
@ -444,9 +438,6 @@ type HTTPRouteRule struct {
// Filters is a list of HTTP-based filters used to modify a request prior // Filters is a list of HTTP-based filters used to modify a request prior
// to routing it to the upstream service // to routing it to the upstream service
Filters HTTPFilters Filters HTTPFilters
// ResponseFilters is a list of HTTP-based filters used to modify a response
// returned by the upstream service
ResponseFilters HTTPResponseFilters
// Matches specified the matching criteria used in the routing table. If a // Matches specified the matching criteria used in the routing table. If a
// request matches the given HTTPMatch configuration, then traffic is routed // request matches the given HTTPMatch configuration, then traffic is routed
// to services specified in the Services field. // to services specified in the Services field.
@ -466,10 +457,6 @@ type HTTPService struct {
// to routing it to the upstream service // to routing it to the upstream service
Filters HTTPFilters Filters HTTPFilters
// ResponseFilters is a list of HTTP-based filters used to modify the
// response returned from the upstream service
ResponseFilters HTTPResponseFilters
acl.EnterpriseMeta `hcl:",squash" mapstructure:",squash"` acl.EnterpriseMeta `hcl:",squash" mapstructure:",squash"`
} }

View File

@ -383,28 +383,6 @@ func (o *HTTPRouteConfigEntry) DeepCopy() *HTTPRouteConfigEntry {
cp.Rules[i2].Filters.URLRewrite = new(URLRewrite) cp.Rules[i2].Filters.URLRewrite = new(URLRewrite)
*cp.Rules[i2].Filters.URLRewrite = *o.Rules[i2].Filters.URLRewrite *cp.Rules[i2].Filters.URLRewrite = *o.Rules[i2].Filters.URLRewrite
} }
if o.Rules[i2].ResponseFilters.Headers != nil {
cp.Rules[i2].ResponseFilters.Headers = make([]HTTPHeaderFilter, len(o.Rules[i2].ResponseFilters.Headers))
copy(cp.Rules[i2].ResponseFilters.Headers, o.Rules[i2].ResponseFilters.Headers)
for i5 := range o.Rules[i2].ResponseFilters.Headers {
if o.Rules[i2].ResponseFilters.Headers[i5].Add != nil {
cp.Rules[i2].ResponseFilters.Headers[i5].Add = make(map[string]string, len(o.Rules[i2].ResponseFilters.Headers[i5].Add))
for k7, v7 := range o.Rules[i2].ResponseFilters.Headers[i5].Add {
cp.Rules[i2].ResponseFilters.Headers[i5].Add[k7] = v7
}
}
if o.Rules[i2].ResponseFilters.Headers[i5].Remove != nil {
cp.Rules[i2].ResponseFilters.Headers[i5].Remove = make([]string, len(o.Rules[i2].ResponseFilters.Headers[i5].Remove))
copy(cp.Rules[i2].ResponseFilters.Headers[i5].Remove, o.Rules[i2].ResponseFilters.Headers[i5].Remove)
}
if o.Rules[i2].ResponseFilters.Headers[i5].Set != nil {
cp.Rules[i2].ResponseFilters.Headers[i5].Set = make(map[string]string, len(o.Rules[i2].ResponseFilters.Headers[i5].Set))
for k7, v7 := range o.Rules[i2].ResponseFilters.Headers[i5].Set {
cp.Rules[i2].ResponseFilters.Headers[i5].Set[k7] = v7
}
}
}
}
if o.Rules[i2].Matches != nil { if o.Rules[i2].Matches != nil {
cp.Rules[i2].Matches = make([]HTTPMatch, len(o.Rules[i2].Matches)) cp.Rules[i2].Matches = make([]HTTPMatch, len(o.Rules[i2].Matches))
copy(cp.Rules[i2].Matches, o.Rules[i2].Matches) copy(cp.Rules[i2].Matches, o.Rules[i2].Matches)
@ -449,28 +427,6 @@ func (o *HTTPRouteConfigEntry) DeepCopy() *HTTPRouteConfigEntry {
cp.Rules[i2].Services[i4].Filters.URLRewrite = new(URLRewrite) cp.Rules[i2].Services[i4].Filters.URLRewrite = new(URLRewrite)
*cp.Rules[i2].Services[i4].Filters.URLRewrite = *o.Rules[i2].Services[i4].Filters.URLRewrite *cp.Rules[i2].Services[i4].Filters.URLRewrite = *o.Rules[i2].Services[i4].Filters.URLRewrite
} }
if o.Rules[i2].Services[i4].ResponseFilters.Headers != nil {
cp.Rules[i2].Services[i4].ResponseFilters.Headers = make([]HTTPHeaderFilter, len(o.Rules[i2].Services[i4].ResponseFilters.Headers))
copy(cp.Rules[i2].Services[i4].ResponseFilters.Headers, o.Rules[i2].Services[i4].ResponseFilters.Headers)
for i7 := range o.Rules[i2].Services[i4].ResponseFilters.Headers {
if o.Rules[i2].Services[i4].ResponseFilters.Headers[i7].Add != nil {
cp.Rules[i2].Services[i4].ResponseFilters.Headers[i7].Add = make(map[string]string, len(o.Rules[i2].Services[i4].ResponseFilters.Headers[i7].Add))
for k9, v9 := range o.Rules[i2].Services[i4].ResponseFilters.Headers[i7].Add {
cp.Rules[i2].Services[i4].ResponseFilters.Headers[i7].Add[k9] = v9
}
}
if o.Rules[i2].Services[i4].ResponseFilters.Headers[i7].Remove != nil {
cp.Rules[i2].Services[i4].ResponseFilters.Headers[i7].Remove = make([]string, len(o.Rules[i2].Services[i4].ResponseFilters.Headers[i7].Remove))
copy(cp.Rules[i2].Services[i4].ResponseFilters.Headers[i7].Remove, o.Rules[i2].Services[i4].ResponseFilters.Headers[i7].Remove)
}
if o.Rules[i2].Services[i4].ResponseFilters.Headers[i7].Set != nil {
cp.Rules[i2].Services[i4].ResponseFilters.Headers[i7].Set = make(map[string]string, len(o.Rules[i2].Services[i4].ResponseFilters.Headers[i7].Set))
for k9, v9 := range o.Rules[i2].Services[i4].ResponseFilters.Headers[i7].Set {
cp.Rules[i2].Services[i4].ResponseFilters.Headers[i7].Set[k9] = v9
}
}
}
}
} }
} }
} }

View File

@ -199,12 +199,6 @@ type HTTPFilters struct {
URLRewrite *URLRewrite URLRewrite *URLRewrite
} }
// HTTPResponseFilters specifies a list of filters used to modify a
// response returned by an upstream
type HTTPResponseFilters struct {
Headers []HTTPHeaderFilter
}
// HTTPHeaderFilter specifies how HTTP headers should be modified. // HTTPHeaderFilter specifies how HTTP headers should be modified.
type HTTPHeaderFilter struct { type HTTPHeaderFilter struct {
Add map[string]string Add map[string]string
@ -222,9 +216,6 @@ type HTTPRouteRule struct {
// Filters is a list of HTTP-based filters used to modify a request prior // Filters is a list of HTTP-based filters used to modify a request prior
// to routing it to the upstream service // to routing it to the upstream service
Filters HTTPFilters Filters HTTPFilters
// ResponseFilters is a list of HTTP-based filters used to modify a response
// returned by the upstream service
ResponseFilters HTTPResponseFilters
// Matches specified the matching criteria used in the routing table. If a // Matches specified the matching criteria used in the routing table. If a
// request matches the given HTTPMatch configuration, then traffic is routed // request matches the given HTTPMatch configuration, then traffic is routed
// to services specified in the Services field. // to services specified in the Services field.
@ -240,15 +231,10 @@ type HTTPService struct {
// Weight is an arbitrary integer used in calculating how much // Weight is an arbitrary integer used in calculating how much
// traffic should be sent to the given service. // traffic should be sent to the given service.
Weight int Weight int
// Filters is a list of HTTP-based filters used to modify a request prior // Filters is a list of HTTP-based filters used to modify a request prior
// to routing it to the upstream service // to routing it to the upstream service
Filters HTTPFilters Filters HTTPFilters
// ResponseFilters is a list of HTTP-based filters used to modify the
// response returned from the upstream service
ResponseFilters HTTPResponseFilters
// Partition is the partition the config entry is associated with. // Partition is the partition the config entry is associated with.
// Partitioning is a Consul Enterprise feature. // Partitioning is a Consul Enterprise feature.
Partition string `json:",omitempty"` Partition string `json:",omitempty"`

View File

@ -524,34 +524,6 @@ func HTTPQueryMatchFromStructs(t *structs.HTTPQueryMatch, s *HTTPQueryMatch) {
s.Name = t.Name s.Name = t.Name
s.Value = t.Value s.Value = t.Value
} }
func HTTPResponseFiltersToStructs(s *HTTPResponseFilters, t *structs.HTTPResponseFilters) {
if s == nil {
return
}
{
t.Headers = make([]structs.HTTPHeaderFilter, len(s.Headers))
for i := range s.Headers {
if s.Headers[i] != nil {
HTTPHeaderFilterToStructs(s.Headers[i], &t.Headers[i])
}
}
}
}
func HTTPResponseFiltersFromStructs(t *structs.HTTPResponseFilters, s *HTTPResponseFilters) {
if s == nil {
return
}
{
s.Headers = make([]*HTTPHeaderFilter, len(t.Headers))
for i := range t.Headers {
{
var x HTTPHeaderFilter
HTTPHeaderFilterFromStructs(&t.Headers[i], &x)
s.Headers[i] = &x
}
}
}
}
func HTTPRouteToStructs(s *HTTPRoute, t *structs.HTTPRouteConfigEntry) { func HTTPRouteToStructs(s *HTTPRoute, t *structs.HTTPRouteConfigEntry) {
if s == nil { if s == nil {
return return
@ -617,9 +589,6 @@ func HTTPRouteRuleToStructs(s *HTTPRouteRule, t *structs.HTTPRouteRule) {
if s.Filters != nil { if s.Filters != nil {
HTTPFiltersToStructs(s.Filters, &t.Filters) HTTPFiltersToStructs(s.Filters, &t.Filters)
} }
if s.ResponseFilters != nil {
HTTPResponseFiltersToStructs(s.ResponseFilters, &t.ResponseFilters)
}
{ {
t.Matches = make([]structs.HTTPMatch, len(s.Matches)) t.Matches = make([]structs.HTTPMatch, len(s.Matches))
for i := range s.Matches { for i := range s.Matches {
@ -646,11 +615,6 @@ func HTTPRouteRuleFromStructs(t *structs.HTTPRouteRule, s *HTTPRouteRule) {
HTTPFiltersFromStructs(&t.Filters, &x) HTTPFiltersFromStructs(&t.Filters, &x)
s.Filters = &x s.Filters = &x
} }
{
var x HTTPResponseFilters
HTTPResponseFiltersFromStructs(&t.ResponseFilters, &x)
s.ResponseFilters = &x
}
{ {
s.Matches = make([]*HTTPMatch, len(t.Matches)) s.Matches = make([]*HTTPMatch, len(t.Matches))
for i := range t.Matches { for i := range t.Matches {
@ -681,9 +645,6 @@ func HTTPServiceToStructs(s *HTTPService, t *structs.HTTPService) {
if s.Filters != nil { if s.Filters != nil {
HTTPFiltersToStructs(s.Filters, &t.Filters) HTTPFiltersToStructs(s.Filters, &t.Filters)
} }
if s.ResponseFilters != nil {
HTTPResponseFiltersToStructs(s.ResponseFilters, &t.ResponseFilters)
}
t.EnterpriseMeta = enterpriseMetaToStructs(s.EnterpriseMeta) t.EnterpriseMeta = enterpriseMetaToStructs(s.EnterpriseMeta)
} }
func HTTPServiceFromStructs(t *structs.HTTPService, s *HTTPService) { func HTTPServiceFromStructs(t *structs.HTTPService, s *HTTPService) {
@ -697,11 +658,6 @@ func HTTPServiceFromStructs(t *structs.HTTPService, s *HTTPService) {
HTTPFiltersFromStructs(&t.Filters, &x) HTTPFiltersFromStructs(&t.Filters, &x)
s.Filters = &x s.Filters = &x
} }
{
var x HTTPResponseFilters
HTTPResponseFiltersFromStructs(&t.ResponseFilters, &x)
s.ResponseFilters = &x
}
s.EnterpriseMeta = enterpriseMetaFromStructs(t.EnterpriseMeta) s.EnterpriseMeta = enterpriseMetaFromStructs(t.EnterpriseMeta)
} }
func HashPolicyToStructs(s *HashPolicy, t *structs.HashPolicy) { func HashPolicyToStructs(s *HashPolicy, t *structs.HashPolicy) {

View File

@ -617,16 +617,6 @@ func (msg *HTTPFilters) UnmarshalBinary(b []byte) error {
return proto.Unmarshal(b, msg) return proto.Unmarshal(b, msg)
} }
// MarshalBinary implements encoding.BinaryMarshaler
func (msg *HTTPResponseFilters) MarshalBinary() ([]byte, error) {
return proto.Marshal(msg)
}
// UnmarshalBinary implements encoding.BinaryUnmarshaler
func (msg *HTTPResponseFilters) UnmarshalBinary(b []byte) error {
return proto.Unmarshal(b, msg)
}
// MarshalBinary implements encoding.BinaryMarshaler // MarshalBinary implements encoding.BinaryMarshaler
func (msg *URLRewrite) MarshalBinary() ([]byte, error) { func (msg *URLRewrite) MarshalBinary() ([]byte, error) {
return proto.Marshal(msg) return proto.Marshal(msg)

File diff suppressed because it is too large Load Diff

View File

@ -793,7 +793,6 @@ message HTTPRouteRule {
HTTPFilters Filters = 1; HTTPFilters Filters = 1;
repeated HTTPMatch Matches = 2; repeated HTTPMatch Matches = 2;
repeated HTTPService Services = 3; repeated HTTPService Services = 3;
HTTPResponseFilters ResponseFilters = 4;
} }
// mog annotation: // mog annotation:
@ -887,15 +886,6 @@ message HTTPFilters {
URLRewrite URLRewrite = 2; URLRewrite URLRewrite = 2;
} }
// mog annotation:
//
// target=github.com/hashicorp/consul/agent/structs.HTTPResponseFilters
// output=config_entry.gen.go
// name=Structs
message HTTPResponseFilters {
repeated HTTPHeaderFilter Headers = 1;
}
// mog annotation: // mog annotation:
// //
// target=github.com/hashicorp/consul/agent/structs.URLRewrite // target=github.com/hashicorp/consul/agent/structs.URLRewrite
@ -928,7 +918,6 @@ message HTTPService {
HTTPFilters Filters = 3; HTTPFilters Filters = 3;
// mog: func-to=enterpriseMetaToStructs func-from=enterpriseMetaFromStructs // mog: func-to=enterpriseMetaToStructs func-from=enterpriseMetaFromStructs
common.EnterpriseMeta EnterpriseMeta = 4; common.EnterpriseMeta EnterpriseMeta = 4;
HTTPResponseFilters ResponseFilters = 5;
} }
// mog annotation: // mog annotation:

View File

@ -224,7 +224,6 @@ func checkTCPRouteConfigEntry(t *testing.T, client *api.Client, routeName string
type checkOptions struct { type checkOptions struct {
debug bool debug bool
responseHeaders map[string]string
statusCode int statusCode int
testName string testName string
} }
@ -275,14 +274,6 @@ func checkRoute(t *testing.T, port int, path string, headers map[string]string,
t.Logf("bad status code - expected: %d, actual: %d", expected.statusCode, res.StatusCode) t.Logf("bad status code - expected: %d, actual: %d", expected.statusCode, res.StatusCode)
return false return false
} }
for name, value := range expected.responseHeaders {
if res.Header.Get(name) != value {
t.Logf("response missing header - expected: %s=%s, actual: %s=%s", name, value, name, res.Header.Get(name))
return false
}
}
if expected.debug { if expected.debug {
if !strings.Contains(string(body), "debug") { if !strings.Contains(string(body), "debug") {
t.Log("body does not contain 'debug'") t.Log("body does not contain 'debug'")

View File

@ -268,7 +268,7 @@ func TestHTTPRouteFlattening(t *testing.T) {
}, checkOptions{debug: false, statusCode: serviceOneResponseCode, testName: "service1, v2 path with v2 hostname"}) }, checkOptions{debug: false, statusCode: serviceOneResponseCode, testName: "service1, v2 path with v2 hostname"})
} }
func TestHTTPRouteFilters(t *testing.T) { func TestHTTPRoutePathRewrite(t *testing.T) {
if testing.Short() { if testing.Short() {
t.Skip("too slow for testing.Short") t.Skip("too slow for testing.Short")
} }
@ -393,12 +393,6 @@ func TestHTTPRouteFilters(t *testing.T) {
Path: fooPath, Path: fooPath,
}, },
}, },
ResponseFilters: api.HTTPResponseFilters{
Headers: []api.HTTPHeaderFilter{{
Add: map[string]string{"response-filters-add": "present"},
Set: map[string]string{"response-filters-set": "present"},
}},
},
Services: []api.HTTPService{ Services: []api.HTTPService{
{ {
Name: fooName, Name: fooName,
@ -484,23 +478,13 @@ func TestHTTPRouteFilters(t *testing.T) {
debugExpectedStatusCode := 200 debugExpectedStatusCode := 200
// hit foo, making sure path is being rewritten by hitting the debug page // hit foo, making sure path is being rewritten by hitting the debug page
// and that we get the expected response headers that we added modifiers for checkRoute(t, gatewayPort, fooUnrewritten, map[string]string{
checkRoute( "Host": "test.foo",
t, gatewayPort, fooUnrewritten, map[string]string{"Host": "test.foo"}, }, checkOptions{debug: true, statusCode: debugExpectedStatusCode, testName: "foo service"})
checkOptions{
debug: true,
responseHeaders: map[string]string{"response-filters-add": "present", "response-filters-set": "present"},
statusCode: debugExpectedStatusCode,
testName: "foo service"})
// make sure foo is being sent to proper service // make sure foo is being sent to proper service
// and that we get the expected response headers that we added modifiers for checkRoute(t, gatewayPort, fooUnrewritten+"/foo", map[string]string{
checkRoute( "Host": "test.foo",
t, gatewayPort, fooUnrewritten+"/foo", map[string]string{"Host": "test.foo"}, }, checkOptions{debug: false, statusCode: fooStatusCode, testName: "foo service 2"})
checkOptions{
debug: false,
responseHeaders: map[string]string{"response-filters-add": "present", "response-filters-set": "present"},
statusCode: fooStatusCode,
testName: "foo service 2"})
// hit bar, making sure its been rewritten // hit bar, making sure its been rewritten
checkRoute(t, gatewayPort, barUnrewritten, map[string]string{ checkRoute(t, gatewayPort, barUnrewritten, map[string]string{