You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-dev@lucene.apache.org by Yonik Seeley <ys...@gmail.com> on 2006/07/12 21:39:22 UTC

setting appropriate content-type

So, right now, the Solr servlet always sets a content type of
"text/xml;charset=UTF-8" before getting the Writer to write the
response.

Now that we have other response writers (like JSON) it seems like they
need a say over what the content-type is.... so the new servlet code
would look something like this:

        QueryResponseWriter responseWriter =
core.getQueryResponseWriter(solrReq);
        response.setContentType(
responseWriter.getContentType(solrReq, solrRsp) );
        PrintWriter out = response.getWriter();
        responseWriter.write(out, solrReq, solrRsp);

So the new method is QueryResponseWriter.getContentType():String, and
I also pass the request and response so content-type could change
based on either of those.

Make sense?  Any other suggestions?

-Yonik

Re: setting appropriate content-type

Posted by Bill Au <bi...@gmail.com>.
Make sense to me too.

Bill

On 7/13/06, Chris Hostetter <ho...@fucit.org> wrote:
>
>
> :         response.setContentType(
> : responseWriter.getContentType(solrReq, solrRsp) );
>
> +1
>
>
>
> -Hoss
>
>

Re: setting appropriate content-type

Posted by Chris Hostetter <ho...@fucit.org>.
:         response.setContentType(
: responseWriter.getContentType(solrReq, solrRsp) );

+1



-Hoss


Re: setting appropriate content-type

Posted by Yoav Shapira <yo...@apache.org>.
Hi,

On 7/12/06, Yonik Seeley <ys...@gmail.com> wrote:
> So, right now, the Solr servlet always sets a content type of
> "text/xml;charset=UTF-8" before getting the Writer to write the
> response.
<snip />
> So the new method is QueryResponseWriter.getContentType():String, and
> I also pass the request and response so content-type could change
> based on either of those.
>
> Make sense?  Any other suggestions?

Makes sense, no problem there.  Just a minor / side comment: you
should check that the response is not committed before setting the
content type.  That provides better support for filtering, e.g. some
earlier or later Filter in the processing chain to set the response
type.  A lot of sites nowadays, for example, have a Filter that sets
content type on UTF-8 for everything.  It's a nice way to do content
type in a universal manner without modifying every single servlet.

As I said, just a side comment, tangential to your approach here,
which I think is fine.

Yoav