You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by István <le...@gmail.com> on 2011/05/07 17:24:18 UTC

how to change the default content-type

Hi,

is there an easy way to change the default content type
from  text/plain;charset=utf-8 to application/json somehow?

Regards,
Istvan


-- 
the sun shines for all

Re: how to change the default content-type

Posted by mulderns <fi...@hotmail.com>.
There is a plugin for firefox name "JSONovich" that has an option to send
the application/json accept header to specified hosts - and it displays the
json nicely.



Re: how to change the default content-type

Posted by István <le...@gmail.com>.
This is why it would be good to able to configure the __default__ behavior.


On Sat, May 7, 2011 at 7:54 PM, Benoit Chesneau <bc...@gmail.com> wrote:

> On Sat, May 7, 2011 at 6:12 PM, István <le...@gmail.com> wrote:
> > $ curl -D - -X GET -H "Content-Type: application/json"
> > http://couch.nohup.hu/nohup_urls/c08b5c2c03d31ee767ab891223000d72
> > HTTP/1.1 200 OK
> > Server: nginx/1.0.0
> > Date: Sat, 07 May 2011 16:11:57 GMT
> > Content-Type: text/plain;charset=utf-8
> > Connection: keep-alive
> > Vary: Accept-Encoding
> > Etag: "1-e643d169eb8593e9354012fb7a082605"
> > Content-Length: 209
> > Cache-Control: must-revalidate
> >
> > I would like the change the _default_ behavior to application/json
> >
> > I.
> >
> We are sending json not text.
>



-- 
the sun shines for all

Re: how to change the default content-type

Posted by Benoit Chesneau <bc...@gmail.com>.
On Sat, May 7, 2011 at 6:12 PM, István <le...@gmail.com> wrote:
> $ curl -D - -X GET -H "Content-Type: application/json"
> http://couch.nohup.hu/nohup_urls/c08b5c2c03d31ee767ab891223000d72
> HTTP/1.1 200 OK
> Server: nginx/1.0.0
> Date: Sat, 07 May 2011 16:11:57 GMT
> Content-Type: text/plain;charset=utf-8
> Connection: keep-alive
> Vary: Accept-Encoding
> Etag: "1-e643d169eb8593e9354012fb7a082605"
> Content-Length: 209
> Cache-Control: must-revalidate
>
> I would like the change the _default_ behavior to application/json
>
> I.
>
We are sending json not text.

Re: how to change the default content-type

Posted by Robert Newson <ro...@gmail.com>.
That should read "Sending an 'Accept: application/json' header will
make a browser...".

There's nothing non-compliant or particularly odd about content-type
negotiation. I'd even argue that application/json is the wrong
content-type, a vendor code or a registered mime type of our own,
would be better in standards terms (fwiw). For example, the
Content-Type of a _bulk_docs request cannot be arbitrary JSON, it must
follow some conventions; It is a more specific content-type than
application/json.

I think we can all probably agree that the best practice of a vendor
type like application/vnd.org.couchdb.bulkdocs+json or a registered
type like application/couchdb-bulk-docs is just too ugly to live.

B.

