Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reusable proxies #561

Merged
merged 20 commits into from
Aug 31, 2022
Merged
15 changes: 15 additions & 0 deletions config/configload/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,21 @@ func mergeServers(bodies []*hclsyntax.Body, proxies map[string]*hclsyntax.Block)
return nil, newMergeError(errUniqueLabels, subBlock)
}

if attr, ok := subBlock.Body.Attributes[proxy]; ok {
johakoch marked this conversation as resolved.
Show resolved Hide resolved
reference, err := attrStringValue(attr)
if err != nil {
return nil, err
}

delete(subBlock.Body.Attributes, proxy)

if proxyBlock, ok := proxies[reference]; !ok {
return nil, newMergeError(errMissingReferencedProxy, subBlock)
} else {
subBlock.Body.Blocks = append(subBlock.Body.Blocks, proxyBlock)
}
}

results[serverKey].apis[apiKey].endpoints[subBlock.Labels[0]] = subBlock
} else if subBlock.Type == errorHandler {
if err := absInBackends(subBlock); err != nil {
Expand Down
3 changes: 3 additions & 0 deletions server/http_endpoints_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -979,6 +979,9 @@ func TestEndpoint_ReusableProxies(t *testing.T) {
{"/abcdef", "abcdef", 204},
{"/reuse", "abcdef", 204},
{"/default", "default", 204},
{"/api-abcdef", "abcdef", 204},
{"/api-reuse", "abcdef", 204},
{"/api-default", "default", 204},
} {
t.Run(tc.path, func(st *testing.T) {
h := test.New(st)
Expand Down
22 changes: 22 additions & 0 deletions server/testdata/endpoints/18_couper.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,28 @@ server "couper" {
status = 204
}
}

api {
endpoint "/api-abcdef" {
proxy = "test"
response {
status = 204
}
}
endpoint "/api-reuse" {
proxy = "test"
response {
status = 204
}
}

endpoint "/api-default" {
proxy = "defaultName"
response {
johakoch marked this conversation as resolved.
Show resolved Hide resolved
status = 204
}
}
}
}

definitions {
Expand Down