You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by Bertrand Delacretaz <bd...@apache.org> on 2008/01/17 14:09:09 UTC

Using X-Sling-Warning headers?

Hi,

I've added this (in revision 612806) to SlingScriptServlet.service(),
to use an X-Sling-Warning HTTP header to indicate an abnormal
non-critical condition:

  final String contentType = request.getResponseContentType();
  if(contentType == null) {
    res.addHeader("X-Sling-Warning",
request.getClass().getSimpleName() + " does not provide a
Content-Type");
    res.setContentType("text/plain");
  } else {
    res.setContentType(contentType);
  }

In such a case (response Content-Type is not as expected), having the
X-Sling-Warning header right next to other headers makes is easy to
spot the problem, when troubleshooting one's app.

What do you think of using such X-Sling-... headers where it makes sense?

-Bertrand

Re: Using X-Sling-Warning headers?

Posted by Bertrand Delacretaz <bd...@apache.org>.
Hi,

> >...having the
> > X-Sling-Warning header right next to other headers makes is easy to
> > spot the problem...

On Jan 17, 2008 3:50 PM, Felix Meschberger <fm...@gmail.com> wrote:
> ...in this case, we probably
> would rather just not do anything if the
> request.getResponseContentType() is not set....

Ok, I've changed the code as you suggest, and removed the
X-Sling-Warning header.

-Bertrand

Re: Using X-Sling-Warning headers?

Posted by Felix Meschberger <fm...@gmail.com>.
Hi,

Am Donnerstag, den 17.01.2008, 14:09 +0100 schrieb Bertrand Delacretaz:
> Hi,
> 
> I've added this (in revision 612806) to SlingScriptServlet.service(),
> to use an X-Sling-Warning HTTP header to indicate an abnormal
> non-critical condition:

This is certainly of value during development. But I think, this (at
least this concrete example) is of little to no use for end users. They
cannot do anything about it any way. I would rather have some logging
entry or so...

> 
>   final String contentType = request.getResponseContentType();
>   if(contentType == null) {
>     res.addHeader("X-Sling-Warning",
> request.getClass().getSimpleName() + " does not provide a
> Content-Type");
>     res.setContentType("text/plain");
>   } else {
>     res.setContentType(contentType);
>   }
> 
> In such a case (response Content-Type is not as expected), having the
> X-Sling-Warning header right next to other headers makes is easy to
> spot the problem, when troubleshooting one's app.

Well, I don't think, this to be a problem, because setting the content
type on behalf of the script may be seen as convenience but also as
tampering with what the script does... So in this case, we probably
would rather just not do anything if the
request.getResponseContentType() is not set.

> What do you think of using such X-Sling-... headers where it makes sense?

I am not really sure, whether it would really help or just be another
place to look at besides the log (and yes, logging must of course be
enhanced !).

Regards
Felix