On 9 May 2011 12:01, István <le...@gmail.com> wrote:
> According to couchd documentation[1] this is not the reason why you are
> sending json with text header.
>
> to answer my own question, there is no way at the moment to change the
> default behavior and send app/json in the response header
>
>
> 1. http://guide.couchdb.org/draft/api.html
>
> <http://guide.couchdb.org/draft/design.html>
>
> "The Content-Type header tells you which MIME type the HTTP response body is
> and its encoding. We already know CouchDB returns JSON strings. The
> appropriateContent-Type header is application/json. Why do we see text/plain?
> This is where pragmatism wins over purity. Sending an application/json
> Content-Typeheader will make a browser offer you the returned JSON for
> download instead of just displaying it. Since it is extremely useful to be
> able to test CouchDB from a browser, CouchDB sends a text/plain content
> type, so all browsers will display the JSON as text.
>
> There are some browser extensions that make your browser JSON-aware, but
> they are not installed by default."
>
> On Sun, May 8, 2011 at 11:52 PM, Alexander Shorin <kx...@gmail.com> wrote:
>
>> This is not a problem due to you haven't specified the Accept header
>> and not defined preferable content type.
>> According HTTP specification [1] section 14.1, if there is no
>> acceptable content-type then assume that client supports all media
>> types. AFAIK, http work with mime types based on another specification
>> [2] which tell to return text/plain value as default one. I suppose
>> that you should specify it due to specifications, not usability
>> reasons, that's not difficult(;
>>
>> [1] http://www.ietf.org/rfc/rfc2616.txt
>> [2] http://www.ietf.org/rfc/rfc2045.txt
>>
>> ------------------
>> ,,,^..^,,,
>>
>>
>>
>> On Mon, May 9, 2011 at 2:20 AM, István <le...@gmail.com> wrote:
>> > This is why i asked about the _default_ in my email, I don't want to
>> specify
>> > it with every request.
>> >
>> > This is not even nginx but couchdb. You can try it yourself talking to
>> > couchdb without a reverse proxy.
>> >
>> > On Sat, May 7, 2011 at 5:40 PM, Alexander Shorin <kx...@gmail.com>
>> wrote:
>> >
>> >> Try to pass "Accept: application/json" header instead of
>> >> "Content-Type" which marks type of returned content, not requested.
>> >> Missed Accept headers means all types are expectable and nginx thought
>> >> that text/plain is good one.
>> >>
>> >> ------------------
>> >> ,,,^..^,,,
>> >>
>> >>
>> >>
>> >> On Sat, May 7, 2011 at 8:12 PM, István <le...@gmail.com> wrote:
>> >> > $ curl -D - -X GET -H "Content-Type: application/json"
>> >> > http://couch.nohup.hu/nohup_urls/c08b5c2c03d31ee767ab891223000d72
>> >> > HTTP/1.1 200 OK
>> >> > Server: nginx/1.0.0
>> >> > Date: Sat, 07 May 2011 16:11:57 GMT
>> >> > Content-Type: text/plain;charset=utf-8
>> >> > Connection: keep-alive
>> >> > Vary: Accept-Encoding
>> >> > Etag: "1-e643d169eb8593e9354012fb7a082605"
>> >> > Content-Length: 209
>> >> > Cache-Control: must-revalidate
>> >> >
>> >> > I would like the change the _default_ behavior to application/json
>> >> >
>> >> > I.
>> >> >
>> >> > On Sat, May 7, 2011 at 4:34 PM, Alexander Shorin <kx...@gmail.com>
>> >> wrote:
>> >> >
>> >> >> Is it for show documents? Just return {json: <your-data>} in this
>> case.
>> >> >>
>> >> >> ------------------
>> >> >> ,,,^..^,,,
>> >> >>
>> >> >>
>> >> >>
>> >> >> On Sat, May 7, 2011 at 7:24 PM, István <le...@gmail.com> wrote:
>> >> >> > Hi,
>> >> >> >
>> >> >> > is there an easy way to change the default content type
>> >> >> > from  text/plain;charset=utf-8 to application/json somehow?
>> >> >> >
>> >> >> > Regards,
>> >> >> > Istvan
>> >> >> >
>> >> >> >
>> >> >> > --
>> >> >> > the sun shines for all
>> >> >> >
>> >> >>
>> >> >
>> >> >
>> >> >
>> >> > --
>> >> > the sun shines for all
>> >> >
>> >>
>> >
>> >
>> >
>> > --
>> > the sun shines for all
>> >
>>
>
>
>
> --
> the sun shines for all
>

Re: how to change the default content-type

Posted by István <le...@gmail.com>.
According to couchd documentation[1] this is not the reason why you are
sending json with text header.

to answer my own question, there is no way at the moment to change the
default behavior and send app/json in the response header


1. http://guide.couchdb.org/draft/api.html

<http://guide.couchdb.org/draft/design.html>

