Caching Behavior when setting headers in Sling Main Servlet

Avatar

Avatar
Validate 1
Level 2
gkkhatal
Level 2

Likes

6 likes

Total Posts

19 posts

Correct reply

2 solutions
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 1
Affirm 1
View profile

Avatar
Validate 1
Level 2
gkkhatal
Level 2

Likes

6 likes

Total Posts

19 posts

Correct reply

2 solutions
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 1
Affirm 1
View profile
gkkhatal
Level 2

17-11-2018

Hello All

There is an option in Sling Main Servlet to specify HTTP headers through OSGI configs. I am wondering how these headers behave when pages are cached.

  • What is the scenario to use this feature? Especially when we can manage the headers on dispatcher?
  • Are headers are also cached when the pages are cached? If yes, where does the information gets stored on dispatcher webserver?
  • If we store headers on dispatcher which headers will be preferred?

Thanks

Ganesh

Replies

Avatar

Avatar
Coach
Employee
Jörg_Hoh
Employee

Likes

1,136 likes

Total Posts

3,167 posts

Correct reply

1,080 solutions
Top badges earned
Coach
Give back 600
Ignite 5
Ignite 3
Ignite 1
View profile

Avatar
Coach
Employee
Jörg_Hoh
Employee

Likes

1,136 likes

Total Posts

3,167 posts

Correct reply

1,080 solutions
Top badges earned
Coach
Give back 600
Ignite 5
Ignite 3
Ignite 1
View profile
Jörg_Hoh
Employee

18-11-2018

Depending on the type of the header it can make sense to add them on dispatcher. On the other hand there are also usecases where code on the publish instance adds headers which should be delivered to the browser.

By default the dispatcher does not cache headers; but you can enable it (check How to make dispatcher cache response headers , it  requires dispatcher 4.1.11 or newer).

Regarding the case, when you have duplicate settings (both cached and set via Apache config): Good question, haven't tested it. But I would assume that the headers set on the Apache config win.

Jörg

Avatar

Avatar
Validate 1
Level 2
gkkhatal
Level 2

Likes

6 likes

Total Posts

19 posts

Correct reply

2 solutions
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 1
Affirm 1
View profile

Avatar
Validate 1
Level 2
gkkhatal
Level 2

Likes

6 likes

Total Posts

19 posts

Correct reply

2 solutions
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 1
Affirm 1
View profile
gkkhatal
Level 2

18-11-2018

Thanks Jörg for the answer

I am clear with points #2 & #3. That makes sense.

For #1 can you explain bit more in it. You mentioned there might be scenarios in which we may set the headers through code. But that is contradictory to our scenario where we are setting it through OSGI configs.

So it looks there are 3 ways to set the headers(at least) :

1. Through code - Scenario when there is a specific business logic and we need to set through code

2. Through Dispatcher - Most common scenario when headers are set on web server level only when there is no specific business logic

3. Through OSGI configs - Not sure yet. Can you help give a scenario?

Thanks,

Ganesh

Avatar

Avatar
Coach
Employee
Jörg_Hoh
Employee

Likes

1,136 likes

Total Posts

3,167 posts

Correct reply

1,080 solutions
Top badges earned
Coach
Give back 600
Ignite 5
Ignite 3
Ignite 1
View profile

Avatar
Coach
Employee
Jörg_Hoh
Employee

Likes

1,136 likes

Total Posts

3,167 posts

Correct reply

1,080 solutions
Top badges earned
Coach
Give back 600
Ignite 5
Ignite 3
Ignite 1
View profile
Jörg_Hoh
Employee

18-11-2018

I don't see a huge difference between your sceario 1 and 3 🙂 In both cases the headers are added by AEM; either through some kind of configuration and there's code to add this configured data to the response (the Sling Main servlet does that unconditioonally to every response), or you have your own code which does that for you (based on your own requirements, logic and configuration).

Jörg