# Add to route headers?

**URL:** https://meta.discourse.org/t/add-to-route-headers/111929
**Category:** Support
**Created:** [March 18, 2019, 2:10pm UTC](https://meta.discourse.org/t/add-to-route-headers/111929 "2019-03-18T14:10:34Z")
**Posts on this page:** 16
**Page:** 1

<div class="post-metadata">

### Author: ![Dev\_Work](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dev_work/32/124200_2.png) [@Dev\_Work](https://meta.discourse.org/u/Dev_Work)
#### Post date: [March 18, 2019, 2:10pm UTC](https://meta.discourse.org/t/add-to-route-headers/111929/1 "2019-03-18T14:10:34Z")

</div>

Route site.local/logs/messages.json

Note, that Cache-Control headers are missing in the response headers

Ideally, the web server should return the following HTTP headers in all responses  
containing sensitive content:

- Cache-control: no-store
- Pragma: no-cache

---

<div class="post-metadata">

### Author: ![Timon1507](https://avatars.discourse-cdn.com/v4/letter/t/b487fb/32.png) [@Timon1507](https://meta.discourse.org/u/Timon1507)
#### Post date: [March 19, 2019, 7:01pm UTC](https://meta.discourse.org/t/add-to-route-headers/111929/2 "2019-03-19T19:01:23Z")

</div>

I am also interested in this qiestion

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [March 19, 2019, 7:15pm UTC](https://meta.discourse.org/t/add-to-route-headers/111929/3 "2019-03-19T19:15:12Z")

</div>

That is a library called logster.

You can send a PR to [GitHub - discourse/logster: Log viewer UI and framework for rack · GitHub](https://github.com/discourse/logster)

---

<div class="post-metadata">

### Author: ![Dev\_Work](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dev_work/32/124200_2.png) [@Dev\_Work](https://meta.discourse.org/u/Dev_Work)
#### Post date: [March 19, 2019, 10:41pm UTC](https://meta.discourse.org/t/add-to-route-headers/111929/4 "2019-03-19T22:41:37Z")

</div>

I want to add headers for this route.

 ![001](https://global.discourse-cdn.com/meta/original/3X/e/f/ef182647aaf621ddcb566fc53362b57306e3232a.png)

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [March 19, 2019, 10:46pm UTC](https://meta.discourse.org/t/add-to-route-headers/111929/5 "2019-03-19T22:46:33Z")

</div>

Yes, I got that. The entire `/logs` route is handled by the aforementioned library, so you will have to hack on it.

---

<div class="post-metadata">

### Author: ![Dev\_Work](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dev_work/32/124200_2.png) [@Dev\_Work](https://meta.discourse.org/u/Dev_Work)
#### Post date: [March 19, 2019, 10:48pm UTC](https://meta.discourse.org/t/add-to-route-headers/111929/6 "2019-03-19T22:48:38Z")

</div>

ok thanks 👍💪

---

<div class="post-metadata">

### Author: ![Dev\_Work](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dev_work/32/124200_2.png) [@Dev\_Work](https://meta.discourse.org/u/Dev_Work)
#### Post date: [March 19, 2019, 10:53pm UTC](https://meta.discourse.org/t/add-to-route-headers/111929/7 "2019-03-19T22:53:15Z")

</div>

can i override methods from my custom plugin?

---

<div class="post-metadata">

### Author: ![Dev\_Work](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dev_work/32/124200_2.png) [@Dev\_Work](https://meta.discourse.org/u/Dev_Work)
#### Post date: [March 21, 2019, 12:58am UTC](https://meta.discourse.org/t/add-to-route-headers/111929/8 "2019-03-21T00:58:35Z")

</div>

I think this will help in resolving the issue  
add to nginx  
location /logs/messages.json {  
}

```plaintext
add_header Cache-Control "no-store";
add_header Pragma "no-cache";

```

How to do this through middleware?

```plaintext
req = Rack::Request.new(@env)
    route = req.path_info.to_s
  if (route == '/logs/messages.json')
    #add headers
  end

```

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [March 21, 2019, 1:21am UTC](https://meta.discourse.org/t/add-to-route-headers/111929/9 "2019-03-21T01:21:24Z")

</div>

You could submit a PR to discourse\_docker that added those headers via nginx (note: I have nothing to do with accepting a PR, but this seems reasonable).

---

<div class="post-metadata">

### Author: ![Dev\_Work](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dev_work/32/124200_2.png) [@Dev\_Work](https://meta.discourse.org/u/Dev_Work)
#### Post date: [March 21, 2019, 6:29am UTC](https://meta.discourse.org/t/add-to-route-headers/111929/10 "2019-03-21T06:29:57Z")

</div>

And there is no easy way for example?

# plugin.rb

```plaintext
   Rails.application.config.action_dispatch.default_headers.merge! ({'Cache-Control' => 'no-store'}, 'my_route_name')

```

or

```plaintext
   Rails.application.config.action_dispatch.default_headers.merge! ({'Cache-Control' => 'no-store'}, '/logs/messages.json')

```

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [March 21, 2019, 10:26am UTC](https://meta.discourse.org/t/add-to-route-headers/111929/11 "2019-03-21T10:26:35Z")

</div>

You have already identified the solution. You don’t need a plugin. Adding a few lines to your app.yml is easy and requires no plugin.

See [Serve Discourse from a subfolder (path prefix) instead of a subdomain](https://meta.discourse.org/t/subfolder-support-with-docker/30507) for examples of how to modify the nginx config in the yml file.

---

<div class="post-metadata">

### Author: ![Dev\_Work](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dev_work/32/124200_2.png) [@Dev\_Work](https://meta.discourse.org/u/Dev_Work)
#### Post date: [March 25, 2019, 11:39am UTC](https://meta.discourse.org/t/add-to-route-headers/111929/12 "2019-03-25T11:39:10Z")

</div>

How do I add these settings in app.yml?  
I could not get ☹

---

<div class="post-metadata">

### Author: ![Dev\_Work](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dev_work/32/124200_2.png) [@Dev\_Work](https://meta.discourse.org/u/Dev_Work)
#### Post date: [March 26, 2019, 6:34am UTC](https://meta.discourse.org/t/add-to-route-headers/111929/13 "2019-03-26T06:34:31Z")

</div>

Happened!! 🙂

> [@Add a custom HTTP header to requests made to your Discourse](https://meta.discourse.org/t/how-to-add-a-custom-http-header-to-your-discourse/26439):
>
> Add this to your app.yml: ## Remember, this is YAML syntax - you can only have one block with a name run: - exec: echo "Beginning of custom commands" # A man's not dead while his name is still spoken. - replace: filename: "/etc/nginx/conf.d/discourse.conf" from: /location \/ {/ to: | location / { add\_header X-Clacks-Overhead "GNU Terry Pratchett"; Make sure to rebuild the container afterwards. play_button Terry Pratchett, author of the Discworld novels, …

```plaintext
  - replace:
     filename: "/etc/nginx/conf.d/discourse.conf"
     from: /sendfile on;/
     to: |
       add_header Cache-Control "no-store";
       add_header Pragma "no-cache";
       sendfile on;

```

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [March 26, 2019, 11:21am UTC](https://meta.discourse.org/t/add-to-route-headers/111929/14 "2019-03-26T11:21:46Z")

</div>

Great! Glad you got it!

Hey @falco. Does this seem like something that should be added to the web template?

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [March 26, 2019, 3:17pm UTC](https://meta.discourse.org/t/add-to-route-headers/111929/15 "2019-03-26T15:17:25Z")

</div>

> [@pfaffman](#):
>
> Hey @falco. Does this seem like something that should be added to the web template?

No, that should be handled in the library code.

---

<div class="post-metadata">

### Author: ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)
#### Post date: [May 24, 2022, 8:18am UTC](https://meta.discourse.org/t/add-to-route-headers/111929/17 "2022-05-24T08:18:59Z")

</div>