"The Content-Type header tells you which MIME type the HTTP response body is
and its encoding. We already know CouchDB returns JSON strings. The
appropriateContent-Type header is application/json. Why do we see text/plain?
This is where pragmatism wins over purity. Sending an application/json
Content-Typeheader will make a browser offer you the returned JSON for
download instead of just displaying it. Since it is extremely useful to be
able to test CouchDB from a browser, CouchDB sends a text/plain content
type, so all browsers will display the JSON as text.

There are some browser extensions that make your browser JSON-aware, but
they are not installed by default."

On Sun, May 8, 2011 at 11:52 PM, Alexander Shorin <kx...@gmail.com> wrote:

> This is not a problem due to you haven't specified the Accept header
> and not defined preferable content type.
> According HTTP specification [1] section 14.1, if there is no
> acceptable content-type then assume that client supports all media
> types. AFAIK, http work with mime types based on another specification
> [2] which tell to return text/plain value as default one. I suppose
> that you should specify it due to specifications, not usability
> reasons, that's not difficult(;
>
> [1] http://www.ietf.org/rfc/rfc2616.txt
> [2] http://www.ietf.org/rfc/rfc2045.txt
>
> ------------------
> ,,,^..^,,,
>
>
>
> On Mon, May 9, 2011 at 2:20 AM, István <le...@gmail.com> wrote:
> > This is why i asked about the _default_ in my email, I don't want to
> specify
> > it with every request.
> >
> > This is not even nginx but couchdb. You can try it yourself talking to
> > couchdb without a reverse proxy.
> >
> > On Sat, May 7, 2011 at 5:40 PM, Alexander Shorin <kx...@gmail.com>
> wrote:
> >
> >> Try to pass "Accept: application/json" header instead of
> >> "Content-Type" which marks type of returned content, not requested.
> >> Missed Accept headers means all types are expectable and nginx thought
> >> that text/plain is good one.
> >>
> >> ------------------
> >> ,,,^..^,,,
> >>
> >>
> >>
> >> On Sat, May 7, 2011 at 8:12 PM, István <le...@gmail.com> wrote:
> >> > $ curl -D - -X GET -H "Content-Type: application/json"
> >> > http://couch.nohup.hu/nohup_urls/c08b5c2c03d31ee767ab891223000d72
> >> > HTTP/1.1 200 OK
> >> > Server: nginx/1.0.0
> >> > Date: Sat, 07 May 2011 16:11:57 GMT
> >> > Content-Type: text/plain;charset=utf-8
> >> > Connection: keep-alive
> >> > Vary: Accept-Encoding
> >> > Etag: "1-e643d169eb8593e9354012fb7a082605"
> >> > Content-Length: 209
> >> > Cache-Control: must-revalidate
> >> >
> >> > I would like the change the _default_ behavior to application/json
> >> >
> >> > I.
> >> >
> >> > On Sat, May 7, 2011 at 4:34 PM, Alexander Shorin <kx...@gmail.com>
> >> wrote:
> >> >
> >> >> Is it for show documents? Just return {json: <your-data>} in this
> case.
> >> >>
> >> >> ------------------
> >> >> ,,,^..^,,,
> >> >>
> >> >>
> >> >>
> >> >> On Sat, May 7, 2011 at 7:24 PM, István <le...@gmail.com> wrote:
> >> >> > Hi,
> >> >> >
> >> >> > is there an easy way to change the default content type
> >> >> > from  text/plain;charset=utf-8 to application/json somehow?
> >> >> >
> >> >> > Regards,
> >> >> > Istvan
> >> >> >
> >> >> >
> >> >> > --
> >> >> > the sun shines for all
> >> >> >
> >> >>
> >> >
> >> >
> >> >
> >> > --
> >> > the sun shines for all
> >> >
> >>
> >
> >
> >
> > --
> > the sun shines for all
> >
>



-- 
the sun shines for all

Re: how to change the default content-type

Posted by Alexander Shorin <kx...@gmail.com>.
This is not a problem due to you haven't specified the Accept header
and not defined preferable content type.
According HTTP specification [1] section 14.1, if there is no
acceptable content-type then assume that client supports all media
types. AFAIK, http work with mime types based on another specification
[2] which tell to return text/plain value as default one. I suppose
that you should specify it due to specifications, not usability
reasons, that's not difficult(;

