Highlighted

Caching Behavior when setting headers in Sling Main Servlet

Avatar

Avatar

gkkhatal

Avatar

gkkhatal

gkkhatal

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

Highlighted

Avatar

Avatar

Jörg_Hoh

Employee

Total Posts

3.0K

Likes

891

Correct Answer

1.0K

Avatar

Jörg_Hoh

Employee

Total Posts

3.0K

Likes

891

Correct Answer

1.0K
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

Highlighted

Avatar

Avatar

gkkhatal

Avatar

gkkhatal

gkkhatal

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

Highlighted

Avatar

Avatar

Jörg_Hoh

Employee

Total Posts

3.0K

Likes

891

Correct Answer

1.0K

Avatar

Jörg_Hoh

Employee

Total Posts

3.0K

Likes

891

Correct Answer

1.0K
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