diff options
| author | WeidiDeng <weidi_deng@icloud.com> | 2023-01-19 05:04:41 +0800 | 
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-01-18 16:04:41 -0500 | 
| commit | c38a040e85a7d277299acaab39bdad171bc45675 (patch) | |
| tree | bc1b7a6f41cc5bfc7be980d159b403d24457420c /caddyconfig/httpcaddyfile/httptype.go | |
| parent | e8ad9b32c9730ddb162b6fb1443fc0b36fcef7dc (diff) | |
httpcaddyfile: Fix `handle` grouping inside `route` (#5315)
Co-authored-by: Francis Lavoie <lavofr@gmail.com>
Diffstat (limited to 'caddyconfig/httpcaddyfile/httptype.go')
| -rw-r--r-- | caddyconfig/httpcaddyfile/httptype.go | 16 | 
1 files changed, 9 insertions, 7 deletions
| diff --git a/caddyconfig/httpcaddyfile/httptype.go b/caddyconfig/httpcaddyfile/httptype.go index 77f990b..00678ef 100644 --- a/caddyconfig/httpcaddyfile/httptype.go +++ b/caddyconfig/httpcaddyfile/httptype.go @@ -618,7 +618,7 @@ func (st *ServerType) serversFromPairings(  			// set up each handler directive, making sure to honor directive order  			dirRoutes := sblock.pile["route"] -			siteSubroute, err := buildSubroute(dirRoutes, groupCounter) +			siteSubroute, err := buildSubroute(dirRoutes, groupCounter, true)  			if err != nil {  				return nil, err  			} @@ -959,14 +959,16 @@ func appendSubrouteToRouteList(routeList caddyhttp.RouteList,  // buildSubroute turns the config values, which are expected to be routes  // into a clean and orderly subroute that has all the routes within it. -func buildSubroute(routes []ConfigValue, groupCounter counter) (*caddyhttp.Subroute, error) { -	for _, val := range routes { -		if !directiveIsOrdered(val.directive) { -			return nil, fmt.Errorf("directive '%s' is not an ordered HTTP handler, so it cannot be used here", val.directive) +func buildSubroute(routes []ConfigValue, groupCounter counter, needsSorting bool) (*caddyhttp.Subroute, error) { +	if needsSorting { +		for _, val := range routes { +			if !directiveIsOrdered(val.directive) { +				return nil, fmt.Errorf("directive '%s' is not an ordered HTTP handler, so it cannot be used here", val.directive) +			}  		} -	} -	sortRoutes(routes) +		sortRoutes(routes) +	}  	subroute := new(caddyhttp.Subroute) | 