[1] http://www.ietf.org/rfc/rfc2616.txt
[2] http://www.ietf.org/rfc/rfc2045.txt

------------------
,,,^..^,,,



On Mon, May 9, 2011 at 2:20 AM, István <le...@gmail.com> wrote:
> This is why i asked about the _default_ in my email, I don't want to specify
> it with every request.
>
> This is not even nginx but couchdb. You can try it yourself talking to
> couchdb without a reverse proxy.
>
> On Sat, May 7, 2011 at 5:40 PM, Alexander Shorin <kx...@gmail.com> wrote:
>
>> Try to pass "Accept: application/json" header instead of
>> "Content-Type" which marks type of returned content, not requested.
>> Missed Accept headers means all types are expectable and nginx thought
>> that text/plain is good one.
>>
>> ------------------
>> ,,,^..^,,,
>>
>>
>>
>> On Sat, May 7, 2011 at 8:12 PM, István <le...@gmail.com> wrote:
>> > $ curl -D - -X GET -H "Content-Type: application/json"
>> > http://couch.nohup.hu/nohup_urls/c08b5c2c03d31ee767ab891223000d72
>> > HTTP/1.1 200 OK
>> > Server: nginx/1.0.0
>> > Date: Sat, 07 May 2011 16:11:57 GMT
>> > Content-Type: text/plain;charset=utf-8
>> > Connection: keep-alive
>> > Vary: Accept-Encoding
>> > Etag: "1-e643d169eb8593e9354012fb7a082605"
>> > Content-Length: 209
>> > Cache-Control: must-revalidate
>> >
>> > I would like the change the _default_ behavior to application/json
>> >
>> > I.
>> >
>> > On Sat, May 7, 2011 at 4:34 PM, Alexander Shorin <kx...@gmail.com>
>> wrote:
>> >
>> >> Is it for show documents? Just return {json: <your-data>} in this case.
>> >>
>> >> ------------------
>> >> ,,,^..^,,,
>> >>
>> >>
>> >>
>> >> On Sat, May 7, 2011 at 7:24 PM, István <le...@gmail.com> wrote:
>> >> > Hi,
>> >> >
>> >> > is there an easy way to change the default content type
>> >> > from  text/plain;charset=utf-8 to application/json somehow?
>> >> >
>> >> > Regards,
>> >> > Istvan
>> >> >
>> >> >
>> >> > --
>> >> > the sun shines for all
>> >> >
>> >>
>> >
>> >
>> >
>> > --
>> > the sun shines for all
>> >
>>
>
>
>
> --
> the sun shines for all
>

Re: how to change the default content-type

Posted by István <le...@gmail.com>.
This is why i asked about the _default_ in my email, I don't want to specify
it with every request.

This is not even nginx but couchdb. You can try it yourself talking to
couchdb without a reverse proxy.

On Sat, May 7, 2011 at 5:40 PM, Alexander Shorin <kx...@gmail.com> wrote:

> Try to pass "Accept: application/json" header instead of
> "Content-Type" which marks type of returned content, not requested.
> Missed Accept headers means all types are expectable and nginx thought
> that text/plain is good one.
>
> ------------------
> ,,,^..^,,,
>
>
>
> On Sat, May 7, 2011 at 8:12 PM, István <le...@gmail.com> wrote:
> > $ curl -D - -X GET -H "Content-Type: application/json"
> > http://couch.nohup.hu/nohup_urls/c08b5c2c03d31ee767ab891223000d72
> > HTTP/1.1 200 OK
> > Server: nginx/1.0.0
> > Date: Sat, 07 May 2011 16:11:57 GMT
> > Content-Type: text/plain;charset=utf-8
> > Connection: keep-alive
> > Vary: Accept-Encoding
> > Etag: "1-e643d169eb8593e9354012fb7a082605"
> > Content-Length: 209
> > Cache-Control: must-revalidate
> >
> > I would like the change the _default_ behavior to application/json
> >
> > I.
> >
> > On Sat, May 7, 2011 at 4:34 PM, Alexander Shorin <kx...@gmail.com>
> wrote:
> >
> >> Is it for show documents? Just return {json: <your-data>} in this case.
> >>
> >> ------------------
> >> ,,,^..^,,,
> >>
> >>
> >>
> >> On Sat, May 7, 2011 at 7:24 PM, István <le...@gmail.com> wrote:
> >> > Hi,
> >> >
> >> > is there an easy way to change the default content type
> >> > from  text/plain;charset=utf-8 to application/json somehow?
> >> >
> >> > Regards,
> >> > Istvan
> >> >
> >> >
> >> > --
> >> > the sun shines for all
> >> >
> >>
> >
> >
> >
> > --
> > the sun shines for all
> >
>



