# Custom Header not getting added in traefik proxy

**URL:** <https://community.traefik.io/t/custom-header-not-getting-added-in-traefik-proxy/19676>\
**Category:** Traefik v2\
**Tags:** middleware\
**Created:** [August 30, 2023, 6:56am UTC](https://community.traefik.io/t/custom-header-not-getting-added-in-traefik-proxy/19676 "2023-08-30T06:56:15Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![premkagrani](https://avatars.discourse-cdn.com/v4/letter/p/fbc32d/32.png) [@premkagrani](https://community.traefik.io/u/premkagrani)\
**Post date:** [August 30, 2023, 6:56am UTC](https://community.traefik.io/t/custom-header-not-getting-added-in-traefik-proxy/19676/1 "2023-08-30T06:56:16Z")

</div>

Custom headers are not getting added in traefik proxy due to which AWS load balancer rule is not working as expected when i add a rule for http header.

```auto
http:
  routers:
    rate-service-route:
      rule: "PathPrefix(`/rate-service/{path:.*}`)"
      service: rate
      entryPoints:
        - port9090
      priority: 60
      middlewares:
        - customHeaders
  middlewares:
    customHeaders:
      headers:
        customRequestHeaders:
          x-service-name: rate
  services:
    rate:
      loadBalancer:
        servers:
          - url: http://test-route.xyz.com

```

---

<div class="post-metadata">

**Author:** ![bluepuma77](https://avatars.discourse-cdn.com/v4/letter/b/a9adbd/32.png) [@bluepuma77](https://community.traefik.io/u/bluepuma77)\
**Post date:** [August 30, 2023, 7:29am UTC](https://community.traefik.io/t/custom-header-not-getting-added-in-traefik-proxy/19676/2 "2023-08-30T07:29:15Z")

</div>

Share your full Traefik static and dynamic config, and `docker-compose.yml` if used.

Format your code with 3 backticks in front and after, or select the code and press `</>` . In yaml every space matters. And it makes it so much more readable for people trying to help you.

---

<div class="post-metadata">

**Author:** ![premkagrani](https://avatars.discourse-cdn.com/v4/letter/p/fbc32d/32.png) [@premkagrani](https://community.traefik.io/u/premkagrani)\
**Post date:** [August 30, 2023, 7:37am UTC](https://community.traefik.io/t/custom-header-not-getting-added-in-traefik-proxy/19676/3 "2023-08-30T07:37:09Z")

</div>

hey @bluepuma77 , i found the issue, apparently when i use x-service-name in all small cases the header is not getting passed, i changed to X-Service-Name and it is working as expected.

```auto
http:
  routers:
    rate-service-route:
      rule: "PathPrefix(`/rate-service/{path:.*}`)"
      service: rate
      entryPoints:
        - port9090
      priority: 60
      middlewares:
        - customHeaders
  middlewares:
    customHeaders:
      headers:
        customRequestHeaders:
          X-Service-Name: rate
  services:
    rate:
      loadBalancer:
        servers:
          - url: http://test-route.xyz.com

```

Do you know the reason why this would happen?

---

<div class="post-metadata">

**Author:** ![premkagrani](https://avatars.discourse-cdn.com/v4/letter/p/fbc32d/32.png) [@premkagrani](https://community.traefik.io/u/premkagrani)\
**Post date:** [August 30, 2023, 8:16am UTC](https://community.traefik.io/t/custom-header-not-getting-added-in-traefik-proxy/19676/4 "2023-08-30T08:16:50Z")

</div>

Hey sorry for the above text, this is a bit intermittent, it is not working now.  
Can you check what is the issue here.

---

<div class="post-metadata">

**Author:** ![bluepuma77](https://avatars.discourse-cdn.com/v4/letter/b/a9adbd/32.png) [@bluepuma77](https://community.traefik.io/u/bluepuma77)\
**Post date:** [August 30, 2023, 9:29am UTC](https://community.traefik.io/t/custom-header-not-getting-added-in-traefik-proxy/19676/5 "2023-08-30T09:29:45Z")

</div>

According to [doc](https://doc.traefik.io/traefik/middlewares/http/headers/) it should look like this:

```auto
http:
  middlewares:
    testHeader:
      headers:
        customRequestHeaders:
          X-Script-Name: "test"

```

And you need to assign the middleware by name to the router.

Just tested, works for me, [whoami](https://github.com/traefik/whoami) shows `X-Script-Name: test`.

---

<div class="post-metadata">

**Author:** ![premkagrani](https://avatars.discourse-cdn.com/v4/letter/p/fbc32d/32.png) [@premkagrani](https://community.traefik.io/u/premkagrani)\
**Post date:** [August 30, 2023, 9:56am UTC](https://community.traefik.io/t/custom-header-not-getting-added-in-traefik-proxy/19676/6 "2023-08-30T09:56:29Z")

</div>

> [@bluepuma77](#):
>
> Just tested, works for me, [whoami](https://github.com/traefik/whoami) shows `X-Script-Name: test`.

Works for me now, i had multiple route files and after making changes in all, it stopped working, the issue was i had kept the middleware name as same in all and it was causing this issue.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex020/uploads/containo/original/2X/b/bd81ebdb578656e76e56ff3cc3eed021d3ba132d.png) [@system](https://community.traefik.io/u/system)\
**Post date:** [September 2, 2023, 9:57am UTC](https://community.traefik.io/t/custom-header-not-getting-added-in-traefik-proxy/19676/7 "2023-09-02T09:57:05Z")

</div>

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.
