<p>Using the v1.7.9 in kubernetes I'm facing this issue:</p>

<p>if I set a rate limit (<code>traefik.ingress.kubernetes.io/rate-limit</code>) and custom response headers (<code>traefik.ingress.kubernetes.io/custom-response-headers</code>) then when a request gets rate limited, the custom headers won't be set. I guess it's because of some ordering/priority among these plugins. And I totally agree that reaching the rate-limit should return the response as soon as is possible, but it would be nice, if we could modify the priorities if we need.</p>

<p>The question therefore is: <strong>will we be able to set priorities for the middlewares?</strong></p>

<p>I couldn't find any clue of it <a href="https://docs.traefik.io/v2.0/providers/kubernetes-crd/#middleware" rel="nofollow noreferrer">in the docs</a> nor among the github issues.</p>

<p>Concrete use-case:</p>

<p>I want CORS-policy headers to always be set, even if the rate-limiting kicked in. I want this because my SPA won't get the response object otherwise, because the browser won't allow it:</p>

<pre><code>Access to XMLHttpRequest at 'https://api.example.com/api/v1/resource' from origin 'https://cors.exmaple.com' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
</code></pre>

<p>In this case it would be a fine solution if i could just set the priority of the <a href="https://docs.traefik.io/v2.0/middlewares/headers/" rel="nofollow noreferrer">headers middleware</a> higher than the <a href="https://docs.traefik.io/v2.0/middlewares/ratelimit/" rel="nofollow noreferrer">rate limit middleware</a>.</p>

<p>For future reference, a working example that demonstrates such an ordering is here:</p>

<pre><code>apiVersion: traefik.containo.us/v1alpha1
kind: Middleware
metadata:
  name: ratelimit
spec:
  rateLimit:
      average: 100
      burst: 50
---
apiVersion: traefik.containo.us/v1alpha1
kind: Middleware
metadata:
  name: response-header
spec:
  headers:
    customResponseHeaders:
      X-Custom-Response-Header: "value"
---
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
  name: ingressroute
spec:
# more fields...
  routes:
    # more fields...
    middlewares: # the middlewares will be called in this order
    - name: response-header
    - name: ratelimit
</code></pre>

<p>I asked the same question on the Containous' community forum: <a href="https://community.containo.us/t/can-we-set-priority-for-the-middlewares-in-v2/1326" rel="nofollow noreferrer">https://community.containo.us/t/can-we-set-priority-for-the-middlewares-in-v2/1326</a></p>