-- 
the sun shines for all

Re: how to change the default content-type

Posted by Alexander Shorin <kx...@gmail.com>.
Try to pass "Accept: application/json" header instead of
"Content-Type" which marks type of returned content, not requested.
Missed Accept headers means all types are expectable and nginx thought
that text/plain is good one.

------------------
,,,^..^,,,



On Sat, May 7, 2011 at 8:12 PM, István <le...@gmail.com> wrote:
> $ curl -D - -X GET -H "Content-Type: application/json"
> http://couch.nohup.hu/nohup_urls/c08b5c2c03d31ee767ab891223000d72
> HTTP/1.1 200 OK
> Server: nginx/1.0.0
> Date: Sat, 07 May 2011 16:11:57 GMT
> Content-Type: text/plain;charset=utf-8
> Connection: keep-alive
> Vary: Accept-Encoding
> Etag: "1-e643d169eb8593e9354012fb7a082605"
> Content-Length: 209
> Cache-Control: must-revalidate
>
> I would like the change the _default_ behavior to application/json
>
> I.
>
> On Sat, May 7, 2011 at 4:34 PM, Alexander Shorin <kx...@gmail.com> wrote:
>
>> Is it for show documents? Just return {json: <your-data>} in this case.
>>
>> ------------------
>> ,,,^..^,,,
>>
>>
>>
>> On Sat, May 7, 2011 at 7:24 PM, István <le...@gmail.com> wrote:
>> > Hi,
>> >
>> > is there an easy way to change the default content type
>> > from  text/plain;charset=utf-8 to application/json somehow?
>> >
>> > Regards,
>> > Istvan
>> >
>> >
>> > --
>> > the sun shines for all
>> >
>>
>
>
>
> --
> the sun shines for all
>

Re: how to change the default content-type

Posted by István <le...@gmail.com>.
$ curl -D - -X GET -H "Content-Type: application/json"
http://couch.nohup.hu/nohup_urls/c08b5c2c03d31ee767ab891223000d72
HTTP/1.1 200 OK
Server: nginx/1.0.0
Date: Sat, 07 May 2011 16:11:57 GMT
Content-Type: text/plain;charset=utf-8
Connection: keep-alive
Vary: Accept-Encoding
Etag: "1-e643d169eb8593e9354012fb7a082605"
Content-Length: 209
Cache-Control: must-revalidate

I would like the change the _default_ behavior to application/json

I.

On Sat, May 7, 2011 at 4:34 PM, Alexander Shorin <kx...@gmail.com> wrote:

> Is it for show documents? Just return {json: <your-data>} in this case.
>
> ------------------
> ,,,^..^,,,
>
>
>
> On Sat, May 7, 2011 at 7:24 PM, István <le...@gmail.com> wrote:
> > Hi,
> >
> > is there an easy way to change the default content type
> > from  text/plain;charset=utf-8 to application/json somehow?
> >
> > Regards,
> > Istvan
> >
> >
> > --
> > the sun shines for all
> >
>



-- 
the sun shines for all

Re: how to change the default content-type

Posted by Alexander Shorin <kx...@gmail.com>.
Is it for show documents? Just return {json: <your-data>} in this case.

------------------
,,,^..^,,,



On Sat, May 7, 2011 at 7:24 PM, István <le...@gmail.com> wrote:
> Hi,
>
> is there an easy way to change the default content type
> from  text/plain;charset=utf-8 to application/json somehow?
>
> Regards,
> Istvan
>
>
> --
> the sun shines for all
>