You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by Janez Štupar <ja...@gmail.com> on 2011/01/10 18:21:54 UTC

Strange issue with VHosts and rewrites...

Here is the problem I'm currently dabbling around with Sofa (got it from
jchrisa's Github)... To this end I'm reverse engineering it and trying to
get it work in a following scenario:

The database is hidden behind following VHost: sofa.mycouch  ->
/sofa/_design/sofa/_rewrite

Since I wanted to improve the appearance of the URL's I also did some
modifications to the rewrites, my current configuration is as follows:

[
   {
       "to": "_list/index/recent-posts",
       "from": "blog/",
       "query": {
           "limit": 10,
           "descending": true
       }
   },
   {
       "to": "_list/:listname/*",
       "from": "list/:listname/*",
       "query": {
           "limit": 10,
           "descending": true
       }
   },
   {
        "to" : "_show/:showname/*",
        "from" : "show/:showname/*"
   },
   {
         "to" : "_update/:updatename/*",
         "from" : "update/:updatename/*"
   },
   {
       "to": "_list/index/recent-posts",
       "from": "",
       "query": {
           "limit": 10,
           "descending": true
       }
   },
   {
       "to": "script/*",
       "from": "script/*"
   },
   {
       "to": "style/*",
       "from": "style/*"
   },
   {
       "to": "vendor/*",
       "from": "vendor/*"
   },
   {
    "to": "../../*",
    "from": ":db/*"
   }
]

The last problem I have left is that although everything works (I have
indeed done some modifications to the templates, pathing function, etc..
nothing relevant to this current issue IMHO).
*
Except* one thing doesn't work as expected ... that is posting comments. I
have kinda narrowed it down that when the browser sends a new blog post it
does PUT to address: '"/sofa/_design/sofa/_rewrite/sofa/spet-nov-post"'
(spet-nov-post is a _id - according to jquery.couch.js)

While comment gets POST -ed to following URL:
'"/sofa/_design/sofa/_rewrite/sofa/"'

what happens in the rewriter is following:

'PUT' /sofa/_design/sofa/_rewrite/sofa/spet-nov-post {1,1} -> 'PUT'
/sofa/spet-nov-post?db=sofa {1,1}
'POST' /sofa/_design/sofa/_rewrite/sofa/ {1,1}  -> 'POST'
/sofa/_design/..?db=sofa {1,1}

I blame the following rewrite rule:
   {
    "to": "../../*",
    "from": ":db/*"
   }

What is a mistery to me is why does the first request get rewritten
correctly and the second not? AFAIK the second should come out as: 'POST'
/sofa/?db=sofa {1,1}

Below are the relevant logs -> The first is from new post creation (the PUT
request), the other is from comment creation (the POST request).

*First:
*[Sat, 08 Jan 2011 20:27:40 GMT] [debug] [<0.785.0>] Vhost Target:
'"/sofa/_design/sofa/_rewrite/sofa/spet-nov-post"'


[Sat, 08 Jan 2011 20:27:40 GMT] [debug] [<0.785.0>] 'PUT'
/sofa/_design/sofa/_rewrite/sofa/spet-nov-post {1,1}
Headers: [{'Accept',"application/json, text/javascript, */*"},
          {'Accept-Charset',"UTF-8,*"},
          {'Accept-Encoding',"gzip,deflate"},
          {'Accept-Language',"en,sl;q=0.7,en-us;q=0.3"},
          {'Connection',"keep-alive"},
          {'Content-Length',"169"},
          {'Content-Type',"application/json; charset=UTF-8"},

{'Cookie',"AuthSession=Y291Y2hkYjo0RDI4Qzg3MTqTKp7crPdUFEbZrfJh-EiPaxh2tA"},
          {'Host',"sofa.mycouch"},
          {'Keep-Alive',"115"},
          {'Referer',"http://sofa.mycouch/show/edit/"},
          {'User-Agent',"Mozilla/5.0 (Windows; U; Windows NT 6.1; sl;
rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12 ( .NET CLR 3.5.30729;
.NET4.0C)"},
          {"X-Requested-With","XMLHttpRequest"}]

[Sat, 08 Jan 2011 20:27:40 GMT] [debug] [<0.785.0>] OAuth Params: []

[Sat, 08 Jan 2011 20:27:40 GMT] [debug] [<0.785.0>] timeout 600

[Sat, 08 Jan 2011 20:27:40 GMT] [debug] [<0.785.0>] Successful cookie auth
as: "couchdb"

[Sat, 08 Jan 2011 20:27:40 GMT] [debug] [<0.785.0>] rewrite to
"/sofa/spet-nov-post?db=sofa"


[Sat, 08 Jan 2011 20:27:40 GMT] [debug] [<0.785.0>] 'PUT'
/sofa/spet-nov-post?db=sofa {1,1}
Headers: [{'Accept',"application/json, text/javascript, */*"},
          {'Accept-Charset',"UTF-8,*"},
          {'Accept-Encoding',"gzip,deflate"},
          {'Accept-Language',"en,sl;q=0.7,en-us;q=0.3"},
          {'Connection',"keep-alive"},
          {'Content-Length',"169"},
          {'Content-Type',"application/json; charset=UTF-8"},

{'Cookie',"AuthSession=Y291Y2hkYjo0RDI4Qzg3MTqTKp7crPdUFEbZrfJh-EiPaxh2tA"},
          {'Host',"sofa.mycouch"},
          {'Keep-Alive',"115"},
          {'Referer',"http://sofa.mycouch/show/edit/"},
          {'User-Agent',"Mozilla/5.0 (Windows; U; Windows NT 6.1; sl;
rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12 ( .NET CLR 3.5.30729;
.NET4.0C)"},
          {"X-Requested-With","XMLHttpRequest"}]

[Sat, 08 Jan 2011 20:27:40 GMT] [debug] [<0.785.0>] OAuth Params:
[{"db","sofa"}]

[Sat, 08 Jan 2011 20:27:40 GMT] [debug] [<0.785.0>] timeout 600

[Sat, 08 Jan 2011 20:27:40 GMT] [debug] [<0.785.0>] Successful cookie auth
as: "couchdb"

[Sat, 08 Jan 2011 20:27:40 GMT] [debug] [<0.93.0>] DDocProc found for
DDocKey: {<<"_design/sofa">>,
                             <<"119-09fa3ceca488bfc1852ea48e3a0f0921">>}

[Sat, 08 Jan 2011 20:27:40 GMT] [debug] [<0.630.0>] OS Process #Port<0.1421>
Input  :: ["reset",{"reduce_limit":true}]

[Sat, 08 Jan 2011 20:27:40 GMT] [debug] [<0.630.0>] OS Process #Port<0.1421>
Output :: true


*************************************************************************************

*Second:*
[Sat, 08 Jan 2011 20:27:56 GMT] [debug] [<0.785.0>] Vhost Target:
'"/sofa/_design/sofa/_rewrite/sofa/"'


[Sat, 08 Jan 2011 20:27:56 GMT] [debug] [<0.785.0>] 'POST'
/sofa/_design/sofa/_rewrite/sofa/ {1,1}
Headers: [{'Accept',"application/json, text/javascript, */*"},
          {'Accept-Charset',"UTF-8,*"},
          {'Accept-Encoding',"gzip,deflate"},
          {'Accept-Language',"en,sl;q=0.7,en-us;q=0.3"},
          {'Cache-Control',"no-cache"},
          {'Connection',"keep-alive"},
          {'Content-Length',"361"},
          {'Content-Type',"application/json; charset=UTF-8"},

{'Cookie',"AuthSession=Y291Y2hkYjo0RDI4QzhCQzqLGFFiyeUSKgz9OniE9_g41buHoQ"},
          {'Host',"sofa.mycouch"},
          {'Keep-Alive',"115"},
          {'Pragma',"no-cache"},
          {'Referer',"
http://sofa.mycouch/list/post/post-page?startkey=%5B%22spet-nov-post%22%5D
"},
          {'User-Agent',"Mozilla/5.0 (Windows; U; Windows NT 6.1; sl;
rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12 ( .NET CLR 3.5.30729;
.NET4.0C)"},
          {"X-Requested-With","XMLHttpRequest"}]

[Sat, 08 Jan 2011 20:27:56 GMT] [debug] [<0.785.0>] OAuth Params: []

[Sat, 08 Jan 2011 20:27:56 GMT] [debug] [<0.785.0>] timeout 600

[Sat, 08 Jan 2011 20:27:56 GMT] [debug] [<0.785.0>] Successful cookie auth
as: "couchdb"

[Sat, 08 Jan 2011 20:27:56 GMT] [debug] [<0.785.0>] rewrite to
"/sofa/_design/..?db=sofa"


[Sat, 08 Jan 2011 20:27:56 GMT] [debug] [<0.785.0>] 'POST'
/sofa/_design/..?db=sofa {1,1}
Headers: [{'Accept',"application/json, text/javascript, */*"},
          {'Accept-Charset',"UTF-8,*"},
          {'Accept-Encoding',"gzip,deflate"},
          {'Accept-Language',"en,sl;q=0.7,en-us;q=0.3"},
          {'Cache-Control',"no-cache"},
          {'Connection',"keep-alive"},
          {'Content-Length',"361"},
          {'Content-Type',"application/json; charset=UTF-8"},

{'Cookie',"AuthSession=Y291Y2hkYjo0RDI4QzhCQzqLGFFiyeUSKgz9OniE9_g41buHoQ"},
          {'Host',"sofa.mycouch"},
          {'Keep-Alive',"115"},
          {'Pragma',"no-cache"},
          {'Referer',"
http://sofa.mycouch/list/post/post-page?startkey=%5B%22spet-nov-post%22%5D
"},
          {'User-Agent',"Mozilla/5.0 (Windows; U; Windows NT 6.1; sl;
rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12 ( .NET CLR 3.5.30729;
.NET4.0C)"},
          {"X-Requested-With","XMLHttpRequest"}]

[Sat, 08 Jan 2011 20:27:56 GMT] [debug] [<0.785.0>] OAuth Params:
[{"db","sofa"}]

[Sat, 08 Jan 2011 20:27:56 GMT] [debug] [<0.785.0>] timeout 600

[Sat, 08 Jan 2011 20:27:56 GMT] [debug] [<0.785.0>] Successful cookie auth
as: "couchdb"

[Sat, 08 Jan 2011 20:27:56 GMT] [debug] [<0.785.0>] Minor error in HTTP
request: {bad_ctype,
                                 "Content-Type must be multipart/form-data"}

Re: Strange issue with VHosts and rewrites...

Posted by Janez Štupar <ja...@gmail.com>.
http://www.friendpaste.com/3WC8RhvK2E9Rh2pE03wysn

here you go.

-Janez

On Thu, Jan 13, 2011 at 6:28 PM, Benoit Chesneau <bc...@gmail.com>wrote:

> On Thu, Jan 13, 2011 at 5:16 PM, Janez Štupar <ja...@gmail.com>
> wrote:
> > I'm sorry - my english is usually not this crappy.
> >
> > The error is still there regardless of rewrite configuration. Drop an eye
> on
> > test results and you will see. Also at the end of the mail there are some
> > additional questions I had.
> >
> > -Janez
> >
> > On Thu, Jan 13, 2011 at 4:53 PM, Benoit Chesneau <bchesneau@gmail.com
> >wrote:
> >
> >> On Thu, Jan 13, 2011 at 4:17 PM, Janez Štupar <ja...@gmail.com>
> >> wrote:
> >> > Benoît, I did what you proposed and it behaves exactly as before
> >> >
> >> > Ok i did some testing and this is what I figured out.
> >> >
> >> > This is my testing setup: I created a new database (test) that doesn't
> >> use
> >> > any VHost rules.
> >> >
> >> > Inside it I created a design document that only has rewrites field. I
> >> will
> >> > present test results exactly as per configuration I used.
> >> >
> >> > I always sent the same document contained in file "example" - namely:
> >> > {
> >> >    "type": "comment"
> >> > }
> >> >
> >> > Below are the test results:
> >> >
> >>
> ----------------------------------------------------------------------------------------------------
> >> > ## Test 1:
> >> > # rewrites config:
> >> > [
> >> >   {
> >> >       "to": "../..",
> >> >       "from": ":db"
> >> >   }
> >> > ]
> >> >
> >> > # Executed command 1.1:
> >> > $ curl  -d @example -H "Content-type:application/json" -e
> >> > http://localhost:5984/test  http://localhost:5984/test/
> >> >
> >>
> {"ok":true,"id":"ce8b504d63666c9257cc07537c00aa70","rev":"1-505a221d0aef5d664f29d6afdae01293"}
> >> >
> >> > # Comment: expected result - everything is fine.
> >> >
> >> >
> >> >
> >> > # Executed command 1.2:
> >> > $ curl -X PUT  -d @example -H "Content-type:application/json"
> >> > http://localhost:5984/test/_design/test/_rewrite/test/randomid324324
> >> > {"error":"not_found","reason":"missing"}
> >> >
> >> > # Comment: result expected since there is no ID parameter passed
> through
> >> -
> >> > due to the rewrite rule
> >> >
> >> > #LOG:
> >> > [Mon, 10 Jan 2011 21:42:17 GMT] [debug] [<0.8844.3>] 'PUT'
> >> > /test/_design/test/_rewrite/test/randomid324324 {1,1}
> >> > Headers: [{'Accept',"*/*"},
> >> >          {'Content-Length',"23"},
> >> >          {'Content-Type',"application/json"},
> >> >          {'Host',"localhost:5984"},
> >> >          {'User-Agent',"curl/7.21.0 (i686-pc-linux-gnu) libcurl/7.21.0
> >> > OpenSSL/0.9.8o zlib/1.2.3.4 libidn/1.18"}]
> >> >
> >> > [Mon, 10 Jan 2011 21:42:17 GMT] [debug] [<0.8844.3>] OAuth Params: []
> >> >
> >> > [Mon, 10 Jan 2011 21:42:17 GMT] [debug] [<0.8844.3>] Minor error in
> HTTP
> >> > request: not_found
> >> >
> >> > [Mon, 10 Jan 2011 21:42:17 GMT] [debug] [<0.8844.3>] Stacktrace:
> >> > [{couch_httpd_rewrite,handle_rewrite_req,3},
> >> >             {couch_httpd_db,do_db_req,2},
> >> >             {couch_httpd,handle_request_int,5},
> >> >             {mochiweb_http,headers,5},
> >> >             {proc_lib,init_p_do_apply,3}]
> >> >
> >> > [Mon, 10 Jan 2011 21:42:17 GMT] [info] [<0.8844.3>] 127.0.0.1 - -
> 'PUT'
> >> > /test/_design/test/_rewrite/test/randomid324324 404
> >> >
> >> > [Mon, 10 Jan 2011 21:42:17 GMT] [debug] [<0.8844.3>] httpd 404 error
> >> > response:
> >> >  {"error":"not_found","reason":"missing"}
> >> >
> >> >
> >> >
> >> >
> >> > # Executed command 1.3:
> >> > $curl  -d @example -H "Content-type:application/json" -e
> >> > http://localhost:5984/test
> >> > http://localhost:5984/test/_design/test/_rewrite/test/
> >> > {"error":"bad_content_type","reason":"Content-Type must be
> >> > multipart/form-data"}
> >> >
> >> > # Comment: Rewrite is wrong - also peculiar it won't take
> >> application/json
> >> > content type.
> >> >
> >> > # LOG:
> >> > [Mon, 10 Jan 2011 21:51:55 GMT] [debug] [<0.9453.3>] 'POST'
> >> > /test/_design/test/_rewrite/test/ {1,1}
> >> > Headers: [{'Accept',"*/*"},
> >> >          {'Content-Length',"23"},
> >> >          {'Content-Type',"application/json"},
> >> >          {'Host',"localhost:5984"},
> >> >          {'Referer',"http://localhost:5984/test"},
> >> >          {'User-Agent',"curl/7.21.0 (i686-pc-linux-gnu) libcurl/7.21.0
> >> > OpenSSL/0.9.8o zlib/1.2.3.4 libidn/1.18"}]
> >> >
> >> > [Mon, 10 Jan 2011 21:51:55 GMT] [debug] [<0.9453.3>] OAuth Params: []
> >> >
> >> > [Mon, 10 Jan 2011 21:51:55 GMT] [debug] [<0.9453.3>] rewrite to
> >> > "/test/_design/..?db=test"
> >> >
> >> >
> >> > [Mon, 10 Jan 2011 21:51:55 GMT] [debug] [<0.9453.3>] 'POST'
> >> > /test/_design/..?db=test {1,1}
> >> > Headers: [{'Accept',"*/*"},
> >> >          {'Content-Length',"23"},
> >> >          {'Content-Type',"application/json"},
> >> >          {'Host',"localhost:5984"},
> >> >          {'Referer',"http://localhost:5984/test"},
> >> >          {'User-Agent',"curl/7.21.0 (i686-pc-linux-gnu) libcurl/7.21.0
> >> > OpenSSL/0.9.8o zlib/1.2.3.4 libidn/1.18"}]
> >> >
> >> > [Mon, 10 Jan 2011 21:51:55 GMT] [debug] [<0.9453.3>] OAuth Params:
> >> > [{"db","test"}]
> >> >
> >> > [Mon, 10 Jan 2011 21:51:55 GMT] [debug] [<0.9453.3>] Minor error in
> HTTP
> >> > request: {bad_ctype,
> >> >                                 "Content-Type must be
> >> multipart/form-data"}
> >> >
> >> > [Mon, 10 Jan 2011 21:51:55 GMT] [debug] [<0.9453.3>] Stacktrace:
> >> > [{couch_httpd,validate_ctype,2},
> >> >             {couch_httpd_db,db_doc_req,3},
> >> >             {couch_httpd_db,do_db_req,2},
> >> >             {couch_httpd,handle_request_int,5},
> >> >             {couch_httpd_db,do_db_req,2},
> >> >             {couch_httpd,handle_request_int,5},
> >> >             {mochiweb_http,headers,5},
> >> >             {proc_lib,init_p_do_apply,3}]
> >> >
> >> > [Mon, 10 Jan 2011 21:51:55 GMT] [info] [<0.9453.3>] 127.0.0.1 - -
> 'POST'
> >> > /test/_design/..?db=test 415
> >> >
> >> > [Mon, 10 Jan 2011 21:51:55 GMT] [debug] [<0.9453.3>] httpd 415 error
> >> > response:
> >> >  {"error":"bad_content_type","reason":"Content-Type must be
> >> > multipart/form-data"}
> >> >
> >> >
> >> >
> >> > # Executed command 1.4:
> >> > $ curl  -d @example -H "Content-type:application/json" -e
> >> > http://localhost:5984/test  http://localhost:5984/test/randomid32420
> >> > {"error":"bad_content_type","reason":"Content-Type must be
> >> > multipart/form-data"}
> >> >
> >> > # Comment: I did this one just because - and I noticed that when you
> post
> >> > with and ID - it wont accept JSON content type
> >> >
> >> > # LOG:
> >> > [Mon, 10 Jan 2011 21:54:23 GMT] [debug] [<0.9490.3>] 'POST'
> >> > /test/randomid32420 {1,1}
> >> > Headers: [{'Accept',"*/*"},
> >> >          {'Content-Length',"23"},
> >> >          {'Content-Type',"application/json"},
> >> >          {'Host',"localhost:5984"},
> >> >          {'Referer',"http://localhost:5984/test"},
> >> >          {'User-Agent',"curl/7.21.0 (i686-pc-linux-gnu) libcurl/7.21.0
> >> > OpenSSL/0.9.8o zlib/1.2.3.4 libidn/1.18"}]
> >> >
> >> > [Mon, 10 Jan 2011 21:54:23 GMT] [debug] [<0.9490.3>] OAuth Params: []
> >> >
> >> > [Mon, 10 Jan 2011 21:54:23 GMT] [debug] [<0.9490.3>] Minor error in
> HTTP
> >> > request: {bad_ctype,
> >> >                                 "Content-Type must be
> >> multipart/form-data"}
> >> >
> >> > [Mon, 10 Jan 2011 21:54:23 GMT] [debug] [<0.9490.3>] Stacktrace:
> >> > [{couch_httpd,validate_ctype,2},
> >> >             {couch_httpd_db,db_doc_req,3},
> >> >             {couch_httpd_db,do_db_req,2},
> >> >             {couch_httpd,handle_request_int,5},
> >> >             {mochiweb_http,headers,5},
> >> >             {proc_lib,init_p_do_apply,3}]
> >> >
> >> > [Mon, 10 Jan 2011 21:54:23 GMT] [info] [<0.9490.3>] 127.0.0.1 - -
> 'POST'
> >> > /test/randomid32420 415
> >> >
> >> > [Mon, 10 Jan 2011 21:54:23 GMT] [debug] [<0.9490.3>] httpd 415 error
> >> > response:
> >> >  {"error":"bad_content_type","reason":"Content-Type must be
> >> > multipart/form-data"}
> >> >
> >> >
> >> >
> >> >
> >>
> ----------------------------------------------------------------------------------------------------
> >> >
> >> >
> >> > ## Test 2:
> >> >
> >> > # Rewrites config:
> >> > [
> >> >   {
> >> >       "to": "../../*",
> >> >       "from": ":db/*"
> >> >   }
> >> > ]
> >> >
> >> > # Executed command 2.1:
> >> > $ curl  -d @example -H "Content-type:application/json" -e
> >> > http://localhost:5984/test  http://localhost:5984/test/
> >> >
> >>
> {"ok":true,"id":"ce8b504d63666c9257cc07537c00af99","rev":"1-505a221d0aef5d664f29d6afdae01293"}
> >> >
> >> > # Comment: OK, everything is fine
> >> >
> >> >
> >> >
> >> > #Executed command 2.2:
> >> > $ curl -X PUT  -d @example -H "Content-type:application/json"
> >> > http://localhost:5984/test/_design/test/_rewrite/test/randomid3125
> >> >
> >>
> {"ok":true,"id":"randomid3125","rev":"1-505a221d0aef5d664f29d6afdae01293"}
> >> >
> >> > # Comment: OK, everything is fine - since now rewrite rule
> appropriately
> >> > handles the ID.
> >> >
> >> >
> >> > #Executed command 2.3:
> >> > $ curl  -d @example -H "Content-type:application/json" -e
> >> > http://localhost:5984/test
> >> > http://localhost:5984/test/_design/test/_rewrite/test/
> >> > {"error":"bad_content_type","reason":"Content-Type must be
> >> > multipart/form-data"}
> >> >
> >> > # Comment: Routing and content type are wrong (routing in PUT request
> -
> >> > command 2.2 was done right!)
> >> >
> >> > # LOG:
> >> > [Mon, 10 Jan 2011 22:06:17 GMT] [debug] [<0.10262.3>] 'POST'
> >> > /test/_design/test/_rewrite/test/ {1,1}
> >> > Headers: [{'Accept',"*/*"},
> >> >          {'Content-Length',"23"},
> >> >          {'Content-Type',"application/json"},
> >> >          {'Host',"localhost:5984"},
> >> >          {'Referer',"http://localhost:5984/test"},
> >> >          {'User-Agent',"curl/7.21.0 (i686-pc-linux-gnu) libcurl/7.21.0
> >> > OpenSSL/0.9.8o zlib/1.2.3.4 libidn/1.18"}]
> >> >
> >> > [Mon, 10 Jan 2011 22:06:17 GMT] [debug] [<0.10262.3>] OAuth Params: []
> >> >
> >> > [Mon, 10 Jan 2011 22:06:17 GMT] [debug] [<0.10262.3>] rewrite to
> >> > "/test/_design/..?db=test"
> >> >
> >> >
> >> > [Mon, 10 Jan 2011 22:06:17 GMT] [debug] [<0.10262.3>] 'POST'
> >> > /test/_design/..?db=test {1,1}
> >> > Headers: [{'Accept',"*/*"},
> >> >          {'Content-Length',"23"},
> >> >          {'Content-Type',"application/json"},
> >> >          {'Host',"localhost:5984"},
> >> >          {'Referer',"http://localhost:5984/test"},
> >> >          {'User-Agent',"curl/7.21.0 (i686-pc-linux-gnu) libcurl/7.21.0
> >> > OpenSSL/0.9.8o zlib/1.2.3.4 libidn/1.18"}]
> >> >
> >> > [Mon, 10 Jan 2011 22:06:17 GMT] [debug] [<0.10262.3>] OAuth Params:
> >> > [{"db","test"}]
> >> >
> >> > [Mon, 10 Jan 2011 22:06:17 GMT] [debug] [<0.10262.3>] Minor error in
> HTTP
> >> > request: {bad_ctype,
> >> >                                 "Content-Type must be
> >> multipart/form-data"}
> >> >
> >> > [Mon, 10 Jan 2011 22:06:17 GMT] [debug] [<0.10262.3>] Stacktrace:
> >> > [{couch_httpd,validate_ctype,2},
> >> >             {couch_httpd_db,db_doc_req,3},
> >> >             {couch_httpd_db,do_db_req,2},
> >> >             {couch_httpd,handle_request_int,5},
> >> >             {couch_httpd_db,do_db_req,2},
> >> >             {couch_httpd,handle_request_int,5},
> >> >             {mochiweb_http,headers,5},
> >> >             {proc_lib,init_p_do_apply,3}]
> >> >
> >> > [Mon, 10 Jan 2011 22:06:17 GMT] [info] [<0.10262.3>] 127.0.0.1 - -
> 'POST'
> >> > /test/_design/..?db=test 415
> >> >
> >> > [Mon, 10 Jan 2011 22:06:17 GMT] [debug] [<0.10262.3>] httpd 415 error
> >> > response:
> >> >  {"error":"bad_content_type","reason":"Content-Type must be
> >> > multipart/form-data"}
> >> >
> >> >
> >> > #Executed command 2.4:
> >> > $ curl  -d @example -H "Content-type:application/json" -e
> >> > http://localhost:5984/test  http://localhost:5984/test/randomid32843
> >> > {"error":"bad_content_type","reason":"Content-Type must be
> >> > multipart/form-data"}
> >> >
> >> > #Comment: No routing information in log, got Cotent type error.
> >> >
> >> > #LOG:
> >> > [Mon, 10 Jan 2011 22:11:53 GMT] [debug] [<0.10377.3>] 'POST'
> >> > /test/randomid32843 {1,1}
> >> > Headers: [{'Accept',"*/*"},
> >> >          {'Content-Length',"23"},
> >> >          {'Content-Type',"application/json"},
> >> >          {'Host',"localhost:5984"},
> >> >          {'Referer',"http://localhost:5984/test"},
> >> >          {'User-Agent',"curl/7.21.0 (i686-pc-linux-gnu) libcurl/7.21.0
> >> > OpenSSL/0.9.8o zlib/1.2.3.4 libidn/1.18"}]
> >> >
> >> > [Mon, 10 Jan 2011 22:11:53 GMT] [debug] [<0.10377.3>] OAuth Params: []
> >> >
> >> > [Mon, 10 Jan 2011 22:11:53 GMT] [debug] [<0.10377.3>] Minor error in
> HTTP
> >> > request: {bad_ctype,
> >> >                                 "Content-Type must be
> >> multipart/form-data"}
> >> >
> >> > [Mon, 10 Jan 2011 22:11:53 GMT] [debug] [<0.10377.3>] Stacktrace:
> >> > [{couch_httpd,validate_ctype,2},
> >> >             {couch_httpd_db,db_doc_req,3},
> >> >             {couch_httpd_db,do_db_req,2},
> >> >             {couch_httpd,handle_request_int,5},
> >> >             {mochiweb_http,headers,5},
> >> >             {proc_lib,init_p_do_apply,3}]
> >> >
> >> > [Mon, 10 Jan 2011 22:11:53 GMT] [info] [<0.10377.3>] 127.0.0.1 - -
> 'POST'
> >> > /test/randomid32843 415
> >> >
> >> > [Mon, 10 Jan 2011 22:11:53 GMT] [debug] [<0.10377.3>] httpd 415 error
> >> > response:
> >> >  {"error":"bad_content_type","reason":"Content-Type must be
> >> > multipart/form-data"}
> >> >
> >> >
> >>
> ----------------------------------------------------------------------------------------------------
> >> >
> >> >
> >> > ## Test 3:
> >> >
> >> > # Rewrites config:
> >> > [
> >> >   {
> >> >       "to": "../../*",
> >> >       "from": ":db/*"
> >> >   },
> >> >   {
> >> >       "to": "../..",
> >> >       "from": ":db"
> >> >   }
> >> > ]
> >> >
> >> >
> >> > # Executed command 3.1:
> >> > $ curl  -d @example -H "Content-type:application/json" -e
> >> > http://localhost:5984/test  http://localhost:5984/test/
> >> >
> >>
> {"ok":true,"id":"ce8b504d63666c9257cc07537c00bbe3","rev":"1-505a221d0aef5d664f29d6afdae01293"}
> >> >
> >> > # Comment: OK! works as expected
> >> >
> >> >
> >> >
> >> > #Executed command 3.2:
> >> > $ curl -X PUT  -d @example -H "Content-type:application/json"
> >> > http://localhost:5984/test/_design/test/_rewrite/test/randomid43242
> >> >
> >>
> {"ok":true,"id":"randomid43242","rev":"1-505a221d0aef5d664f29d6afdae01293"}
> >> >
> >> > # Comment: OK! works as expected
> >> >
> >> >
> >> > #Executed command 3.3:
> >> > $ curl  -d @example -H "Content-type:application/json" -e
> >> > http://localhost:5984/test
> >> > http://localhost:5984/test/_design/test/_rewrite/test/
> >> > {"error":"bad_content_type","reason":"Content-Type must be
> >> > multipart/form-data"}
> >> >
> >> > # Comment: Rewrite issue and content type issue
> >> >
> >> > # LOG:
> >> > [Mon, 10 Jan 2011 22:19:55 GMT] [debug] [<0.11199.3>] 'POST'
> >> > /test/_design/test/_rewrite/test/ {1,1}
> >> > Headers: [{'Accept',"*/*"},
> >> >          {'Content-Length',"23"},
> >> >          {'Content-Type',"application/json"},
> >> >          {'Host',"localhost:5984"},
> >> >          {'Referer',"http://localhost:5984/test"},
> >> >          {'User-Agent',"curl/7.21.0 (i686-pc-linux-gnu) libcurl/7.21.0
> >> > OpenSSL/0.9.8o zlib/1.2.3.4 libidn/1.18"}]
> >> >
> >> > [Mon, 10 Jan 2011 22:19:55 GMT] [debug] [<0.11199.3>] OAuth Params: []
> >> >
> >> > [Mon, 10 Jan 2011 22:19:55 GMT] [debug] [<0.11199.3>] rewrite to
> >> > "/test/_design/..?db=test"
> >> >
> >> >
> >> > [Mon, 10 Jan 2011 22:19:55 GMT] [debug] [<0.11199.3>] 'POST'
> >> > /test/_design/..?db=test {1,1}
> >> > Headers: [{'Accept',"*/*"},
> >> >          {'Content-Length',"23"},
> >> >          {'Content-Type',"application/json"},
> >> >          {'Host',"localhost:5984"},
> >> >          {'Referer',"http://localhost:5984/test"},
> >> >          {'User-Agent',"curl/7.21.0 (i686-pc-linux-gnu) libcurl/7.21.0
> >> > OpenSSL/0.9.8o zlib/1.2.3.4 libidn/1.18"}]
> >> >
> >> > [Mon, 10 Jan 2011 22:19:55 GMT] [debug] [<0.11199.3>] OAuth Params:
> >> > [{"db","test"}]
> >> >
> >> > [Mon, 10 Jan 2011 22:19:55 GMT] [debug] [<0.11199.3>] Minor error in
> HTTP
> >> > request: {bad_ctype,
> >> >                                 "Content-Type must be
> >> multipart/form-data"}
> >> >
> >> > [Mon, 10 Jan 2011 22:19:55 GMT] [debug] [<0.11199.3>] Stacktrace:
> >> > [{couch_httpd,validate_ctype,2},
> >> >             {couch_httpd_db,db_doc_req,3},
> >> >             {couch_httpd_db,do_db_req,2},
> >> >             {couch_httpd,handle_request_int,5},
> >> >             {couch_httpd_db,do_db_req,2},
> >> >             {couch_httpd,handle_request_int,5},
> >> >             {mochiweb_http,headers,5},
> >> >             {proc_lib,init_p_do_apply,3}]
> >> >
> >> > [Mon, 10 Jan 2011 22:19:55 GMT] [info] [<0.11199.3>] 127.0.0.1 - -
> 'POST'
> >> > /test/_design/..?db=test 415
> >> >
> >> > [Mon, 10 Jan 2011 22:19:55 GMT] [debug] [<0.11199.3>] httpd 415 error
> >> > response:
> >> >  {"error":"bad_content_type","reason":"Content-Type must be
> >> > multipart/form-data"}
> >> >
> >> >
> >> > #Executed command 3.4:
> >> > $  curl  -d @example -H "Content-type:application/json" -e
> >> > http://localhost:5984/test  http://localhost:5984/test/randomid432432
> >> > {"error":"bad_content_type","reason":"Content-Type must be
> >> > multipart/form-data"}
> >> >
> >> > #Comment: Obviously no rewrite issue, however content type problem is
> >> there
> >> >
> >> > #LOG:
> >> > [Mon, 10 Jan 2011 22:21:24 GMT] [debug] [<0.11220.3>] 'POST'
> >> > /test/randomid432432 {1,1}
> >> > Headers: [{'Accept',"*/*"},
> >> >          {'Content-Length',"23"},
> >> >          {'Content-Type',"application/json"},
> >> >          {'Host',"localhost:5984"},
> >> >          {'Referer',"http://localhost:5984/test"},
> >> >          {'User-Agent',"curl/7.21.0 (i686-pc-linux-gnu) libcurl/7.21.0
> >> > OpenSSL/0.9.8o zlib/1.2.3.4 libidn/1.18"}]
> >> >
> >> > [Mon, 10 Jan 2011 22:21:24 GMT] [debug] [<0.11220.3>] OAuth Params: []
> >> >
> >> > [Mon, 10 Jan 2011 22:21:24 GMT] [debug] [<0.11220.3>] Minor error in
> HTTP
> >> > request: {bad_ctype,
> >> >                                 "Content-Type must be
> >> multipart/form-data"}
> >> >
> >> > [Mon, 10 Jan 2011 22:21:24 GMT] [debug] [<0.11220.3>] Stacktrace:
> >> > [{couch_httpd,validate_ctype,2},
> >> >             {couch_httpd_db,db_doc_req,3},
> >> >             {couch_httpd_db,do_db_req,2},
> >> >             {couch_httpd,handle_request_int,5},
> >> >             {mochiweb_http,headers,5},
> >> >             {proc_lib,init_p_do_apply,3}]
> >> >
> >> > [Mon, 10 Jan 2011 22:21:24 GMT] [info] [<0.11220.3>] 127.0.0.1 - -
> 'POST'
> >> > /test/randomid432432 415
> >> >
> >> > [Mon, 10 Jan 2011 22:21:24 GMT] [debug] [<0.11220.3>] httpd 415 error
> >> > response:
> >> >  {"error":"bad_content_type","reason":"Content-Type must be
> >> > multipart/form-data"}
> >> >
> >> >
> >> >
> >> > Apparently these are two different issues.
> >> >
> >> > First handling of rewrites for POST requests and the second is the
> >> problem
> >> > with Content types?
> >> >
> >> > Also I would be extremely happy to find out what are more exact rules
> for
> >> > pattern matching? I have found this site (
> >> > http://caolanmcmahon.com/on_designs_undocumented.html) which provides
> >> some
> >> > answers. I have also read somewhere that rewriting is basically Erlang
> >> > pattern matching ... so should I read up more about the topic in
> Erlang
> >> > documentation?
> >> >
> >> > There is also a question I have that wasn't answered anywhere - is it
> >> > possible for multiple rewrites to apply to single request? If so what
> is
> >> the
> >> > precedence? If not - what is the precedence in that case.
> >> >
> >> > Thank you for any response.
> >> >
> >> > Kind regards, -Janez
> >> >
> >> > On Thu, Jan 13, 2011 at 8:21 AM, Benoit Chesneau <bchesneau@gmail.com
> >> >wrote:
> >> >
> >> >> did you try to add:
> >> >>
> >> >> {
> >> >>
> >> >> "from": ":db",
> >> >> "to": "../.."
> >> >> }
> >> >>
> >> >> ?
> >> >>
> >> >> - benoît
> >> >>
> >> >> On Mon, Jan 10, 2011 at 6:21 PM, Janez Štupar <
> janez.stupar@gmail.com>
> >> >> wrote:
> >> >> > Here is the problem I'm currently dabbling around with Sofa (got it
> >> from
> >> >> > jchrisa's Github)... To this end I'm reverse engineering it and
> trying
> >> to
> >> >> > get it work in a following scenario:
> >> >> >
> >> >> > The database is hidden behind following VHost: sofa.mycouch  ->
> >> >> > /sofa/_design/sofa/_rewrite
> >> >> >
> >> >> > Since I wanted to improve the appearance of the URL's I also did
> some
> >> >> > modifications to the rewrites, my current configuration is as
> follows:
> >> >> >
> >> >> > [
> >> >> >   {
> >> >> >       "to": "_list/index/recent-posts",
> >> >> >       "from": "blog/",
> >> >> >       "query": {
> >> >> >           "limit": 10,
> >> >> >           "descending": true
> >> >> >       }
> >> >> >   },
> >> >> >   {
> >> >> >       "to": "_list/:listname/*",
> >> >> >       "from": "list/:listname/*",
> >> >> >       "query": {
> >> >> >           "limit": 10,
> >> >> >           "descending": true
> >> >> >       }
> >> >> >   },
> >> >> >   {
> >> >> >        "to" : "_show/:showname/*",
> >> >> >        "from" : "show/:showname/*"
> >> >> >   },
> >> >> >   {
> >> >> >         "to" : "_update/:updatename/*",
> >> >> >         "from" : "update/:updatename/*"
> >> >> >   },
> >> >> >   {
> >> >> >       "to": "_list/index/recent-posts",
> >> >> >       "from": "",
> >> >> >       "query": {
> >> >> >           "limit": 10,
> >> >> >           "descending": true
> >> >> >       }
> >> >> >   },
> >> >> >   {
> >> >> >       "to": "script/*",
> >> >> >       "from": "script/*"
> >> >> >   },
> >> >> >   {
> >> >> >       "to": "style/*",
> >> >> >       "from": "style/*"
> >> >> >   },
> >> >> >   {
> >> >> >       "to": "vendor/*",
> >> >> >       "from": "vendor/*"
> >> >> >   },
> >> >> >   {
> >> >> >    "to": "../../*",
> >> >> >    "from": ":db/*"
> >> >> >   }
> >> >> > ]
> >> >> >
> >> >> > The last problem I have left is that although everything works (I
> have
> >> >> > indeed done some modifications to the templates, pathing function,
> >> etc..
> >> >> > nothing relevant to this current issue IMHO).
> >> >> > *
> >> >> > Except* one thing doesn't work as expected ... that is posting
> >> comments.
> >> >> I
> >> >> > have kinda narrowed it down that when the browser sends a new blog
> >> post
> >> >> it
> >> >> > does PUT to address:
> >> '"/sofa/_design/sofa/_rewrite/sofa/spet-nov-post"'
> >> >> > (spet-nov-post is a _id - according to jquery.couch.js)
> >> >> >
> >> >> > While comment gets POST -ed to following URL:
> >> >> > '"/sofa/_design/sofa/_rewrite/sofa/"'
> >> >> >
> >> >> > what happens in the rewriter is following:
> >> >> >
> >> >> > 'PUT' /sofa/_design/sofa/_rewrite/sofa/spet-nov-post {1,1} -> 'PUT'
> >> >> > /sofa/spet-nov-post?db=sofa {1,1}
> >> >> > 'POST' /sofa/_design/sofa/_rewrite/sofa/ {1,1}  -> 'POST'
> >> >> > /sofa/_design/..?db=sofa {1,1}
> >> >> >
> >> >> > I blame the following rewrite rule:
> >> >> >   {
> >> >> >    "to": "../../*",
> >> >> >    "from": ":db/*"
> >> >> >   }
> >> >> >
> >> >>
> >> >
> >> So using 2 rewrites rules work right ? (That what I suggested). For
> >> content-type This is something expected i think. Will re-read this
> >> separate issue later. Headers are not rewritten anyway.
> >>
> >> - benoît
> >>
> >
> can you post it your rewrites and log somewhere (on friendpaste) for
> eg, and post them here ? Logs aren't really readable on my mua.
>
> - benoit
>

Re: Strange issue with VHosts and rewrites...

Posted by Benoit Chesneau <bc...@gmail.com>.
On Thu, Jan 13, 2011 at 5:16 PM, Janez Štupar <ja...@gmail.com> wrote:
> I'm sorry - my english is usually not this crappy.
>
> The error is still there regardless of rewrite configuration. Drop an eye on
> test results and you will see. Also at the end of the mail there are some
> additional questions I had.
>
> -Janez
>
> On Thu, Jan 13, 2011 at 4:53 PM, Benoit Chesneau <bc...@gmail.com>wrote:
>
>> On Thu, Jan 13, 2011 at 4:17 PM, Janez Štupar <ja...@gmail.com>
>> wrote:
>> > Benoît, I did what you proposed and it behaves exactly as before
>> >
>> > Ok i did some testing and this is what I figured out.
>> >
>> > This is my testing setup: I created a new database (test) that doesn't
>> use
>> > any VHost rules.
>> >
>> > Inside it I created a design document that only has rewrites field. I
>> will
>> > present test results exactly as per configuration I used.
>> >
>> > I always sent the same document contained in file "example" - namely:
>> > {
>> >    "type": "comment"
>> > }
>> >
>> > Below are the test results:
>> >
>> ----------------------------------------------------------------------------------------------------
>> > ## Test 1:
>> > # rewrites config:
>> > [
>> >   {
>> >       "to": "../..",
>> >       "from": ":db"
>> >   }
>> > ]
>> >
>> > # Executed command 1.1:
>> > $ curl  -d @example -H "Content-type:application/json" -e
>> > http://localhost:5984/test  http://localhost:5984/test/
>> >
>> {"ok":true,"id":"ce8b504d63666c9257cc07537c00aa70","rev":"1-505a221d0aef5d664f29d6afdae01293"}
>> >
>> > # Comment: expected result - everything is fine.
>> >
>> >
>> >
>> > # Executed command 1.2:
>> > $ curl -X PUT  -d @example -H "Content-type:application/json"
>> > http://localhost:5984/test/_design/test/_rewrite/test/randomid324324
>> > {"error":"not_found","reason":"missing"}
>> >
>> > # Comment: result expected since there is no ID parameter passed through
>> -
>> > due to the rewrite rule
>> >
>> > #LOG:
>> > [Mon, 10 Jan 2011 21:42:17 GMT] [debug] [<0.8844.3>] 'PUT'
>> > /test/_design/test/_rewrite/test/randomid324324 {1,1}
>> > Headers: [{'Accept',"*/*"},
>> >          {'Content-Length',"23"},
>> >          {'Content-Type',"application/json"},
>> >          {'Host',"localhost:5984"},
>> >          {'User-Agent',"curl/7.21.0 (i686-pc-linux-gnu) libcurl/7.21.0
>> > OpenSSL/0.9.8o zlib/1.2.3.4 libidn/1.18"}]
>> >
>> > [Mon, 10 Jan 2011 21:42:17 GMT] [debug] [<0.8844.3>] OAuth Params: []
>> >
>> > [Mon, 10 Jan 2011 21:42:17 GMT] [debug] [<0.8844.3>] Minor error in HTTP
>> > request: not_found
>> >
>> > [Mon, 10 Jan 2011 21:42:17 GMT] [debug] [<0.8844.3>] Stacktrace:
>> > [{couch_httpd_rewrite,handle_rewrite_req,3},
>> >             {couch_httpd_db,do_db_req,2},
>> >             {couch_httpd,handle_request_int,5},
>> >             {mochiweb_http,headers,5},
>> >             {proc_lib,init_p_do_apply,3}]
>> >
>> > [Mon, 10 Jan 2011 21:42:17 GMT] [info] [<0.8844.3>] 127.0.0.1 - - 'PUT'
>> > /test/_design/test/_rewrite/test/randomid324324 404
>> >
>> > [Mon, 10 Jan 2011 21:42:17 GMT] [debug] [<0.8844.3>] httpd 404 error
>> > response:
>> >  {"error":"not_found","reason":"missing"}
>> >
>> >
>> >
>> >
>> > # Executed command 1.3:
>> > $curl  -d @example -H "Content-type:application/json" -e
>> > http://localhost:5984/test
>> > http://localhost:5984/test/_design/test/_rewrite/test/
>> > {"error":"bad_content_type","reason":"Content-Type must be
>> > multipart/form-data"}
>> >
>> > # Comment: Rewrite is wrong - also peculiar it won't take
>> application/json
>> > content type.
>> >
>> > # LOG:
>> > [Mon, 10 Jan 2011 21:51:55 GMT] [debug] [<0.9453.3>] 'POST'
>> > /test/_design/test/_rewrite/test/ {1,1}
>> > Headers: [{'Accept',"*/*"},
>> >          {'Content-Length',"23"},
>> >          {'Content-Type',"application/json"},
>> >          {'Host',"localhost:5984"},
>> >          {'Referer',"http://localhost:5984/test"},
>> >          {'User-Agent',"curl/7.21.0 (i686-pc-linux-gnu) libcurl/7.21.0
>> > OpenSSL/0.9.8o zlib/1.2.3.4 libidn/1.18"}]
>> >
>> > [Mon, 10 Jan 2011 21:51:55 GMT] [debug] [<0.9453.3>] OAuth Params: []
>> >
>> > [Mon, 10 Jan 2011 21:51:55 GMT] [debug] [<0.9453.3>] rewrite to
>> > "/test/_design/..?db=test"
>> >
>> >
>> > [Mon, 10 Jan 2011 21:51:55 GMT] [debug] [<0.9453.3>] 'POST'
>> > /test/_design/..?db=test {1,1}
>> > Headers: [{'Accept',"*/*"},
>> >          {'Content-Length',"23"},
>> >          {'Content-Type',"application/json"},
>> >          {'Host',"localhost:5984"},
>> >          {'Referer',"http://localhost:5984/test"},
>> >          {'User-Agent',"curl/7.21.0 (i686-pc-linux-gnu) libcurl/7.21.0
>> > OpenSSL/0.9.8o zlib/1.2.3.4 libidn/1.18"}]
>> >
>> > [Mon, 10 Jan 2011 21:51:55 GMT] [debug] [<0.9453.3>] OAuth Params:
>> > [{"db","test"}]
>> >
>> > [Mon, 10 Jan 2011 21:51:55 GMT] [debug] [<0.9453.3>] Minor error in HTTP
>> > request: {bad_ctype,
>> >                                 "Content-Type must be
>> multipart/form-data"}
>> >
>> > [Mon, 10 Jan 2011 21:51:55 GMT] [debug] [<0.9453.3>] Stacktrace:
>> > [{couch_httpd,validate_ctype,2},
>> >             {couch_httpd_db,db_doc_req,3},
>> >             {couch_httpd_db,do_db_req,2},
>> >             {couch_httpd,handle_request_int,5},
>> >             {couch_httpd_db,do_db_req,2},
>> >             {couch_httpd,handle_request_int,5},
>> >             {mochiweb_http,headers,5},
>> >             {proc_lib,init_p_do_apply,3}]
>> >
>> > [Mon, 10 Jan 2011 21:51:55 GMT] [info] [<0.9453.3>] 127.0.0.1 - - 'POST'
>> > /test/_design/..?db=test 415
>> >
>> > [Mon, 10 Jan 2011 21:51:55 GMT] [debug] [<0.9453.3>] httpd 415 error
>> > response:
>> >  {"error":"bad_content_type","reason":"Content-Type must be
>> > multipart/form-data"}
>> >
>> >
>> >
>> > # Executed command 1.4:
>> > $ curl  -d @example -H "Content-type:application/json" -e
>> > http://localhost:5984/test  http://localhost:5984/test/randomid32420
>> > {"error":"bad_content_type","reason":"Content-Type must be
>> > multipart/form-data"}
>> >
>> > # Comment: I did this one just because - and I noticed that when you post
>> > with and ID - it wont accept JSON content type
>> >
>> > # LOG:
>> > [Mon, 10 Jan 2011 21:54:23 GMT] [debug] [<0.9490.3>] 'POST'
>> > /test/randomid32420 {1,1}
>> > Headers: [{'Accept',"*/*"},
>> >          {'Content-Length',"23"},
>> >          {'Content-Type',"application/json"},
>> >          {'Host',"localhost:5984"},
>> >          {'Referer',"http://localhost:5984/test"},
>> >          {'User-Agent',"curl/7.21.0 (i686-pc-linux-gnu) libcurl/7.21.0
>> > OpenSSL/0.9.8o zlib/1.2.3.4 libidn/1.18"}]
>> >
>> > [Mon, 10 Jan 2011 21:54:23 GMT] [debug] [<0.9490.3>] OAuth Params: []
>> >
>> > [Mon, 10 Jan 2011 21:54:23 GMT] [debug] [<0.9490.3>] Minor error in HTTP
>> > request: {bad_ctype,
>> >                                 "Content-Type must be
>> multipart/form-data"}
>> >
>> > [Mon, 10 Jan 2011 21:54:23 GMT] [debug] [<0.9490.3>] Stacktrace:
>> > [{couch_httpd,validate_ctype,2},
>> >             {couch_httpd_db,db_doc_req,3},
>> >             {couch_httpd_db,do_db_req,2},
>> >             {couch_httpd,handle_request_int,5},
>> >             {mochiweb_http,headers,5},
>> >             {proc_lib,init_p_do_apply,3}]
>> >
>> > [Mon, 10 Jan 2011 21:54:23 GMT] [info] [<0.9490.3>] 127.0.0.1 - - 'POST'
>> > /test/randomid32420 415
>> >
>> > [Mon, 10 Jan 2011 21:54:23 GMT] [debug] [<0.9490.3>] httpd 415 error
>> > response:
>> >  {"error":"bad_content_type","reason":"Content-Type must be
>> > multipart/form-data"}
>> >
>> >
>> >
>> >
>> ----------------------------------------------------------------------------------------------------
>> >
>> >
>> > ## Test 2:
>> >
>> > # Rewrites config:
>> > [
>> >   {
>> >       "to": "../../*",
>> >       "from": ":db/*"
>> >   }
>> > ]
>> >
>> > # Executed command 2.1:
>> > $ curl  -d @example -H "Content-type:application/json" -e
>> > http://localhost:5984/test  http://localhost:5984/test/
>> >
>> {"ok":true,"id":"ce8b504d63666c9257cc07537c00af99","rev":"1-505a221d0aef5d664f29d6afdae01293"}
>> >
>> > # Comment: OK, everything is fine
>> >
>> >
>> >
>> > #Executed command 2.2:
>> > $ curl -X PUT  -d @example -H "Content-type:application/json"
>> > http://localhost:5984/test/_design/test/_rewrite/test/randomid3125
>> >
>> {"ok":true,"id":"randomid3125","rev":"1-505a221d0aef5d664f29d6afdae01293"}
>> >
>> > # Comment: OK, everything is fine - since now rewrite rule appropriately
>> > handles the ID.
>> >
>> >
>> > #Executed command 2.3:
>> > $ curl  -d @example -H "Content-type:application/json" -e
>> > http://localhost:5984/test
>> > http://localhost:5984/test/_design/test/_rewrite/test/
>> > {"error":"bad_content_type","reason":"Content-Type must be
>> > multipart/form-data"}
>> >
>> > # Comment: Routing and content type are wrong (routing in PUT request -
>> > command 2.2 was done right!)
>> >
>> > # LOG:
>> > [Mon, 10 Jan 2011 22:06:17 GMT] [debug] [<0.10262.3>] 'POST'
>> > /test/_design/test/_rewrite/test/ {1,1}
>> > Headers: [{'Accept',"*/*"},
>> >          {'Content-Length',"23"},
>> >          {'Content-Type',"application/json"},
>> >          {'Host',"localhost:5984"},
>> >          {'Referer',"http://localhost:5984/test"},
>> >          {'User-Agent',"curl/7.21.0 (i686-pc-linux-gnu) libcurl/7.21.0
>> > OpenSSL/0.9.8o zlib/1.2.3.4 libidn/1.18"}]
>> >
>> > [Mon, 10 Jan 2011 22:06:17 GMT] [debug] [<0.10262.3>] OAuth Params: []
>> >
>> > [Mon, 10 Jan 2011 22:06:17 GMT] [debug] [<0.10262.3>] rewrite to
>> > "/test/_design/..?db=test"
>> >
>> >
>> > [Mon, 10 Jan 2011 22:06:17 GMT] [debug] [<0.10262.3>] 'POST'
>> > /test/_design/..?db=test {1,1}
>> > Headers: [{'Accept',"*/*"},
>> >          {'Content-Length',"23"},
>> >          {'Content-Type',"application/json"},
>> >          {'Host',"localhost:5984"},
>> >          {'Referer',"http://localhost:5984/test"},
>> >          {'User-Agent',"curl/7.21.0 (i686-pc-linux-gnu) libcurl/7.21.0
>> > OpenSSL/0.9.8o zlib/1.2.3.4 libidn/1.18"}]
>> >
>> > [Mon, 10 Jan 2011 22:06:17 GMT] [debug] [<0.10262.3>] OAuth Params:
>> > [{"db","test"}]
>> >
>> > [Mon, 10 Jan 2011 22:06:17 GMT] [debug] [<0.10262.3>] Minor error in HTTP
>> > request: {bad_ctype,
>> >                                 "Content-Type must be
>> multipart/form-data"}
>> >
>> > [Mon, 10 Jan 2011 22:06:17 GMT] [debug] [<0.10262.3>] Stacktrace:
>> > [{couch_httpd,validate_ctype,2},
>> >             {couch_httpd_db,db_doc_req,3},
>> >             {couch_httpd_db,do_db_req,2},
>> >             {couch_httpd,handle_request_int,5},
>> >             {couch_httpd_db,do_db_req,2},
>> >             {couch_httpd,handle_request_int,5},
>> >             {mochiweb_http,headers,5},
>> >             {proc_lib,init_p_do_apply,3}]
>> >
>> > [Mon, 10 Jan 2011 22:06:17 GMT] [info] [<0.10262.3>] 127.0.0.1 - - 'POST'
>> > /test/_design/..?db=test 415
>> >
>> > [Mon, 10 Jan 2011 22:06:17 GMT] [debug] [<0.10262.3>] httpd 415 error
>> > response:
>> >  {"error":"bad_content_type","reason":"Content-Type must be
>> > multipart/form-data"}
>> >
>> >
>> > #Executed command 2.4:
>> > $ curl  -d @example -H "Content-type:application/json" -e
>> > http://localhost:5984/test  http://localhost:5984/test/randomid32843
>> > {"error":"bad_content_type","reason":"Content-Type must be
>> > multipart/form-data"}
>> >
>> > #Comment: No routing information in log, got Cotent type error.
>> >
>> > #LOG:
>> > [Mon, 10 Jan 2011 22:11:53 GMT] [debug] [<0.10377.3>] 'POST'
>> > /test/randomid32843 {1,1}
>> > Headers: [{'Accept',"*/*"},
>> >          {'Content-Length',"23"},
>> >          {'Content-Type',"application/json"},
>> >          {'Host',"localhost:5984"},
>> >          {'Referer',"http://localhost:5984/test"},
>> >          {'User-Agent',"curl/7.21.0 (i686-pc-linux-gnu) libcurl/7.21.0
>> > OpenSSL/0.9.8o zlib/1.2.3.4 libidn/1.18"}]
>> >
>> > [Mon, 10 Jan 2011 22:11:53 GMT] [debug] [<0.10377.3>] OAuth Params: []
>> >
>> > [Mon, 10 Jan 2011 22:11:53 GMT] [debug] [<0.10377.3>] Minor error in HTTP
>> > request: {bad_ctype,
>> >                                 "Content-Type must be
>> multipart/form-data"}
>> >
>> > [Mon, 10 Jan 2011 22:11:53 GMT] [debug] [<0.10377.3>] Stacktrace:
>> > [{couch_httpd,validate_ctype,2},
>> >             {couch_httpd_db,db_doc_req,3},
>> >             {couch_httpd_db,do_db_req,2},
>> >             {couch_httpd,handle_request_int,5},
>> >             {mochiweb_http,headers,5},
>> >             {proc_lib,init_p_do_apply,3}]
>> >
>> > [Mon, 10 Jan 2011 22:11:53 GMT] [info] [<0.10377.3>] 127.0.0.1 - - 'POST'
>> > /test/randomid32843 415
>> >
>> > [Mon, 10 Jan 2011 22:11:53 GMT] [debug] [<0.10377.3>] httpd 415 error
>> > response:
>> >  {"error":"bad_content_type","reason":"Content-Type must be
>> > multipart/form-data"}
>> >
>> >
>> ----------------------------------------------------------------------------------------------------
>> >
>> >
>> > ## Test 3:
>> >
>> > # Rewrites config:
>> > [
>> >   {
>> >       "to": "../../*",
>> >       "from": ":db/*"
>> >   },
>> >   {
>> >       "to": "../..",
>> >       "from": ":db"
>> >   }
>> > ]
>> >
>> >
>> > # Executed command 3.1:
>> > $ curl  -d @example -H "Content-type:application/json" -e
>> > http://localhost:5984/test  http://localhost:5984/test/
>> >
>> {"ok":true,"id":"ce8b504d63666c9257cc07537c00bbe3","rev":"1-505a221d0aef5d664f29d6afdae01293"}
>> >
>> > # Comment: OK! works as expected
>> >
>> >
>> >
>> > #Executed command 3.2:
>> > $ curl -X PUT  -d @example -H "Content-type:application/json"
>> > http://localhost:5984/test/_design/test/_rewrite/test/randomid43242
>> >
>> {"ok":true,"id":"randomid43242","rev":"1-505a221d0aef5d664f29d6afdae01293"}
>> >
>> > # Comment: OK! works as expected
>> >
>> >
>> > #Executed command 3.3:
>> > $ curl  -d @example -H "Content-type:application/json" -e
>> > http://localhost:5984/test
>> > http://localhost:5984/test/_design/test/_rewrite/test/
>> > {"error":"bad_content_type","reason":"Content-Type must be
>> > multipart/form-data"}
>> >
>> > # Comment: Rewrite issue and content type issue
>> >
>> > # LOG:
>> > [Mon, 10 Jan 2011 22:19:55 GMT] [debug] [<0.11199.3>] 'POST'
>> > /test/_design/test/_rewrite/test/ {1,1}
>> > Headers: [{'Accept',"*/*"},
>> >          {'Content-Length',"23"},
>> >          {'Content-Type',"application/json"},
>> >          {'Host',"localhost:5984"},
>> >          {'Referer',"http://localhost:5984/test"},
>> >          {'User-Agent',"curl/7.21.0 (i686-pc-linux-gnu) libcurl/7.21.0
>> > OpenSSL/0.9.8o zlib/1.2.3.4 libidn/1.18"}]
>> >
>> > [Mon, 10 Jan 2011 22:19:55 GMT] [debug] [<0.11199.3>] OAuth Params: []
>> >
>> > [Mon, 10 Jan 2011 22:19:55 GMT] [debug] [<0.11199.3>] rewrite to
>> > "/test/_design/..?db=test"
>> >
>> >
>> > [Mon, 10 Jan 2011 22:19:55 GMT] [debug] [<0.11199.3>] 'POST'
>> > /test/_design/..?db=test {1,1}
>> > Headers: [{'Accept',"*/*"},
>> >          {'Content-Length',"23"},
>> >          {'Content-Type',"application/json"},
>> >          {'Host',"localhost:5984"},
>> >          {'Referer',"http://localhost:5984/test"},
>> >          {'User-Agent',"curl/7.21.0 (i686-pc-linux-gnu) libcurl/7.21.0
>> > OpenSSL/0.9.8o zlib/1.2.3.4 libidn/1.18"}]
>> >
>> > [Mon, 10 Jan 2011 22:19:55 GMT] [debug] [<0.11199.3>] OAuth Params:
>> > [{"db","test"}]
>> >
>> > [Mon, 10 Jan 2011 22:19:55 GMT] [debug] [<0.11199.3>] Minor error in HTTP
>> > request: {bad_ctype,
>> >                                 "Content-Type must be
>> multipart/form-data"}
>> >
>> > [Mon, 10 Jan 2011 22:19:55 GMT] [debug] [<0.11199.3>] Stacktrace:
>> > [{couch_httpd,validate_ctype,2},
>> >             {couch_httpd_db,db_doc_req,3},
>> >             {couch_httpd_db,do_db_req,2},
>> >             {couch_httpd,handle_request_int,5},
>> >             {couch_httpd_db,do_db_req,2},
>> >             {couch_httpd,handle_request_int,5},
>> >             {mochiweb_http,headers,5},
>> >             {proc_lib,init_p_do_apply,3}]
>> >
>> > [Mon, 10 Jan 2011 22:19:55 GMT] [info] [<0.11199.3>] 127.0.0.1 - - 'POST'
>> > /test/_design/..?db=test 415
>> >
>> > [Mon, 10 Jan 2011 22:19:55 GMT] [debug] [<0.11199.3>] httpd 415 error
>> > response:
>> >  {"error":"bad_content_type","reason":"Content-Type must be
>> > multipart/form-data"}
>> >
>> >
>> > #Executed command 3.4:
>> > $  curl  -d @example -H "Content-type:application/json" -e
>> > http://localhost:5984/test  http://localhost:5984/test/randomid432432
>> > {"error":"bad_content_type","reason":"Content-Type must be
>> > multipart/form-data"}
>> >
>> > #Comment: Obviously no rewrite issue, however content type problem is
>> there
>> >
>> > #LOG:
>> > [Mon, 10 Jan 2011 22:21:24 GMT] [debug] [<0.11220.3>] 'POST'
>> > /test/randomid432432 {1,1}
>> > Headers: [{'Accept',"*/*"},
>> >          {'Content-Length',"23"},
>> >          {'Content-Type',"application/json"},
>> >          {'Host',"localhost:5984"},
>> >          {'Referer',"http://localhost:5984/test"},
>> >          {'User-Agent',"curl/7.21.0 (i686-pc-linux-gnu) libcurl/7.21.0
>> > OpenSSL/0.9.8o zlib/1.2.3.4 libidn/1.18"}]
>> >
>> > [Mon, 10 Jan 2011 22:21:24 GMT] [debug] [<0.11220.3>] OAuth Params: []
>> >
>> > [Mon, 10 Jan 2011 22:21:24 GMT] [debug] [<0.11220.3>] Minor error in HTTP
>> > request: {bad_ctype,
>> >                                 "Content-Type must be
>> multipart/form-data"}
>> >
>> > [Mon, 10 Jan 2011 22:21:24 GMT] [debug] [<0.11220.3>] Stacktrace:
>> > [{couch_httpd,validate_ctype,2},
>> >             {couch_httpd_db,db_doc_req,3},
>> >             {couch_httpd_db,do_db_req,2},
>> >             {couch_httpd,handle_request_int,5},
>> >             {mochiweb_http,headers,5},
>> >             {proc_lib,init_p_do_apply,3}]
>> >
>> > [Mon, 10 Jan 2011 22:21:24 GMT] [info] [<0.11220.3>] 127.0.0.1 - - 'POST'
>> > /test/randomid432432 415
>> >
>> > [Mon, 10 Jan 2011 22:21:24 GMT] [debug] [<0.11220.3>] httpd 415 error
>> > response:
>> >  {"error":"bad_content_type","reason":"Content-Type must be
>> > multipart/form-data"}
>> >
>> >
>> >
>> > Apparently these are two different issues.
>> >
>> > First handling of rewrites for POST requests and the second is the
>> problem
>> > with Content types?
>> >
>> > Also I would be extremely happy to find out what are more exact rules for
>> > pattern matching? I have found this site (
>> > http://caolanmcmahon.com/on_designs_undocumented.html) which provides
>> some
>> > answers. I have also read somewhere that rewriting is basically Erlang
>> > pattern matching ... so should I read up more about the topic in Erlang
>> > documentation?
>> >
>> > There is also a question I have that wasn't answered anywhere - is it
>> > possible for multiple rewrites to apply to single request? If so what is
>> the
>> > precedence? If not - what is the precedence in that case.
>> >
>> > Thank you for any response.
>> >
>> > Kind regards, -Janez
>> >
>> > On Thu, Jan 13, 2011 at 8:21 AM, Benoit Chesneau <bchesneau@gmail.com
>> >wrote:
>> >
>> >> did you try to add:
>> >>
>> >> {
>> >>
>> >> "from": ":db",
>> >> "to": "../.."
>> >> }
>> >>
>> >> ?
>> >>
>> >> - benoît
>> >>
>> >> On Mon, Jan 10, 2011 at 6:21 PM, Janez Štupar <ja...@gmail.com>
>> >> wrote:
>> >> > Here is the problem I'm currently dabbling around with Sofa (got it
>> from
>> >> > jchrisa's Github)... To this end I'm reverse engineering it and trying
>> to
>> >> > get it work in a following scenario:
>> >> >
>> >> > The database is hidden behind following VHost: sofa.mycouch  ->
>> >> > /sofa/_design/sofa/_rewrite
>> >> >
>> >> > Since I wanted to improve the appearance of the URL's I also did some
>> >> > modifications to the rewrites, my current configuration is as follows:
>> >> >
>> >> > [
>> >> >   {
>> >> >       "to": "_list/index/recent-posts",
>> >> >       "from": "blog/",
>> >> >       "query": {
>> >> >           "limit": 10,
>> >> >           "descending": true
>> >> >       }
>> >> >   },
>> >> >   {
>> >> >       "to": "_list/:listname/*",
>> >> >       "from": "list/:listname/*",
>> >> >       "query": {
>> >> >           "limit": 10,
>> >> >           "descending": true
>> >> >       }
>> >> >   },
>> >> >   {
>> >> >        "to" : "_show/:showname/*",
>> >> >        "from" : "show/:showname/*"
>> >> >   },
>> >> >   {
>> >> >         "to" : "_update/:updatename/*",
>> >> >         "from" : "update/:updatename/*"
>> >> >   },
>> >> >   {
>> >> >       "to": "_list/index/recent-posts",
>> >> >       "from": "",
>> >> >       "query": {
>> >> >           "limit": 10,
>> >> >           "descending": true
>> >> >       }
>> >> >   },
>> >> >   {
>> >> >       "to": "script/*",
>> >> >       "from": "script/*"
>> >> >   },
>> >> >   {
>> >> >       "to": "style/*",
>> >> >       "from": "style/*"
>> >> >   },
>> >> >   {
>> >> >       "to": "vendor/*",
>> >> >       "from": "vendor/*"
>> >> >   },
>> >> >   {
>> >> >    "to": "../../*",
>> >> >    "from": ":db/*"
>> >> >   }
>> >> > ]
>> >> >
>> >> > The last problem I have left is that although everything works (I have
>> >> > indeed done some modifications to the templates, pathing function,
>> etc..
>> >> > nothing relevant to this current issue IMHO).
>> >> > *
>> >> > Except* one thing doesn't work as expected ... that is posting
>> comments.
>> >> I
>> >> > have kinda narrowed it down that when the browser sends a new blog
>> post
>> >> it
>> >> > does PUT to address:
>> '"/sofa/_design/sofa/_rewrite/sofa/spet-nov-post"'
>> >> > (spet-nov-post is a _id - according to jquery.couch.js)
>> >> >
>> >> > While comment gets POST -ed to following URL:
>> >> > '"/sofa/_design/sofa/_rewrite/sofa/"'
>> >> >
>> >> > what happens in the rewriter is following:
>> >> >
>> >> > 'PUT' /sofa/_design/sofa/_rewrite/sofa/spet-nov-post {1,1} -> 'PUT'
>> >> > /sofa/spet-nov-post?db=sofa {1,1}
>> >> > 'POST' /sofa/_design/sofa/_rewrite/sofa/ {1,1}  -> 'POST'
>> >> > /sofa/_design/..?db=sofa {1,1}
>> >> >
>> >> > I blame the following rewrite rule:
>> >> >   {
>> >> >    "to": "../../*",
>> >> >    "from": ":db/*"
>> >> >   }
>> >> >
>> >>
>> >
>> So using 2 rewrites rules work right ? (That what I suggested). For
>> content-type This is something expected i think. Will re-read this
>> separate issue later. Headers are not rewritten anyway.
>>
>> - benoît
>>
>
can you post it your rewrites and log somewhere (on friendpaste) for
eg, and post them here ? Logs aren't really readable on my mua.

- benoit

Re: Strange issue with VHosts and rewrites...

Posted by Janez Štupar <ja...@gmail.com>.
I'm sorry - my english is usually not this crappy.

The error is still there regardless of rewrite configuration. Drop an eye on
test results and you will see. Also at the end of the mail there are some
additional questions I had.

-Janez

On Thu, Jan 13, 2011 at 4:53 PM, Benoit Chesneau <bc...@gmail.com>wrote:

> On Thu, Jan 13, 2011 at 4:17 PM, Janez Štupar <ja...@gmail.com>
> wrote:
> > Benoît, I did what you proposed and it behaves exactly as before
> >
> > Ok i did some testing and this is what I figured out.
> >
> > This is my testing setup: I created a new database (test) that doesn't
> use
> > any VHost rules.
> >
> > Inside it I created a design document that only has rewrites field. I
> will
> > present test results exactly as per configuration I used.
> >
> > I always sent the same document contained in file "example" - namely:
> > {
> >    "type": "comment"
> > }
> >
> > Below are the test results:
> >
> ----------------------------------------------------------------------------------------------------
> > ## Test 1:
> > # rewrites config:
> > [
> >   {
> >       "to": "../..",
> >       "from": ":db"
> >   }
> > ]
> >
> > # Executed command 1.1:
> > $ curl  -d @example -H "Content-type:application/json" -e
> > http://localhost:5984/test  http://localhost:5984/test/
> >
> {"ok":true,"id":"ce8b504d63666c9257cc07537c00aa70","rev":"1-505a221d0aef5d664f29d6afdae01293"}
> >
> > # Comment: expected result - everything is fine.
> >
> >
> >
> > # Executed command 1.2:
> > $ curl -X PUT  -d @example -H "Content-type:application/json"
> > http://localhost:5984/test/_design/test/_rewrite/test/randomid324324
> > {"error":"not_found","reason":"missing"}
> >
> > # Comment: result expected since there is no ID parameter passed through
> -
> > due to the rewrite rule
> >
> > #LOG:
> > [Mon, 10 Jan 2011 21:42:17 GMT] [debug] [<0.8844.3>] 'PUT'
> > /test/_design/test/_rewrite/test/randomid324324 {1,1}
> > Headers: [{'Accept',"*/*"},
> >          {'Content-Length',"23"},
> >          {'Content-Type',"application/json"},
> >          {'Host',"localhost:5984"},
> >          {'User-Agent',"curl/7.21.0 (i686-pc-linux-gnu) libcurl/7.21.0
> > OpenSSL/0.9.8o zlib/1.2.3.4 libidn/1.18"}]
> >
> > [Mon, 10 Jan 2011 21:42:17 GMT] [debug] [<0.8844.3>] OAuth Params: []
> >
> > [Mon, 10 Jan 2011 21:42:17 GMT] [debug] [<0.8844.3>] Minor error in HTTP
> > request: not_found
> >
> > [Mon, 10 Jan 2011 21:42:17 GMT] [debug] [<0.8844.3>] Stacktrace:
> > [{couch_httpd_rewrite,handle_rewrite_req,3},
> >             {couch_httpd_db,do_db_req,2},
> >             {couch_httpd,handle_request_int,5},
> >             {mochiweb_http,headers,5},
> >             {proc_lib,init_p_do_apply,3}]
> >
> > [Mon, 10 Jan 2011 21:42:17 GMT] [info] [<0.8844.3>] 127.0.0.1 - - 'PUT'
> > /test/_design/test/_rewrite/test/randomid324324 404
> >
> > [Mon, 10 Jan 2011 21:42:17 GMT] [debug] [<0.8844.3>] httpd 404 error
> > response:
> >  {"error":"not_found","reason":"missing"}
> >
> >
> >
> >
> > # Executed command 1.3:
> > $curl  -d @example -H "Content-type:application/json" -e
> > http://localhost:5984/test
> > http://localhost:5984/test/_design/test/_rewrite/test/
> > {"error":"bad_content_type","reason":"Content-Type must be
> > multipart/form-data"}
> >
> > # Comment: Rewrite is wrong - also peculiar it won't take
> application/json
> > content type.
> >
> > # LOG:
> > [Mon, 10 Jan 2011 21:51:55 GMT] [debug] [<0.9453.3>] 'POST'
> > /test/_design/test/_rewrite/test/ {1,1}
> > Headers: [{'Accept',"*/*"},
> >          {'Content-Length',"23"},
> >          {'Content-Type',"application/json"},
> >          {'Host',"localhost:5984"},
> >          {'Referer',"http://localhost:5984/test"},
> >          {'User-Agent',"curl/7.21.0 (i686-pc-linux-gnu) libcurl/7.21.0
> > OpenSSL/0.9.8o zlib/1.2.3.4 libidn/1.18"}]
> >
> > [Mon, 10 Jan 2011 21:51:55 GMT] [debug] [<0.9453.3>] OAuth Params: []
> >
> > [Mon, 10 Jan 2011 21:51:55 GMT] [debug] [<0.9453.3>] rewrite to
> > "/test/_design/..?db=test"
> >
> >
> > [Mon, 10 Jan 2011 21:51:55 GMT] [debug] [<0.9453.3>] 'POST'
> > /test/_design/..?db=test {1,1}
> > Headers: [{'Accept',"*/*"},
> >          {'Content-Length',"23"},
> >          {'Content-Type',"application/json"},
> >          {'Host',"localhost:5984"},
> >          {'Referer',"http://localhost:5984/test"},
> >          {'User-Agent',"curl/7.21.0 (i686-pc-linux-gnu) libcurl/7.21.0
> > OpenSSL/0.9.8o zlib/1.2.3.4 libidn/1.18"}]
> >
> > [Mon, 10 Jan 2011 21:51:55 GMT] [debug] [<0.9453.3>] OAuth Params:
> > [{"db","test"}]
> >
> > [Mon, 10 Jan 2011 21:51:55 GMT] [debug] [<0.9453.3>] Minor error in HTTP
> > request: {bad_ctype,
> >                                 "Content-Type must be
> multipart/form-data"}
> >
> > [Mon, 10 Jan 2011 21:51:55 GMT] [debug] [<0.9453.3>] Stacktrace:
> > [{couch_httpd,validate_ctype,2},
> >             {couch_httpd_db,db_doc_req,3},
> >             {couch_httpd_db,do_db_req,2},
> >             {couch_httpd,handle_request_int,5},
> >             {couch_httpd_db,do_db_req,2},
> >             {couch_httpd,handle_request_int,5},
> >             {mochiweb_http,headers,5},
> >             {proc_lib,init_p_do_apply,3}]
> >
> > [Mon, 10 Jan 2011 21:51:55 GMT] [info] [<0.9453.3>] 127.0.0.1 - - 'POST'
> > /test/_design/..?db=test 415
> >
> > [Mon, 10 Jan 2011 21:51:55 GMT] [debug] [<0.9453.3>] httpd 415 error
> > response:
> >  {"error":"bad_content_type","reason":"Content-Type must be
> > multipart/form-data"}
> >
> >
> >
> > # Executed command 1.4:
> > $ curl  -d @example -H "Content-type:application/json" -e
> > http://localhost:5984/test  http://localhost:5984/test/randomid32420
> > {"error":"bad_content_type","reason":"Content-Type must be
> > multipart/form-data"}
> >
> > # Comment: I did this one just because - and I noticed that when you post
> > with and ID - it wont accept JSON content type
> >
> > # LOG:
> > [Mon, 10 Jan 2011 21:54:23 GMT] [debug] [<0.9490.3>] 'POST'
> > /test/randomid32420 {1,1}
> > Headers: [{'Accept',"*/*"},
> >          {'Content-Length',"23"},
> >          {'Content-Type',"application/json"},
> >          {'Host',"localhost:5984"},
> >          {'Referer',"http://localhost:5984/test"},
> >          {'User-Agent',"curl/7.21.0 (i686-pc-linux-gnu) libcurl/7.21.0
> > OpenSSL/0.9.8o zlib/1.2.3.4 libidn/1.18"}]
> >
> > [Mon, 10 Jan 2011 21:54:23 GMT] [debug] [<0.9490.3>] OAuth Params: []
> >
> > [Mon, 10 Jan 2011 21:54:23 GMT] [debug] [<0.9490.3>] Minor error in HTTP
> > request: {bad_ctype,
> >                                 "Content-Type must be
> multipart/form-data"}
> >
> > [Mon, 10 Jan 2011 21:54:23 GMT] [debug] [<0.9490.3>] Stacktrace:
> > [{couch_httpd,validate_ctype,2},
> >             {couch_httpd_db,db_doc_req,3},
> >             {couch_httpd_db,do_db_req,2},
> >             {couch_httpd,handle_request_int,5},
> >             {mochiweb_http,headers,5},
> >             {proc_lib,init_p_do_apply,3}]
> >
> > [Mon, 10 Jan 2011 21:54:23 GMT] [info] [<0.9490.3>] 127.0.0.1 - - 'POST'
> > /test/randomid32420 415
> >
> > [Mon, 10 Jan 2011 21:54:23 GMT] [debug] [<0.9490.3>] httpd 415 error
> > response:
> >  {"error":"bad_content_type","reason":"Content-Type must be
> > multipart/form-data"}
> >
> >
> >
> >
> ----------------------------------------------------------------------------------------------------
> >
> >
> > ## Test 2:
> >
> > # Rewrites config:
> > [
> >   {
> >       "to": "../../*",
> >       "from": ":db/*"
> >   }
> > ]
> >
> > # Executed command 2.1:
> > $ curl  -d @example -H "Content-type:application/json" -e
> > http://localhost:5984/test  http://localhost:5984/test/
> >
> {"ok":true,"id":"ce8b504d63666c9257cc07537c00af99","rev":"1-505a221d0aef5d664f29d6afdae01293"}
> >
> > # Comment: OK, everything is fine
> >
> >
> >
> > #Executed command 2.2:
> > $ curl -X PUT  -d @example -H "Content-type:application/json"
> > http://localhost:5984/test/_design/test/_rewrite/test/randomid3125
> >
> {"ok":true,"id":"randomid3125","rev":"1-505a221d0aef5d664f29d6afdae01293"}
> >
> > # Comment: OK, everything is fine - since now rewrite rule appropriately
> > handles the ID.
> >
> >
> > #Executed command 2.3:
> > $ curl  -d @example -H "Content-type:application/json" -e
> > http://localhost:5984/test
> > http://localhost:5984/test/_design/test/_rewrite/test/
> > {"error":"bad_content_type","reason":"Content-Type must be
> > multipart/form-data"}
> >
> > # Comment: Routing and content type are wrong (routing in PUT request -
> > command 2.2 was done right!)
> >
> > # LOG:
> > [Mon, 10 Jan 2011 22:06:17 GMT] [debug] [<0.10262.3>] 'POST'
> > /test/_design/test/_rewrite/test/ {1,1}
> > Headers: [{'Accept',"*/*"},
> >          {'Content-Length',"23"},
> >          {'Content-Type',"application/json"},
> >          {'Host',"localhost:5984"},
> >          {'Referer',"http://localhost:5984/test"},
> >          {'User-Agent',"curl/7.21.0 (i686-pc-linux-gnu) libcurl/7.21.0
> > OpenSSL/0.9.8o zlib/1.2.3.4 libidn/1.18"}]
> >
> > [Mon, 10 Jan 2011 22:06:17 GMT] [debug] [<0.10262.3>] OAuth Params: []
> >
> > [Mon, 10 Jan 2011 22:06:17 GMT] [debug] [<0.10262.3>] rewrite to
> > "/test/_design/..?db=test"
> >
> >
> > [Mon, 10 Jan 2011 22:06:17 GMT] [debug] [<0.10262.3>] 'POST'
> > /test/_design/..?db=test {1,1}
> > Headers: [{'Accept',"*/*"},
> >          {'Content-Length',"23"},
> >          {'Content-Type',"application/json"},
> >          {'Host',"localhost:5984"},
> >          {'Referer',"http://localhost:5984/test"},
> >          {'User-Agent',"curl/7.21.0 (i686-pc-linux-gnu) libcurl/7.21.0
> > OpenSSL/0.9.8o zlib/1.2.3.4 libidn/1.18"}]
> >
> > [Mon, 10 Jan 2011 22:06:17 GMT] [debug] [<0.10262.3>] OAuth Params:
> > [{"db","test"}]
> >
> > [Mon, 10 Jan 2011 22:06:17 GMT] [debug] [<0.10262.3>] Minor error in HTTP
> > request: {bad_ctype,
> >                                 "Content-Type must be
> multipart/form-data"}
> >
> > [Mon, 10 Jan 2011 22:06:17 GMT] [debug] [<0.10262.3>] Stacktrace:
> > [{couch_httpd,validate_ctype,2},
> >             {couch_httpd_db,db_doc_req,3},
> >             {couch_httpd_db,do_db_req,2},
> >             {couch_httpd,handle_request_int,5},
> >             {couch_httpd_db,do_db_req,2},
> >             {couch_httpd,handle_request_int,5},
> >             {mochiweb_http,headers,5},
> >             {proc_lib,init_p_do_apply,3}]
> >
> > [Mon, 10 Jan 2011 22:06:17 GMT] [info] [<0.10262.3>] 127.0.0.1 - - 'POST'
> > /test/_design/..?db=test 415
> >
> > [Mon, 10 Jan 2011 22:06:17 GMT] [debug] [<0.10262.3>] httpd 415 error
> > response:
> >  {"error":"bad_content_type","reason":"Content-Type must be
> > multipart/form-data"}
> >
> >
> > #Executed command 2.4:
> > $ curl  -d @example -H "Content-type:application/json" -e
> > http://localhost:5984/test  http://localhost:5984/test/randomid32843
> > {"error":"bad_content_type","reason":"Content-Type must be
> > multipart/form-data"}
> >
> > #Comment: No routing information in log, got Cotent type error.
> >
> > #LOG:
> > [Mon, 10 Jan 2011 22:11:53 GMT] [debug] [<0.10377.3>] 'POST'
> > /test/randomid32843 {1,1}
> > Headers: [{'Accept',"*/*"},
> >          {'Content-Length',"23"},
> >          {'Content-Type',"application/json"},
> >          {'Host',"localhost:5984"},
> >          {'Referer',"http://localhost:5984/test"},
> >          {'User-Agent',"curl/7.21.0 (i686-pc-linux-gnu) libcurl/7.21.0
> > OpenSSL/0.9.8o zlib/1.2.3.4 libidn/1.18"}]
> >
> > [Mon, 10 Jan 2011 22:11:53 GMT] [debug] [<0.10377.3>] OAuth Params: []
> >
> > [Mon, 10 Jan 2011 22:11:53 GMT] [debug] [<0.10377.3>] Minor error in HTTP
> > request: {bad_ctype,
> >                                 "Content-Type must be
> multipart/form-data"}
> >
> > [Mon, 10 Jan 2011 22:11:53 GMT] [debug] [<0.10377.3>] Stacktrace:
> > [{couch_httpd,validate_ctype,2},
> >             {couch_httpd_db,db_doc_req,3},
> >             {couch_httpd_db,do_db_req,2},
> >             {couch_httpd,handle_request_int,5},
> >             {mochiweb_http,headers,5},
> >             {proc_lib,init_p_do_apply,3}]
> >
> > [Mon, 10 Jan 2011 22:11:53 GMT] [info] [<0.10377.3>] 127.0.0.1 - - 'POST'
> > /test/randomid32843 415
> >
> > [Mon, 10 Jan 2011 22:11:53 GMT] [debug] [<0.10377.3>] httpd 415 error
> > response:
> >  {"error":"bad_content_type","reason":"Content-Type must be
> > multipart/form-data"}
> >
> >
> ----------------------------------------------------------------------------------------------------
> >
> >
> > ## Test 3:
> >
> > # Rewrites config:
> > [
> >   {
> >       "to": "../../*",
> >       "from": ":db/*"
> >   },
> >   {
> >       "to": "../..",
> >       "from": ":db"
> >   }
> > ]
> >
> >
> > # Executed command 3.1:
> > $ curl  -d @example -H "Content-type:application/json" -e
> > http://localhost:5984/test  http://localhost:5984/test/
> >
> {"ok":true,"id":"ce8b504d63666c9257cc07537c00bbe3","rev":"1-505a221d0aef5d664f29d6afdae01293"}
> >
> > # Comment: OK! works as expected
> >
> >
> >
> > #Executed command 3.2:
> > $ curl -X PUT  -d @example -H "Content-type:application/json"
> > http://localhost:5984/test/_design/test/_rewrite/test/randomid43242
> >
> {"ok":true,"id":"randomid43242","rev":"1-505a221d0aef5d664f29d6afdae01293"}
> >
> > # Comment: OK! works as expected
> >
> >
> > #Executed command 3.3:
> > $ curl  -d @example -H "Content-type:application/json" -e
> > http://localhost:5984/test
> > http://localhost:5984/test/_design/test/_rewrite/test/
> > {"error":"bad_content_type","reason":"Content-Type must be
> > multipart/form-data"}
> >
> > # Comment: Rewrite issue and content type issue
> >
> > # LOG:
> > [Mon, 10 Jan 2011 22:19:55 GMT] [debug] [<0.11199.3>] 'POST'
> > /test/_design/test/_rewrite/test/ {1,1}
> > Headers: [{'Accept',"*/*"},
> >          {'Content-Length',"23"},
> >          {'Content-Type',"application/json"},
> >          {'Host',"localhost:5984"},
> >          {'Referer',"http://localhost:5984/test"},
> >          {'User-Agent',"curl/7.21.0 (i686-pc-linux-gnu) libcurl/7.21.0
> > OpenSSL/0.9.8o zlib/1.2.3.4 libidn/1.18"}]
> >
> > [Mon, 10 Jan 2011 22:19:55 GMT] [debug] [<0.11199.3>] OAuth Params: []
> >
> > [Mon, 10 Jan 2011 22:19:55 GMT] [debug] [<0.11199.3>] rewrite to
> > "/test/_design/..?db=test"
> >
> >
> > [Mon, 10 Jan 2011 22:19:55 GMT] [debug] [<0.11199.3>] 'POST'
> > /test/_design/..?db=test {1,1}
> > Headers: [{'Accept',"*/*"},
> >          {'Content-Length',"23"},
> >          {'Content-Type',"application/json"},
> >          {'Host',"localhost:5984"},
> >          {'Referer',"http://localhost:5984/test"},
> >          {'User-Agent',"curl/7.21.0 (i686-pc-linux-gnu) libcurl/7.21.0
> > OpenSSL/0.9.8o zlib/1.2.3.4 libidn/1.18"}]
> >
> > [Mon, 10 Jan 2011 22:19:55 GMT] [debug] [<0.11199.3>] OAuth Params:
> > [{"db","test"}]
> >
> > [Mon, 10 Jan 2011 22:19:55 GMT] [debug] [<0.11199.3>] Minor error in HTTP
> > request: {bad_ctype,
> >                                 "Content-Type must be
> multipart/form-data"}
> >
> > [Mon, 10 Jan 2011 22:19:55 GMT] [debug] [<0.11199.3>] Stacktrace:
> > [{couch_httpd,validate_ctype,2},
> >             {couch_httpd_db,db_doc_req,3},
> >             {couch_httpd_db,do_db_req,2},
> >             {couch_httpd,handle_request_int,5},
> >             {couch_httpd_db,do_db_req,2},
> >             {couch_httpd,handle_request_int,5},
> >             {mochiweb_http,headers,5},
> >             {proc_lib,init_p_do_apply,3}]
> >
> > [Mon, 10 Jan 2011 22:19:55 GMT] [info] [<0.11199.3>] 127.0.0.1 - - 'POST'
> > /test/_design/..?db=test 415
> >
> > [Mon, 10 Jan 2011 22:19:55 GMT] [debug] [<0.11199.3>] httpd 415 error
> > response:
> >  {"error":"bad_content_type","reason":"Content-Type must be
> > multipart/form-data"}
> >
> >
> > #Executed command 3.4:
> > $  curl  -d @example -H "Content-type:application/json" -e
> > http://localhost:5984/test  http://localhost:5984/test/randomid432432
> > {"error":"bad_content_type","reason":"Content-Type must be
> > multipart/form-data"}
> >
> > #Comment: Obviously no rewrite issue, however content type problem is
> there
> >
> > #LOG:
> > [Mon, 10 Jan 2011 22:21:24 GMT] [debug] [<0.11220.3>] 'POST'
> > /test/randomid432432 {1,1}
> > Headers: [{'Accept',"*/*"},
> >          {'Content-Length',"23"},
> >          {'Content-Type',"application/json"},
> >          {'Host',"localhost:5984"},
> >          {'Referer',"http://localhost:5984/test"},
> >          {'User-Agent',"curl/7.21.0 (i686-pc-linux-gnu) libcurl/7.21.0
> > OpenSSL/0.9.8o zlib/1.2.3.4 libidn/1.18"}]
> >
> > [Mon, 10 Jan 2011 22:21:24 GMT] [debug] [<0.11220.3>] OAuth Params: []
> >
> > [Mon, 10 Jan 2011 22:21:24 GMT] [debug] [<0.11220.3>] Minor error in HTTP
> > request: {bad_ctype,
> >                                 "Content-Type must be
> multipart/form-data"}
> >
> > [Mon, 10 Jan 2011 22:21:24 GMT] [debug] [<0.11220.3>] Stacktrace:
> > [{couch_httpd,validate_ctype,2},
> >             {couch_httpd_db,db_doc_req,3},
> >             {couch_httpd_db,do_db_req,2},
> >             {couch_httpd,handle_request_int,5},
> >             {mochiweb_http,headers,5},
> >             {proc_lib,init_p_do_apply,3}]
> >
> > [Mon, 10 Jan 2011 22:21:24 GMT] [info] [<0.11220.3>] 127.0.0.1 - - 'POST'
> > /test/randomid432432 415
> >
> > [Mon, 10 Jan 2011 22:21:24 GMT] [debug] [<0.11220.3>] httpd 415 error
> > response:
> >  {"error":"bad_content_type","reason":"Content-Type must be
> > multipart/form-data"}
> >
> >
> >
> > Apparently these are two different issues.
> >
> > First handling of rewrites for POST requests and the second is the
> problem
> > with Content types?
> >
> > Also I would be extremely happy to find out what are more exact rules for
> > pattern matching? I have found this site (
> > http://caolanmcmahon.com/on_designs_undocumented.html) which provides
> some
> > answers. I have also read somewhere that rewriting is basically Erlang
> > pattern matching ... so should I read up more about the topic in Erlang
> > documentation?
> >
> > There is also a question I have that wasn't answered anywhere - is it
> > possible for multiple rewrites to apply to single request? If so what is
> the
> > precedence? If not - what is the precedence in that case.
> >
> > Thank you for any response.
> >
> > Kind regards, -Janez
> >
> > On Thu, Jan 13, 2011 at 8:21 AM, Benoit Chesneau <bchesneau@gmail.com
> >wrote:
> >
> >> did you try to add:
> >>
> >> {
> >>
> >> "from": ":db",
> >> "to": "../.."
> >> }
> >>
> >> ?
> >>
> >> - benoît
> >>
> >> On Mon, Jan 10, 2011 at 6:21 PM, Janez Štupar <ja...@gmail.com>
> >> wrote:
> >> > Here is the problem I'm currently dabbling around with Sofa (got it
> from
> >> > jchrisa's Github)... To this end I'm reverse engineering it and trying
> to
> >> > get it work in a following scenario:
> >> >
> >> > The database is hidden behind following VHost: sofa.mycouch  ->
> >> > /sofa/_design/sofa/_rewrite
> >> >
> >> > Since I wanted to improve the appearance of the URL's I also did some
> >> > modifications to the rewrites, my current configuration is as follows:
> >> >
> >> > [
> >> >   {
> >> >       "to": "_list/index/recent-posts",
> >> >       "from": "blog/",
> >> >       "query": {
> >> >           "limit": 10,
> >> >           "descending": true
> >> >       }
> >> >   },
> >> >   {
> >> >       "to": "_list/:listname/*",
> >> >       "from": "list/:listname/*",
> >> >       "query": {
> >> >           "limit": 10,
> >> >           "descending": true
> >> >       }
> >> >   },
> >> >   {
> >> >        "to" : "_show/:showname/*",
> >> >        "from" : "show/:showname/*"
> >> >   },
> >> >   {
> >> >         "to" : "_update/:updatename/*",
> >> >         "from" : "update/:updatename/*"
> >> >   },
> >> >   {
> >> >       "to": "_list/index/recent-posts",
> >> >       "from": "",
> >> >       "query": {
> >> >           "limit": 10,
> >> >           "descending": true
> >> >       }
> >> >   },
> >> >   {
> >> >       "to": "script/*",
> >> >       "from": "script/*"
> >> >   },
> >> >   {
> >> >       "to": "style/*",
> >> >       "from": "style/*"
> >> >   },
> >> >   {
> >> >       "to": "vendor/*",
> >> >       "from": "vendor/*"
> >> >   },
> >> >   {
> >> >    "to": "../../*",
> >> >    "from": ":db/*"
> >> >   }
> >> > ]
> >> >
> >> > The last problem I have left is that although everything works (I have
> >> > indeed done some modifications to the templates, pathing function,
> etc..
> >> > nothing relevant to this current issue IMHO).
> >> > *
> >> > Except* one thing doesn't work as expected ... that is posting
> comments.
> >> I
> >> > have kinda narrowed it down that when the browser sends a new blog
> post
> >> it
> >> > does PUT to address:
> '"/sofa/_design/sofa/_rewrite/sofa/spet-nov-post"'
> >> > (spet-nov-post is a _id - according to jquery.couch.js)
> >> >
> >> > While comment gets POST -ed to following URL:
> >> > '"/sofa/_design/sofa/_rewrite/sofa/"'
> >> >
> >> > what happens in the rewriter is following:
> >> >
> >> > 'PUT' /sofa/_design/sofa/_rewrite/sofa/spet-nov-post {1,1} -> 'PUT'
> >> > /sofa/spet-nov-post?db=sofa {1,1}
> >> > 'POST' /sofa/_design/sofa/_rewrite/sofa/ {1,1}  -> 'POST'
> >> > /sofa/_design/..?db=sofa {1,1}
> >> >
> >> > I blame the following rewrite rule:
> >> >   {
> >> >    "to": "../../*",
> >> >    "from": ":db/*"
> >> >   }
> >> >
> >>
> >
> So using 2 rewrites rules work right ? (That what I suggested). For
> content-type This is something expected i think. Will re-read this
> separate issue later. Headers are not rewritten anyway.
>
> - benoît
>

Re: Strange issue with VHosts and rewrites...

Posted by Benoit Chesneau <bc...@gmail.com>.
On Thu, Jan 13, 2011 at 4:17 PM, Janez Štupar <ja...@gmail.com> wrote:
> Benoît, I did what you proposed and it behaves exactly as before
>
> Ok i did some testing and this is what I figured out.
>
> This is my testing setup: I created a new database (test) that doesn't use
> any VHost rules.
>
> Inside it I created a design document that only has rewrites field. I will
> present test results exactly as per configuration I used.
>
> I always sent the same document contained in file "example" - namely:
> {
>    "type": "comment"
> }
>
> Below are the test results:
> ----------------------------------------------------------------------------------------------------
> ## Test 1:
> # rewrites config:
> [
>   {
>       "to": "../..",
>       "from": ":db"
>   }
> ]
>
> # Executed command 1.1:
> $ curl  -d @example -H "Content-type:application/json" -e
> http://localhost:5984/test  http://localhost:5984/test/
> {"ok":true,"id":"ce8b504d63666c9257cc07537c00aa70","rev":"1-505a221d0aef5d664f29d6afdae01293"}
>
> # Comment: expected result - everything is fine.
>
>
>
> # Executed command 1.2:
> $ curl -X PUT  -d @example -H "Content-type:application/json"
> http://localhost:5984/test/_design/test/_rewrite/test/randomid324324
> {"error":"not_found","reason":"missing"}
>
> # Comment: result expected since there is no ID parameter passed through -
> due to the rewrite rule
>
> #LOG:
> [Mon, 10 Jan 2011 21:42:17 GMT] [debug] [<0.8844.3>] 'PUT'
> /test/_design/test/_rewrite/test/randomid324324 {1,1}
> Headers: [{'Accept',"*/*"},
>          {'Content-Length',"23"},
>          {'Content-Type',"application/json"},
>          {'Host',"localhost:5984"},
>          {'User-Agent',"curl/7.21.0 (i686-pc-linux-gnu) libcurl/7.21.0
> OpenSSL/0.9.8o zlib/1.2.3.4 libidn/1.18"}]
>
> [Mon, 10 Jan 2011 21:42:17 GMT] [debug] [<0.8844.3>] OAuth Params: []
>
> [Mon, 10 Jan 2011 21:42:17 GMT] [debug] [<0.8844.3>] Minor error in HTTP
> request: not_found
>
> [Mon, 10 Jan 2011 21:42:17 GMT] [debug] [<0.8844.3>] Stacktrace:
> [{couch_httpd_rewrite,handle_rewrite_req,3},
>             {couch_httpd_db,do_db_req,2},
>             {couch_httpd,handle_request_int,5},
>             {mochiweb_http,headers,5},
>             {proc_lib,init_p_do_apply,3}]
>
> [Mon, 10 Jan 2011 21:42:17 GMT] [info] [<0.8844.3>] 127.0.0.1 - - 'PUT'
> /test/_design/test/_rewrite/test/randomid324324 404
>
> [Mon, 10 Jan 2011 21:42:17 GMT] [debug] [<0.8844.3>] httpd 404 error
> response:
>  {"error":"not_found","reason":"missing"}
>
>
>
>
> # Executed command 1.3:
> $curl  -d @example -H "Content-type:application/json" -e
> http://localhost:5984/test
> http://localhost:5984/test/_design/test/_rewrite/test/
> {"error":"bad_content_type","reason":"Content-Type must be
> multipart/form-data"}
>
> # Comment: Rewrite is wrong - also peculiar it won't take application/json
> content type.
>
> # LOG:
> [Mon, 10 Jan 2011 21:51:55 GMT] [debug] [<0.9453.3>] 'POST'
> /test/_design/test/_rewrite/test/ {1,1}
> Headers: [{'Accept',"*/*"},
>          {'Content-Length',"23"},
>          {'Content-Type',"application/json"},
>          {'Host',"localhost:5984"},
>          {'Referer',"http://localhost:5984/test"},
>          {'User-Agent',"curl/7.21.0 (i686-pc-linux-gnu) libcurl/7.21.0
> OpenSSL/0.9.8o zlib/1.2.3.4 libidn/1.18"}]
>
> [Mon, 10 Jan 2011 21:51:55 GMT] [debug] [<0.9453.3>] OAuth Params: []
>
> [Mon, 10 Jan 2011 21:51:55 GMT] [debug] [<0.9453.3>] rewrite to
> "/test/_design/..?db=test"
>
>
> [Mon, 10 Jan 2011 21:51:55 GMT] [debug] [<0.9453.3>] 'POST'
> /test/_design/..?db=test {1,1}
> Headers: [{'Accept',"*/*"},
>          {'Content-Length',"23"},
>          {'Content-Type',"application/json"},
>          {'Host',"localhost:5984"},
>          {'Referer',"http://localhost:5984/test"},
>          {'User-Agent',"curl/7.21.0 (i686-pc-linux-gnu) libcurl/7.21.0
> OpenSSL/0.9.8o zlib/1.2.3.4 libidn/1.18"}]
>
> [Mon, 10 Jan 2011 21:51:55 GMT] [debug] [<0.9453.3>] OAuth Params:
> [{"db","test"}]
>
> [Mon, 10 Jan 2011 21:51:55 GMT] [debug] [<0.9453.3>] Minor error in HTTP
> request: {bad_ctype,
>                                 "Content-Type must be multipart/form-data"}
>
> [Mon, 10 Jan 2011 21:51:55 GMT] [debug] [<0.9453.3>] Stacktrace:
> [{couch_httpd,validate_ctype,2},
>             {couch_httpd_db,db_doc_req,3},
>             {couch_httpd_db,do_db_req,2},
>             {couch_httpd,handle_request_int,5},
>             {couch_httpd_db,do_db_req,2},
>             {couch_httpd,handle_request_int,5},
>             {mochiweb_http,headers,5},
>             {proc_lib,init_p_do_apply,3}]
>
> [Mon, 10 Jan 2011 21:51:55 GMT] [info] [<0.9453.3>] 127.0.0.1 - - 'POST'
> /test/_design/..?db=test 415
>
> [Mon, 10 Jan 2011 21:51:55 GMT] [debug] [<0.9453.3>] httpd 415 error
> response:
>  {"error":"bad_content_type","reason":"Content-Type must be
> multipart/form-data"}
>
>
>
> # Executed command 1.4:
> $ curl  -d @example -H "Content-type:application/json" -e
> http://localhost:5984/test  http://localhost:5984/test/randomid32420
> {"error":"bad_content_type","reason":"Content-Type must be
> multipart/form-data"}
>
> # Comment: I did this one just because - and I noticed that when you post
> with and ID - it wont accept JSON content type
>
> # LOG:
> [Mon, 10 Jan 2011 21:54:23 GMT] [debug] [<0.9490.3>] 'POST'
> /test/randomid32420 {1,1}
> Headers: [{'Accept',"*/*"},
>          {'Content-Length',"23"},
>          {'Content-Type',"application/json"},
>          {'Host',"localhost:5984"},
>          {'Referer',"http://localhost:5984/test"},
>          {'User-Agent',"curl/7.21.0 (i686-pc-linux-gnu) libcurl/7.21.0
> OpenSSL/0.9.8o zlib/1.2.3.4 libidn/1.18"}]
>
> [Mon, 10 Jan 2011 21:54:23 GMT] [debug] [<0.9490.3>] OAuth Params: []
>
> [Mon, 10 Jan 2011 21:54:23 GMT] [debug] [<0.9490.3>] Minor error in HTTP
> request: {bad_ctype,
>                                 "Content-Type must be multipart/form-data"}
>
> [Mon, 10 Jan 2011 21:54:23 GMT] [debug] [<0.9490.3>] Stacktrace:
> [{couch_httpd,validate_ctype,2},
>             {couch_httpd_db,db_doc_req,3},
>             {couch_httpd_db,do_db_req,2},
>             {couch_httpd,handle_request_int,5},
>             {mochiweb_http,headers,5},
>             {proc_lib,init_p_do_apply,3}]
>
> [Mon, 10 Jan 2011 21:54:23 GMT] [info] [<0.9490.3>] 127.0.0.1 - - 'POST'
> /test/randomid32420 415
>
> [Mon, 10 Jan 2011 21:54:23 GMT] [debug] [<0.9490.3>] httpd 415 error
> response:
>  {"error":"bad_content_type","reason":"Content-Type must be
> multipart/form-data"}
>
>
>
> ----------------------------------------------------------------------------------------------------
>
>
> ## Test 2:
>
> # Rewrites config:
> [
>   {
>       "to": "../../*",
>       "from": ":db/*"
>   }
> ]
>
> # Executed command 2.1:
> $ curl  -d @example -H "Content-type:application/json" -e
> http://localhost:5984/test  http://localhost:5984/test/
> {"ok":true,"id":"ce8b504d63666c9257cc07537c00af99","rev":"1-505a221d0aef5d664f29d6afdae01293"}
>
> # Comment: OK, everything is fine
>
>
>
> #Executed command 2.2:
> $ curl -X PUT  -d @example -H "Content-type:application/json"
> http://localhost:5984/test/_design/test/_rewrite/test/randomid3125
> {"ok":true,"id":"randomid3125","rev":"1-505a221d0aef5d664f29d6afdae01293"}
>
> # Comment: OK, everything is fine - since now rewrite rule appropriately
> handles the ID.
>
>
> #Executed command 2.3:
> $ curl  -d @example -H "Content-type:application/json" -e
> http://localhost:5984/test
> http://localhost:5984/test/_design/test/_rewrite/test/
> {"error":"bad_content_type","reason":"Content-Type must be
> multipart/form-data"}
>
> # Comment: Routing and content type are wrong (routing in PUT request -
> command 2.2 was done right!)
>
> # LOG:
> [Mon, 10 Jan 2011 22:06:17 GMT] [debug] [<0.10262.3>] 'POST'
> /test/_design/test/_rewrite/test/ {1,1}
> Headers: [{'Accept',"*/*"},
>          {'Content-Length',"23"},
>          {'Content-Type',"application/json"},
>          {'Host',"localhost:5984"},
>          {'Referer',"http://localhost:5984/test"},
>          {'User-Agent',"curl/7.21.0 (i686-pc-linux-gnu) libcurl/7.21.0
> OpenSSL/0.9.8o zlib/1.2.3.4 libidn/1.18"}]
>
> [Mon, 10 Jan 2011 22:06:17 GMT] [debug] [<0.10262.3>] OAuth Params: []
>
> [Mon, 10 Jan 2011 22:06:17 GMT] [debug] [<0.10262.3>] rewrite to
> "/test/_design/..?db=test"
>
>
> [Mon, 10 Jan 2011 22:06:17 GMT] [debug] [<0.10262.3>] 'POST'
> /test/_design/..?db=test {1,1}
> Headers: [{'Accept',"*/*"},
>          {'Content-Length',"23"},
>          {'Content-Type',"application/json"},
>          {'Host',"localhost:5984"},
>          {'Referer',"http://localhost:5984/test"},
>          {'User-Agent',"curl/7.21.0 (i686-pc-linux-gnu) libcurl/7.21.0
> OpenSSL/0.9.8o zlib/1.2.3.4 libidn/1.18"}]
>
> [Mon, 10 Jan 2011 22:06:17 GMT] [debug] [<0.10262.3>] OAuth Params:
> [{"db","test"}]
>
> [Mon, 10 Jan 2011 22:06:17 GMT] [debug] [<0.10262.3>] Minor error in HTTP
> request: {bad_ctype,
>                                 "Content-Type must be multipart/form-data"}
>
> [Mon, 10 Jan 2011 22:06:17 GMT] [debug] [<0.10262.3>] Stacktrace:
> [{couch_httpd,validate_ctype,2},
>             {couch_httpd_db,db_doc_req,3},
>             {couch_httpd_db,do_db_req,2},
>             {couch_httpd,handle_request_int,5},
>             {couch_httpd_db,do_db_req,2},
>             {couch_httpd,handle_request_int,5},
>             {mochiweb_http,headers,5},
>             {proc_lib,init_p_do_apply,3}]
>
> [Mon, 10 Jan 2011 22:06:17 GMT] [info] [<0.10262.3>] 127.0.0.1 - - 'POST'
> /test/_design/..?db=test 415
>
> [Mon, 10 Jan 2011 22:06:17 GMT] [debug] [<0.10262.3>] httpd 415 error
> response:
>  {"error":"bad_content_type","reason":"Content-Type must be
> multipart/form-data"}
>
>
> #Executed command 2.4:
> $ curl  -d @example -H "Content-type:application/json" -e
> http://localhost:5984/test  http://localhost:5984/test/randomid32843
> {"error":"bad_content_type","reason":"Content-Type must be
> multipart/form-data"}
>
> #Comment: No routing information in log, got Cotent type error.
>
> #LOG:
> [Mon, 10 Jan 2011 22:11:53 GMT] [debug] [<0.10377.3>] 'POST'
> /test/randomid32843 {1,1}
> Headers: [{'Accept',"*/*"},
>          {'Content-Length',"23"},
>          {'Content-Type',"application/json"},
>          {'Host',"localhost:5984"},
>          {'Referer',"http://localhost:5984/test"},
>          {'User-Agent',"curl/7.21.0 (i686-pc-linux-gnu) libcurl/7.21.0
> OpenSSL/0.9.8o zlib/1.2.3.4 libidn/1.18"}]
>
> [Mon, 10 Jan 2011 22:11:53 GMT] [debug] [<0.10377.3>] OAuth Params: []
>
> [Mon, 10 Jan 2011 22:11:53 GMT] [debug] [<0.10377.3>] Minor error in HTTP
> request: {bad_ctype,
>                                 "Content-Type must be multipart/form-data"}
>
> [Mon, 10 Jan 2011 22:11:53 GMT] [debug] [<0.10377.3>] Stacktrace:
> [{couch_httpd,validate_ctype,2},
>             {couch_httpd_db,db_doc_req,3},
>             {couch_httpd_db,do_db_req,2},
>             {couch_httpd,handle_request_int,5},
>             {mochiweb_http,headers,5},
>             {proc_lib,init_p_do_apply,3}]
>
> [Mon, 10 Jan 2011 22:11:53 GMT] [info] [<0.10377.3>] 127.0.0.1 - - 'POST'
> /test/randomid32843 415
>
> [Mon, 10 Jan 2011 22:11:53 GMT] [debug] [<0.10377.3>] httpd 415 error
> response:
>  {"error":"bad_content_type","reason":"Content-Type must be
> multipart/form-data"}
>
> ----------------------------------------------------------------------------------------------------
>
>
> ## Test 3:
>
> # Rewrites config:
> [
>   {
>       "to": "../../*",
>       "from": ":db/*"
>   },
>   {
>       "to": "../..",
>       "from": ":db"
>   }
> ]
>
>
> # Executed command 3.1:
> $ curl  -d @example -H "Content-type:application/json" -e
> http://localhost:5984/test  http://localhost:5984/test/
> {"ok":true,"id":"ce8b504d63666c9257cc07537c00bbe3","rev":"1-505a221d0aef5d664f29d6afdae01293"}
>
> # Comment: OK! works as expected
>
>
>
> #Executed command 3.2:
> $ curl -X PUT  -d @example -H "Content-type:application/json"
> http://localhost:5984/test/_design/test/_rewrite/test/randomid43242
> {"ok":true,"id":"randomid43242","rev":"1-505a221d0aef5d664f29d6afdae01293"}
>
> # Comment: OK! works as expected
>
>
> #Executed command 3.3:
> $ curl  -d @example -H "Content-type:application/json" -e
> http://localhost:5984/test
> http://localhost:5984/test/_design/test/_rewrite/test/
> {"error":"bad_content_type","reason":"Content-Type must be
> multipart/form-data"}
>
> # Comment: Rewrite issue and content type issue
>
> # LOG:
> [Mon, 10 Jan 2011 22:19:55 GMT] [debug] [<0.11199.3>] 'POST'
> /test/_design/test/_rewrite/test/ {1,1}
> Headers: [{'Accept',"*/*"},
>          {'Content-Length',"23"},
>          {'Content-Type',"application/json"},
>          {'Host',"localhost:5984"},
>          {'Referer',"http://localhost:5984/test"},
>          {'User-Agent',"curl/7.21.0 (i686-pc-linux-gnu) libcurl/7.21.0
> OpenSSL/0.9.8o zlib/1.2.3.4 libidn/1.18"}]
>
> [Mon, 10 Jan 2011 22:19:55 GMT] [debug] [<0.11199.3>] OAuth Params: []
>
> [Mon, 10 Jan 2011 22:19:55 GMT] [debug] [<0.11199.3>] rewrite to
> "/test/_design/..?db=test"
>
>
> [Mon, 10 Jan 2011 22:19:55 GMT] [debug] [<0.11199.3>] 'POST'
> /test/_design/..?db=test {1,1}
> Headers: [{'Accept',"*/*"},
>          {'Content-Length',"23"},
>          {'Content-Type',"application/json"},
>          {'Host',"localhost:5984"},
>          {'Referer',"http://localhost:5984/test"},
>          {'User-Agent',"curl/7.21.0 (i686-pc-linux-gnu) libcurl/7.21.0
> OpenSSL/0.9.8o zlib/1.2.3.4 libidn/1.18"}]
>
> [Mon, 10 Jan 2011 22:19:55 GMT] [debug] [<0.11199.3>] OAuth Params:
> [{"db","test"}]
>
> [Mon, 10 Jan 2011 22:19:55 GMT] [debug] [<0.11199.3>] Minor error in HTTP
> request: {bad_ctype,
>                                 "Content-Type must be multipart/form-data"}
>
> [Mon, 10 Jan 2011 22:19:55 GMT] [debug] [<0.11199.3>] Stacktrace:
> [{couch_httpd,validate_ctype,2},
>             {couch_httpd_db,db_doc_req,3},
>             {couch_httpd_db,do_db_req,2},
>             {couch_httpd,handle_request_int,5},
>             {couch_httpd_db,do_db_req,2},
>             {couch_httpd,handle_request_int,5},
>             {mochiweb_http,headers,5},
>             {proc_lib,init_p_do_apply,3}]
>
> [Mon, 10 Jan 2011 22:19:55 GMT] [info] [<0.11199.3>] 127.0.0.1 - - 'POST'
> /test/_design/..?db=test 415
>
> [Mon, 10 Jan 2011 22:19:55 GMT] [debug] [<0.11199.3>] httpd 415 error
> response:
>  {"error":"bad_content_type","reason":"Content-Type must be
> multipart/form-data"}
>
>
> #Executed command 3.4:
> $  curl  -d @example -H "Content-type:application/json" -e
> http://localhost:5984/test  http://localhost:5984/test/randomid432432
> {"error":"bad_content_type","reason":"Content-Type must be
> multipart/form-data"}
>
> #Comment: Obviously no rewrite issue, however content type problem is there
>
> #LOG:
> [Mon, 10 Jan 2011 22:21:24 GMT] [debug] [<0.11220.3>] 'POST'
> /test/randomid432432 {1,1}
> Headers: [{'Accept',"*/*"},
>          {'Content-Length',"23"},
>          {'Content-Type',"application/json"},
>          {'Host',"localhost:5984"},
>          {'Referer',"http://localhost:5984/test"},
>          {'User-Agent',"curl/7.21.0 (i686-pc-linux-gnu) libcurl/7.21.0
> OpenSSL/0.9.8o zlib/1.2.3.4 libidn/1.18"}]
>
> [Mon, 10 Jan 2011 22:21:24 GMT] [debug] [<0.11220.3>] OAuth Params: []
>
> [Mon, 10 Jan 2011 22:21:24 GMT] [debug] [<0.11220.3>] Minor error in HTTP
> request: {bad_ctype,
>                                 "Content-Type must be multipart/form-data"}
>
> [Mon, 10 Jan 2011 22:21:24 GMT] [debug] [<0.11220.3>] Stacktrace:
> [{couch_httpd,validate_ctype,2},
>             {couch_httpd_db,db_doc_req,3},
>             {couch_httpd_db,do_db_req,2},
>             {couch_httpd,handle_request_int,5},
>             {mochiweb_http,headers,5},
>             {proc_lib,init_p_do_apply,3}]
>
> [Mon, 10 Jan 2011 22:21:24 GMT] [info] [<0.11220.3>] 127.0.0.1 - - 'POST'
> /test/randomid432432 415
>
> [Mon, 10 Jan 2011 22:21:24 GMT] [debug] [<0.11220.3>] httpd 415 error
> response:
>  {"error":"bad_content_type","reason":"Content-Type must be
> multipart/form-data"}
>
>
>
> Apparently these are two different issues.
>
> First handling of rewrites for POST requests and the second is the problem
> with Content types?
>
> Also I would be extremely happy to find out what are more exact rules for
> pattern matching? I have found this site (
> http://caolanmcmahon.com/on_designs_undocumented.html) which provides some
> answers. I have also read somewhere that rewriting is basically Erlang
> pattern matching ... so should I read up more about the topic in Erlang
> documentation?
>
> There is also a question I have that wasn't answered anywhere - is it
> possible for multiple rewrites to apply to single request? If so what is the
> precedence? If not - what is the precedence in that case.
>
> Thank you for any response.
>
> Kind regards, -Janez
>
> On Thu, Jan 13, 2011 at 8:21 AM, Benoit Chesneau <bc...@gmail.com>wrote:
>
>> did you try to add:
>>
>> {
>>
>> "from": ":db",
>> "to": "../.."
>> }
>>
>> ?
>>
>> - benoît
>>
>> On Mon, Jan 10, 2011 at 6:21 PM, Janez Štupar <ja...@gmail.com>
>> wrote:
>> > Here is the problem I'm currently dabbling around with Sofa (got it from
>> > jchrisa's Github)... To this end I'm reverse engineering it and trying to
>> > get it work in a following scenario:
>> >
>> > The database is hidden behind following VHost: sofa.mycouch  ->
>> > /sofa/_design/sofa/_rewrite
>> >
>> > Since I wanted to improve the appearance of the URL's I also did some
>> > modifications to the rewrites, my current configuration is as follows:
>> >
>> > [
>> >   {
>> >       "to": "_list/index/recent-posts",
>> >       "from": "blog/",
>> >       "query": {
>> >           "limit": 10,
>> >           "descending": true
>> >       }
>> >   },
>> >   {
>> >       "to": "_list/:listname/*",
>> >       "from": "list/:listname/*",
>> >       "query": {
>> >           "limit": 10,
>> >           "descending": true
>> >       }
>> >   },
>> >   {
>> >        "to" : "_show/:showname/*",
>> >        "from" : "show/:showname/*"
>> >   },
>> >   {
>> >         "to" : "_update/:updatename/*",
>> >         "from" : "update/:updatename/*"
>> >   },
>> >   {
>> >       "to": "_list/index/recent-posts",
>> >       "from": "",
>> >       "query": {
>> >           "limit": 10,
>> >           "descending": true
>> >       }
>> >   },
>> >   {
>> >       "to": "script/*",
>> >       "from": "script/*"
>> >   },
>> >   {
>> >       "to": "style/*",
>> >       "from": "style/*"
>> >   },
>> >   {
>> >       "to": "vendor/*",
>> >       "from": "vendor/*"
>> >   },
>> >   {
>> >    "to": "../../*",
>> >    "from": ":db/*"
>> >   }
>> > ]
>> >
>> > The last problem I have left is that although everything works (I have
>> > indeed done some modifications to the templates, pathing function, etc..
>> > nothing relevant to this current issue IMHO).
>> > *
>> > Except* one thing doesn't work as expected ... that is posting comments.
>> I
>> > have kinda narrowed it down that when the browser sends a new blog post
>> it
>> > does PUT to address: '"/sofa/_design/sofa/_rewrite/sofa/spet-nov-post"'
>> > (spet-nov-post is a _id - according to jquery.couch.js)
>> >
>> > While comment gets POST -ed to following URL:
>> > '"/sofa/_design/sofa/_rewrite/sofa/"'
>> >
>> > what happens in the rewriter is following:
>> >
>> > 'PUT' /sofa/_design/sofa/_rewrite/sofa/spet-nov-post {1,1} -> 'PUT'
>> > /sofa/spet-nov-post?db=sofa {1,1}
>> > 'POST' /sofa/_design/sofa/_rewrite/sofa/ {1,1}  -> 'POST'
>> > /sofa/_design/..?db=sofa {1,1}
>> >
>> > I blame the following rewrite rule:
>> >   {
>> >    "to": "../../*",
>> >    "from": ":db/*"
>> >   }
>> >
>>
>
So using 2 rewrites rules work right ? (That what I suggested). For
content-type This is something expected i think. Will re-read this
separate issue later. Headers are not rewritten anyway.

- benoît

Re: Strange issue with VHosts and rewrites...

Posted by Janez Štupar <ja...@gmail.com>.
Benoît, I did what you proposed and it behaves exactly as before

Ok i did some testing and this is what I figured out.

This is my testing setup: I created a new database (test) that doesn't use
any VHost rules.

Inside it I created a design document that only has rewrites field. I will
present test results exactly as per configuration I used.

I always sent the same document contained in file "example" - namely:
{
    "type": "comment"
}

Below are the test results:
----------------------------------------------------------------------------------------------------
## Test 1:
# rewrites config:
[
   {
       "to": "../..",
       "from": ":db"
   }
]

# Executed command 1.1:
$ curl  -d @example -H "Content-type:application/json" -e
http://localhost:5984/test  http://localhost:5984/test/
{"ok":true,"id":"ce8b504d63666c9257cc07537c00aa70","rev":"1-505a221d0aef5d664f29d6afdae01293"}

# Comment: expected result - everything is fine.



# Executed command 1.2:
$ curl -X PUT  -d @example -H "Content-type:application/json"
http://localhost:5984/test/_design/test/_rewrite/test/randomid324324
{"error":"not_found","reason":"missing"}

# Comment: result expected since there is no ID parameter passed through -
due to the rewrite rule

#LOG:
[Mon, 10 Jan 2011 21:42:17 GMT] [debug] [<0.8844.3>] 'PUT'
/test/_design/test/_rewrite/test/randomid324324 {1,1}
Headers: [{'Accept',"*/*"},
          {'Content-Length',"23"},
          {'Content-Type',"application/json"},
          {'Host',"localhost:5984"},
          {'User-Agent',"curl/7.21.0 (i686-pc-linux-gnu) libcurl/7.21.0
OpenSSL/0.9.8o zlib/1.2.3.4 libidn/1.18"}]

[Mon, 10 Jan 2011 21:42:17 GMT] [debug] [<0.8844.3>] OAuth Params: []

[Mon, 10 Jan 2011 21:42:17 GMT] [debug] [<0.8844.3>] Minor error in HTTP
request: not_found

[Mon, 10 Jan 2011 21:42:17 GMT] [debug] [<0.8844.3>] Stacktrace:
[{couch_httpd_rewrite,handle_rewrite_req,3},
             {couch_httpd_db,do_db_req,2},
             {couch_httpd,handle_request_int,5},
             {mochiweb_http,headers,5},
             {proc_lib,init_p_do_apply,3}]

[Mon, 10 Jan 2011 21:42:17 GMT] [info] [<0.8844.3>] 127.0.0.1 - - 'PUT'
/test/_design/test/_rewrite/test/randomid324324 404

[Mon, 10 Jan 2011 21:42:17 GMT] [debug] [<0.8844.3>] httpd 404 error
response:
 {"error":"not_found","reason":"missing"}




# Executed command 1.3:
$curl  -d @example -H "Content-type:application/json" -e
http://localhost:5984/test
http://localhost:5984/test/_design/test/_rewrite/test/
{"error":"bad_content_type","reason":"Content-Type must be
multipart/form-data"}

# Comment: Rewrite is wrong - also peculiar it won't take application/json
content type.

# LOG:
[Mon, 10 Jan 2011 21:51:55 GMT] [debug] [<0.9453.3>] 'POST'
/test/_design/test/_rewrite/test/ {1,1}
Headers: [{'Accept',"*/*"},
          {'Content-Length',"23"},
          {'Content-Type',"application/json"},
          {'Host',"localhost:5984"},
          {'Referer',"http://localhost:5984/test"},
          {'User-Agent',"curl/7.21.0 (i686-pc-linux-gnu) libcurl/7.21.0
OpenSSL/0.9.8o zlib/1.2.3.4 libidn/1.18"}]

[Mon, 10 Jan 2011 21:51:55 GMT] [debug] [<0.9453.3>] OAuth Params: []

[Mon, 10 Jan 2011 21:51:55 GMT] [debug] [<0.9453.3>] rewrite to
"/test/_design/..?db=test"


[Mon, 10 Jan 2011 21:51:55 GMT] [debug] [<0.9453.3>] 'POST'
/test/_design/..?db=test {1,1}
Headers: [{'Accept',"*/*"},
          {'Content-Length',"23"},
          {'Content-Type',"application/json"},
          {'Host',"localhost:5984"},
          {'Referer',"http://localhost:5984/test"},
          {'User-Agent',"curl/7.21.0 (i686-pc-linux-gnu) libcurl/7.21.0
OpenSSL/0.9.8o zlib/1.2.3.4 libidn/1.18"}]

[Mon, 10 Jan 2011 21:51:55 GMT] [debug] [<0.9453.3>] OAuth Params:
[{"db","test"}]

[Mon, 10 Jan 2011 21:51:55 GMT] [debug] [<0.9453.3>] Minor error in HTTP
request: {bad_ctype,
                                 "Content-Type must be multipart/form-data"}

[Mon, 10 Jan 2011 21:51:55 GMT] [debug] [<0.9453.3>] Stacktrace:
[{couch_httpd,validate_ctype,2},
             {couch_httpd_db,db_doc_req,3},
             {couch_httpd_db,do_db_req,2},
             {couch_httpd,handle_request_int,5},
             {couch_httpd_db,do_db_req,2},
             {couch_httpd,handle_request_int,5},
             {mochiweb_http,headers,5},
             {proc_lib,init_p_do_apply,3}]

[Mon, 10 Jan 2011 21:51:55 GMT] [info] [<0.9453.3>] 127.0.0.1 - - 'POST'
/test/_design/..?db=test 415

[Mon, 10 Jan 2011 21:51:55 GMT] [debug] [<0.9453.3>] httpd 415 error
response:
 {"error":"bad_content_type","reason":"Content-Type must be
multipart/form-data"}



# Executed command 1.4:
$ curl  -d @example -H "Content-type:application/json" -e
http://localhost:5984/test  http://localhost:5984/test/randomid32420
{"error":"bad_content_type","reason":"Content-Type must be
multipart/form-data"}

# Comment: I did this one just because - and I noticed that when you post
with and ID - it wont accept JSON content type

# LOG:
[Mon, 10 Jan 2011 21:54:23 GMT] [debug] [<0.9490.3>] 'POST'
/test/randomid32420 {1,1}
Headers: [{'Accept',"*/*"},
          {'Content-Length',"23"},
          {'Content-Type',"application/json"},
          {'Host',"localhost:5984"},
          {'Referer',"http://localhost:5984/test"},
          {'User-Agent',"curl/7.21.0 (i686-pc-linux-gnu) libcurl/7.21.0
OpenSSL/0.9.8o zlib/1.2.3.4 libidn/1.18"}]

[Mon, 10 Jan 2011 21:54:23 GMT] [debug] [<0.9490.3>] OAuth Params: []

[Mon, 10 Jan 2011 21:54:23 GMT] [debug] [<0.9490.3>] Minor error in HTTP
request: {bad_ctype,
                                 "Content-Type must be multipart/form-data"}

[Mon, 10 Jan 2011 21:54:23 GMT] [debug] [<0.9490.3>] Stacktrace:
[{couch_httpd,validate_ctype,2},
             {couch_httpd_db,db_doc_req,3},
             {couch_httpd_db,do_db_req,2},
             {couch_httpd,handle_request_int,5},
             {mochiweb_http,headers,5},
             {proc_lib,init_p_do_apply,3}]

[Mon, 10 Jan 2011 21:54:23 GMT] [info] [<0.9490.3>] 127.0.0.1 - - 'POST'
/test/randomid32420 415

[Mon, 10 Jan 2011 21:54:23 GMT] [debug] [<0.9490.3>] httpd 415 error
response:
 {"error":"bad_content_type","reason":"Content-Type must be
multipart/form-data"}



----------------------------------------------------------------------------------------------------


## Test 2:

# Rewrites config:
[
   {
       "to": "../../*",
       "from": ":db/*"
   }
]

# Executed command 2.1:
$ curl  -d @example -H "Content-type:application/json" -e
http://localhost:5984/test  http://localhost:5984/test/
{"ok":true,"id":"ce8b504d63666c9257cc07537c00af99","rev":"1-505a221d0aef5d664f29d6afdae01293"}

# Comment: OK, everything is fine



#Executed command 2.2:
$ curl -X PUT  -d @example -H "Content-type:application/json"
http://localhost:5984/test/_design/test/_rewrite/test/randomid3125
{"ok":true,"id":"randomid3125","rev":"1-505a221d0aef5d664f29d6afdae01293"}

# Comment: OK, everything is fine - since now rewrite rule appropriately
handles the ID.


#Executed command 2.3:
$ curl  -d @example -H "Content-type:application/json" -e
http://localhost:5984/test
http://localhost:5984/test/_design/test/_rewrite/test/
{"error":"bad_content_type","reason":"Content-Type must be
multipart/form-data"}

# Comment: Routing and content type are wrong (routing in PUT request -
command 2.2 was done right!)

# LOG:
[Mon, 10 Jan 2011 22:06:17 GMT] [debug] [<0.10262.3>] 'POST'
/test/_design/test/_rewrite/test/ {1,1}
Headers: [{'Accept',"*/*"},
          {'Content-Length',"23"},
          {'Content-Type',"application/json"},
          {'Host',"localhost:5984"},
          {'Referer',"http://localhost:5984/test"},
          {'User-Agent',"curl/7.21.0 (i686-pc-linux-gnu) libcurl/7.21.0
OpenSSL/0.9.8o zlib/1.2.3.4 libidn/1.18"}]

[Mon, 10 Jan 2011 22:06:17 GMT] [debug] [<0.10262.3>] OAuth Params: []

[Mon, 10 Jan 2011 22:06:17 GMT] [debug] [<0.10262.3>] rewrite to
"/test/_design/..?db=test"


[Mon, 10 Jan 2011 22:06:17 GMT] [debug] [<0.10262.3>] 'POST'
/test/_design/..?db=test {1,1}
Headers: [{'Accept',"*/*"},
          {'Content-Length',"23"},
          {'Content-Type',"application/json"},
          {'Host',"localhost:5984"},
          {'Referer',"http://localhost:5984/test"},
          {'User-Agent',"curl/7.21.0 (i686-pc-linux-gnu) libcurl/7.21.0
OpenSSL/0.9.8o zlib/1.2.3.4 libidn/1.18"}]

[Mon, 10 Jan 2011 22:06:17 GMT] [debug] [<0.10262.3>] OAuth Params:
[{"db","test"}]

[Mon, 10 Jan 2011 22:06:17 GMT] [debug] [<0.10262.3>] Minor error in HTTP
request: {bad_ctype,
                                 "Content-Type must be multipart/form-data"}

[Mon, 10 Jan 2011 22:06:17 GMT] [debug] [<0.10262.3>] Stacktrace:
[{couch_httpd,validate_ctype,2},
             {couch_httpd_db,db_doc_req,3},
             {couch_httpd_db,do_db_req,2},
             {couch_httpd,handle_request_int,5},
             {couch_httpd_db,do_db_req,2},
             {couch_httpd,handle_request_int,5},
             {mochiweb_http,headers,5},
             {proc_lib,init_p_do_apply,3}]

[Mon, 10 Jan 2011 22:06:17 GMT] [info] [<0.10262.3>] 127.0.0.1 - - 'POST'
/test/_design/..?db=test 415

[Mon, 10 Jan 2011 22:06:17 GMT] [debug] [<0.10262.3>] httpd 415 error
response:
 {"error":"bad_content_type","reason":"Content-Type must be
multipart/form-data"}


#Executed command 2.4:
$ curl  -d @example -H "Content-type:application/json" -e
http://localhost:5984/test  http://localhost:5984/test/randomid32843
{"error":"bad_content_type","reason":"Content-Type must be
multipart/form-data"}

#Comment: No routing information in log, got Cotent type error.

#LOG:
[Mon, 10 Jan 2011 22:11:53 GMT] [debug] [<0.10377.3>] 'POST'
/test/randomid32843 {1,1}
Headers: [{'Accept',"*/*"},
          {'Content-Length',"23"},
          {'Content-Type',"application/json"},
          {'Host',"localhost:5984"},
          {'Referer',"http://localhost:5984/test"},
          {'User-Agent',"curl/7.21.0 (i686-pc-linux-gnu) libcurl/7.21.0
OpenSSL/0.9.8o zlib/1.2.3.4 libidn/1.18"}]

[Mon, 10 Jan 2011 22:11:53 GMT] [debug] [<0.10377.3>] OAuth Params: []

[Mon, 10 Jan 2011 22:11:53 GMT] [debug] [<0.10377.3>] Minor error in HTTP
request: {bad_ctype,
                                 "Content-Type must be multipart/form-data"}

[Mon, 10 Jan 2011 22:11:53 GMT] [debug] [<0.10377.3>] Stacktrace:
[{couch_httpd,validate_ctype,2},
             {couch_httpd_db,db_doc_req,3},
             {couch_httpd_db,do_db_req,2},
             {couch_httpd,handle_request_int,5},
             {mochiweb_http,headers,5},
             {proc_lib,init_p_do_apply,3}]

[Mon, 10 Jan 2011 22:11:53 GMT] [info] [<0.10377.3>] 127.0.0.1 - - 'POST'
/test/randomid32843 415

[Mon, 10 Jan 2011 22:11:53 GMT] [debug] [<0.10377.3>] httpd 415 error
response:
 {"error":"bad_content_type","reason":"Content-Type must be
multipart/form-data"}

----------------------------------------------------------------------------------------------------


## Test 3:

# Rewrites config:
[
   {
       "to": "../../*",
       "from": ":db/*"
   },
   {
       "to": "../..",
       "from": ":db"
   }
]


# Executed command 3.1:
$ curl  -d @example -H "Content-type:application/json" -e
http://localhost:5984/test  http://localhost:5984/test/
{"ok":true,"id":"ce8b504d63666c9257cc07537c00bbe3","rev":"1-505a221d0aef5d664f29d6afdae01293"}

# Comment: OK! works as expected



#Executed command 3.2:
$ curl -X PUT  -d @example -H "Content-type:application/json"
http://localhost:5984/test/_design/test/_rewrite/test/randomid43242
{"ok":true,"id":"randomid43242","rev":"1-505a221d0aef5d664f29d6afdae01293"}

# Comment: OK! works as expected


#Executed command 3.3:
$ curl  -d @example -H "Content-type:application/json" -e
http://localhost:5984/test
http://localhost:5984/test/_design/test/_rewrite/test/
{"error":"bad_content_type","reason":"Content-Type must be
multipart/form-data"}

# Comment: Rewrite issue and content type issue

# LOG:
[Mon, 10 Jan 2011 22:19:55 GMT] [debug] [<0.11199.3>] 'POST'
/test/_design/test/_rewrite/test/ {1,1}
Headers: [{'Accept',"*/*"},
          {'Content-Length',"23"},
          {'Content-Type',"application/json"},
          {'Host',"localhost:5984"},
          {'Referer',"http://localhost:5984/test"},
          {'User-Agent',"curl/7.21.0 (i686-pc-linux-gnu) libcurl/7.21.0
OpenSSL/0.9.8o zlib/1.2.3.4 libidn/1.18"}]

[Mon, 10 Jan 2011 22:19:55 GMT] [debug] [<0.11199.3>] OAuth Params: []

[Mon, 10 Jan 2011 22:19:55 GMT] [debug] [<0.11199.3>] rewrite to
"/test/_design/..?db=test"


[Mon, 10 Jan 2011 22:19:55 GMT] [debug] [<0.11199.3>] 'POST'
/test/_design/..?db=test {1,1}
Headers: [{'Accept',"*/*"},
          {'Content-Length',"23"},
          {'Content-Type',"application/json"},
          {'Host',"localhost:5984"},
          {'Referer',"http://localhost:5984/test"},
          {'User-Agent',"curl/7.21.0 (i686-pc-linux-gnu) libcurl/7.21.0
OpenSSL/0.9.8o zlib/1.2.3.4 libidn/1.18"}]

[Mon, 10 Jan 2011 22:19:55 GMT] [debug] [<0.11199.3>] OAuth Params:
[{"db","test"}]

[Mon, 10 Jan 2011 22:19:55 GMT] [debug] [<0.11199.3>] Minor error in HTTP
request: {bad_ctype,
                                 "Content-Type must be multipart/form-data"}

[Mon, 10 Jan 2011 22:19:55 GMT] [debug] [<0.11199.3>] Stacktrace:
[{couch_httpd,validate_ctype,2},
             {couch_httpd_db,db_doc_req,3},
             {couch_httpd_db,do_db_req,2},
             {couch_httpd,handle_request_int,5},
             {couch_httpd_db,do_db_req,2},
             {couch_httpd,handle_request_int,5},
             {mochiweb_http,headers,5},
             {proc_lib,init_p_do_apply,3}]

[Mon, 10 Jan 2011 22:19:55 GMT] [info] [<0.11199.3>] 127.0.0.1 - - 'POST'
/test/_design/..?db=test 415

[Mon, 10 Jan 2011 22:19:55 GMT] [debug] [<0.11199.3>] httpd 415 error
response:
 {"error":"bad_content_type","reason":"Content-Type must be
multipart/form-data"}


#Executed command 3.4:
$  curl  -d @example -H "Content-type:application/json" -e
http://localhost:5984/test  http://localhost:5984/test/randomid432432
{"error":"bad_content_type","reason":"Content-Type must be
multipart/form-data"}

#Comment: Obviously no rewrite issue, however content type problem is there

#LOG:
[Mon, 10 Jan 2011 22:21:24 GMT] [debug] [<0.11220.3>] 'POST'
/test/randomid432432 {1,1}
Headers: [{'Accept',"*/*"},
          {'Content-Length',"23"},
          {'Content-Type',"application/json"},
          {'Host',"localhost:5984"},
          {'Referer',"http://localhost:5984/test"},
          {'User-Agent',"curl/7.21.0 (i686-pc-linux-gnu) libcurl/7.21.0
OpenSSL/0.9.8o zlib/1.2.3.4 libidn/1.18"}]

[Mon, 10 Jan 2011 22:21:24 GMT] [debug] [<0.11220.3>] OAuth Params: []

[Mon, 10 Jan 2011 22:21:24 GMT] [debug] [<0.11220.3>] Minor error in HTTP
request: {bad_ctype,
                                 "Content-Type must be multipart/form-data"}

[Mon, 10 Jan 2011 22:21:24 GMT] [debug] [<0.11220.3>] Stacktrace:
[{couch_httpd,validate_ctype,2},
             {couch_httpd_db,db_doc_req,3},
             {couch_httpd_db,do_db_req,2},
             {couch_httpd,handle_request_int,5},
             {mochiweb_http,headers,5},
             {proc_lib,init_p_do_apply,3}]

[Mon, 10 Jan 2011 22:21:24 GMT] [info] [<0.11220.3>] 127.0.0.1 - - 'POST'
/test/randomid432432 415

[Mon, 10 Jan 2011 22:21:24 GMT] [debug] [<0.11220.3>] httpd 415 error
response:
 {"error":"bad_content_type","reason":"Content-Type must be
multipart/form-data"}



Apparently these are two different issues.

First handling of rewrites for POST requests and the second is the problem
with Content types?

Also I would be extremely happy to find out what are more exact rules for
pattern matching? I have found this site (
http://caolanmcmahon.com/on_designs_undocumented.html) which provides some
answers. I have also read somewhere that rewriting is basically Erlang
pattern matching ... so should I read up more about the topic in Erlang
documentation?

There is also a question I have that wasn't answered anywhere - is it
possible for multiple rewrites to apply to single request? If so what is the
precedence? If not - what is the precedence in that case.

Thank you for any response.

Kind regards, -Janez

On Thu, Jan 13, 2011 at 8:21 AM, Benoit Chesneau <bc...@gmail.com>wrote:

> did you try to add:
>
> {
>
> "from": ":db",
> "to": "../.."
> }
>
> ?
>
> - benoît
>
> On Mon, Jan 10, 2011 at 6:21 PM, Janez Štupar <ja...@gmail.com>
> wrote:
> > Here is the problem I'm currently dabbling around with Sofa (got it from
> > jchrisa's Github)... To this end I'm reverse engineering it and trying to
> > get it work in a following scenario:
> >
> > The database is hidden behind following VHost: sofa.mycouch  ->
> > /sofa/_design/sofa/_rewrite
> >
> > Since I wanted to improve the appearance of the URL's I also did some
> > modifications to the rewrites, my current configuration is as follows:
> >
> > [
> >   {
> >       "to": "_list/index/recent-posts",
> >       "from": "blog/",
> >       "query": {
> >           "limit": 10,
> >           "descending": true
> >       }
> >   },
> >   {
> >       "to": "_list/:listname/*",
> >       "from": "list/:listname/*",
> >       "query": {
> >           "limit": 10,
> >           "descending": true
> >       }
> >   },
> >   {
> >        "to" : "_show/:showname/*",
> >        "from" : "show/:showname/*"
> >   },
> >   {
> >         "to" : "_update/:updatename/*",
> >         "from" : "update/:updatename/*"
> >   },
> >   {
> >       "to": "_list/index/recent-posts",
> >       "from": "",
> >       "query": {
> >           "limit": 10,
> >           "descending": true
> >       }
> >   },
> >   {
> >       "to": "script/*",
> >       "from": "script/*"
> >   },
> >   {
> >       "to": "style/*",
> >       "from": "style/*"
> >   },
> >   {
> >       "to": "vendor/*",
> >       "from": "vendor/*"
> >   },
> >   {
> >    "to": "../../*",
> >    "from": ":db/*"
> >   }
> > ]
> >
> > The last problem I have left is that although everything works (I have
> > indeed done some modifications to the templates, pathing function, etc..
> > nothing relevant to this current issue IMHO).
> > *
> > Except* one thing doesn't work as expected ... that is posting comments.
> I
> > have kinda narrowed it down that when the browser sends a new blog post
> it
> > does PUT to address: '"/sofa/_design/sofa/_rewrite/sofa/spet-nov-post"'
> > (spet-nov-post is a _id - according to jquery.couch.js)
> >
> > While comment gets POST -ed to following URL:
> > '"/sofa/_design/sofa/_rewrite/sofa/"'
> >
> > what happens in the rewriter is following:
> >
> > 'PUT' /sofa/_design/sofa/_rewrite/sofa/spet-nov-post {1,1} -> 'PUT'
> > /sofa/spet-nov-post?db=sofa {1,1}
> > 'POST' /sofa/_design/sofa/_rewrite/sofa/ {1,1}  -> 'POST'
> > /sofa/_design/..?db=sofa {1,1}
> >
> > I blame the following rewrite rule:
> >   {
> >    "to": "../../*",
> >    "from": ":db/*"
> >   }
> >
>

Re: Strange issue with VHosts and rewrites...

Posted by Benoit Chesneau <bc...@gmail.com>.
did you try to add:

{

"from": ":db",
"to": "../.."
}

?

- benoît

On Mon, Jan 10, 2011 at 6:21 PM, Janez Štupar <ja...@gmail.com> wrote:
> Here is the problem I'm currently dabbling around with Sofa (got it from
> jchrisa's Github)... To this end I'm reverse engineering it and trying to
> get it work in a following scenario:
>
> The database is hidden behind following VHost: sofa.mycouch  ->
> /sofa/_design/sofa/_rewrite
>
> Since I wanted to improve the appearance of the URL's I also did some
> modifications to the rewrites, my current configuration is as follows:
>
> [
>   {
>       "to": "_list/index/recent-posts",
>       "from": "blog/",
>       "query": {
>           "limit": 10,
>           "descending": true
>       }
>   },
>   {
>       "to": "_list/:listname/*",
>       "from": "list/:listname/*",
>       "query": {
>           "limit": 10,
>           "descending": true
>       }
>   },
>   {
>        "to" : "_show/:showname/*",
>        "from" : "show/:showname/*"
>   },
>   {
>         "to" : "_update/:updatename/*",
>         "from" : "update/:updatename/*"
>   },
>   {
>       "to": "_list/index/recent-posts",
>       "from": "",
>       "query": {
>           "limit": 10,
>           "descending": true
>       }
>   },
>   {
>       "to": "script/*",
>       "from": "script/*"
>   },
>   {
>       "to": "style/*",
>       "from": "style/*"
>   },
>   {
>       "to": "vendor/*",
>       "from": "vendor/*"
>   },
>   {
>    "to": "../../*",
>    "from": ":db/*"
>   }
> ]
>
> The last problem I have left is that although everything works (I have
> indeed done some modifications to the templates, pathing function, etc..
> nothing relevant to this current issue IMHO).
> *
> Except* one thing doesn't work as expected ... that is posting comments. I
> have kinda narrowed it down that when the browser sends a new blog post it
> does PUT to address: '"/sofa/_design/sofa/_rewrite/sofa/spet-nov-post"'
> (spet-nov-post is a _id - according to jquery.couch.js)
>
> While comment gets POST -ed to following URL:
> '"/sofa/_design/sofa/_rewrite/sofa/"'
>
> what happens in the rewriter is following:
>
> 'PUT' /sofa/_design/sofa/_rewrite/sofa/spet-nov-post {1,1} -> 'PUT'
> /sofa/spet-nov-post?db=sofa {1,1}
> 'POST' /sofa/_design/sofa/_rewrite/sofa/ {1,1}  -> 'POST'
> /sofa/_design/..?db=sofa {1,1}
>
> I blame the following rewrite rule:
>   {
>    "to": "../../*",
>    "from": ":db/*"
>   }
>

Re: Strange issue with VHosts and rewrites...

Posted by feiman <lf...@gmail.com>.
unsubscribe

2011/1/11 Janez Štupar <ja...@gmail.com>

> Here is the problem I'm currently dabbling around with Sofa (got it from
> jchrisa's Github)... To this end I'm reverse engineering it and trying to
> get it work in a following scenario:
>
> The database is hidden behind following VHost: sofa.mycouch  ->
> /sofa/_design/sofa/_rewrite
>
> Since I wanted to improve the appearance of the URL's I also did some
> modifications to the rewrites, my current configuration is as follows:
>
> [
>   {
>       "to": "_list/index/recent-posts",
>       "from": "blog/",
>       "query": {
>           "limit": 10,
>           "descending": true
>       }
>   },
>   {
>       "to": "_list/:listname/*",
>       "from": "list/:listname/*",
>       "query": {
>           "limit": 10,
>           "descending": true
>       }
>   },
>   {
>        "to" : "_show/:showname/*",
>        "from" : "show/:showname/*"
>   },
>   {
>         "to" : "_update/:updatename/*",
>         "from" : "update/:updatename/*"
>   },
>   {
>       "to": "_list/index/recent-posts",
>       "from": "",
>       "query": {
>           "limit": 10,
>           "descending": true
>       }
>   },
>   {
>       "to": "script/*",
>       "from": "script/*"
>   },
>   {
>       "to": "style/*",
>       "from": "style/*"
>   },
>   {
>       "to": "vendor/*",
>       "from": "vendor/*"
>   },
>   {
>    "to": "../../*",
>    "from": ":db/*"
>   }
> ]
>
> The last problem I have left is that although everything works (I have
> indeed done some modifications to the templates, pathing function, etc..
> nothing relevant to this current issue IMHO).
> *
> Except* one thing doesn't work as expected ... that is posting comments. I
> have kinda narrowed it down that when the browser sends a new blog post it
> does PUT to address: '"/sofa/_design/sofa/_rewrite/sofa/spet-nov-post"'
> (spet-nov-post is a _id - according to jquery.couch.js)
>
> While comment gets POST -ed to following URL:
> '"/sofa/_design/sofa/_rewrite/sofa/"'
>
> what happens in the rewriter is following:
>
> 'PUT' /sofa/_design/sofa/_rewrite/sofa/spet-nov-post {1,1} -> 'PUT'
> /sofa/spet-nov-post?db=sofa {1,1}
> 'POST' /sofa/_design/sofa/_rewrite/sofa/ {1,1}  -> 'POST'
> /sofa/_design/..?db=sofa {1,1}
>
> I blame the following rewrite rule:
>   {
>    "to": "../../*",
>    "from": ":db/*"
>   }
>
> What is a mistery to me is why does the first request get rewritten
> correctly and the second not? AFAIK the second should come out as: 'POST'
> /sofa/?db=sofa {1,1}
>
> Below are the relevant logs -> The first is from new post creation (the PUT
> request), the other is from comment creation (the POST request).
>
> *First:
> *[Sat, 08 Jan 2011 20:27:40 GMT] [debug] [<0.785.0>] Vhost Target:
> '"/sofa/_design/sofa/_rewrite/sofa/spet-nov-post"'
>
>
> [Sat, 08 Jan 2011 20:27:40 GMT] [debug] [<0.785.0>] 'PUT'
> /sofa/_design/sofa/_rewrite/sofa/spet-nov-post {1,1}
> Headers: [{'Accept',"application/json, text/javascript, */*"},
>          {'Accept-Charset',"UTF-8,*"},
>          {'Accept-Encoding',"gzip,deflate"},
>          {'Accept-Language',"en,sl;q=0.7,en-us;q=0.3"},
>          {'Connection',"keep-alive"},
>          {'Content-Length',"169"},
>          {'Content-Type',"application/json; charset=UTF-8"},
>
>
> {'Cookie',"AuthSession=Y291Y2hkYjo0RDI4Qzg3MTqTKp7crPdUFEbZrfJh-EiPaxh2tA"},
>          {'Host',"sofa.mycouch"},
>          {'Keep-Alive',"115"},
>          {'Referer',"http://sofa.mycouch/show/edit/"},
>          {'User-Agent',"Mozilla/5.0 (Windows; U; Windows NT 6.1; sl;
> rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12 ( .NET CLR 3.5.30729;
> .NET4.0C)"},
>          {"X-Requested-With","XMLHttpRequest"}]
>
> [Sat, 08 Jan 2011 20:27:40 GMT] [debug] [<0.785.0>] OAuth Params: []
>
> [Sat, 08 Jan 2011 20:27:40 GMT] [debug] [<0.785.0>] timeout 600
>
> [Sat, 08 Jan 2011 20:27:40 GMT] [debug] [<0.785.0>] Successful cookie auth
> as: "couchdb"
>
> [Sat, 08 Jan 2011 20:27:40 GMT] [debug] [<0.785.0>] rewrite to
> "/sofa/spet-nov-post?db=sofa"
>
>
> [Sat, 08 Jan 2011 20:27:40 GMT] [debug] [<0.785.0>] 'PUT'
> /sofa/spet-nov-post?db=sofa {1,1}
> Headers: [{'Accept',"application/json, text/javascript, */*"},
>          {'Accept-Charset',"UTF-8,*"},
>          {'Accept-Encoding',"gzip,deflate"},
>          {'Accept-Language',"en,sl;q=0.7,en-us;q=0.3"},
>          {'Connection',"keep-alive"},
>          {'Content-Length',"169"},
>          {'Content-Type',"application/json; charset=UTF-8"},
>
>
> {'Cookie',"AuthSession=Y291Y2hkYjo0RDI4Qzg3MTqTKp7crPdUFEbZrfJh-EiPaxh2tA"},
>          {'Host',"sofa.mycouch"},
>          {'Keep-Alive',"115"},
>          {'Referer',"http://sofa.mycouch/show/edit/"},
>          {'User-Agent',"Mozilla/5.0 (Windows; U; Windows NT 6.1; sl;
> rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12 ( .NET CLR 3.5.30729;
> .NET4.0C)"},
>          {"X-Requested-With","XMLHttpRequest"}]
>
> [Sat, 08 Jan 2011 20:27:40 GMT] [debug] [<0.785.0>] OAuth Params:
> [{"db","sofa"}]
>
> [Sat, 08 Jan 2011 20:27:40 GMT] [debug] [<0.785.0>] timeout 600
>
> [Sat, 08 Jan 2011 20:27:40 GMT] [debug] [<0.785.0>] Successful cookie auth
> as: "couchdb"
>
> [Sat, 08 Jan 2011 20:27:40 GMT] [debug] [<0.93.0>] DDocProc found for
> DDocKey: {<<"_design/sofa">>,
>                             <<"119-09fa3ceca488bfc1852ea48e3a0f0921">>}
>
> [Sat, 08 Jan 2011 20:27:40 GMT] [debug] [<0.630.0>] OS Process
> #Port<0.1421>
> Input  :: ["reset",{"reduce_limit":true}]
>
> [Sat, 08 Jan 2011 20:27:40 GMT] [debug] [<0.630.0>] OS Process
> #Port<0.1421>
> Output :: true
>
>
>
> *************************************************************************************
>
> *Second:*
> [Sat, 08 Jan 2011 20:27:56 GMT] [debug] [<0.785.0>] Vhost Target:
> '"/sofa/_design/sofa/_rewrite/sofa/"'
>
>
> [Sat, 08 Jan 2011 20:27:56 GMT] [debug] [<0.785.0>] 'POST'
> /sofa/_design/sofa/_rewrite/sofa/ {1,1}
> Headers: [{'Accept',"application/json, text/javascript, */*"},
>          {'Accept-Charset',"UTF-8,*"},
>          {'Accept-Encoding',"gzip,deflate"},
>          {'Accept-Language',"en,sl;q=0.7,en-us;q=0.3"},
>          {'Cache-Control',"no-cache"},
>          {'Connection',"keep-alive"},
>          {'Content-Length',"361"},
>          {'Content-Type',"application/json; charset=UTF-8"},
>
>
> {'Cookie',"AuthSession=Y291Y2hkYjo0RDI4QzhCQzqLGFFiyeUSKgz9OniE9_g41buHoQ"},
>          {'Host',"sofa.mycouch"},
>          {'Keep-Alive',"115"},
>          {'Pragma',"no-cache"},
>          {'Referer',"
> http://sofa.mycouch/list/post/post-page?startkey=%5B%22spet-nov-post%22%5D
> "},
>          {'User-Agent',"Mozilla/5.0 (Windows; U; Windows NT 6.1; sl;
> rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12 ( .NET CLR 3.5.30729;
> .NET4.0C)"},
>          {"X-Requested-With","XMLHttpRequest"}]
>
> [Sat, 08 Jan 2011 20:27:56 GMT] [debug] [<0.785.0>] OAuth Params: []
>
> [Sat, 08 Jan 2011 20:27:56 GMT] [debug] [<0.785.0>] timeout 600
>
> [Sat, 08 Jan 2011 20:27:56 GMT] [debug] [<0.785.0>] Successful cookie auth
> as: "couchdb"
>
> [Sat, 08 Jan 2011 20:27:56 GMT] [debug] [<0.785.0>] rewrite to
> "/sofa/_design/..?db=sofa"
>
>
> [Sat, 08 Jan 2011 20:27:56 GMT] [debug] [<0.785.0>] 'POST'
> /sofa/_design/..?db=sofa {1,1}
> Headers: [{'Accept',"application/json, text/javascript, */*"},
>          {'Accept-Charset',"UTF-8,*"},
>          {'Accept-Encoding',"gzip,deflate"},
>          {'Accept-Language',"en,sl;q=0.7,en-us;q=0.3"},
>          {'Cache-Control',"no-cache"},
>          {'Connection',"keep-alive"},
>          {'Content-Length',"361"},
>          {'Content-Type',"application/json; charset=UTF-8"},
>
>
> {'Cookie',"AuthSession=Y291Y2hkYjo0RDI4QzhCQzqLGFFiyeUSKgz9OniE9_g41buHoQ"},
>          {'Host',"sofa.mycouch"},
>          {'Keep-Alive',"115"},
>          {'Pragma',"no-cache"},
>          {'Referer',"
> http://sofa.mycouch/list/post/post-page?startkey=%5B%22spet-nov-post%22%5D
> "},
>          {'User-Agent',"Mozilla/5.0 (Windows; U; Windows NT 6.1; sl;
> rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12 ( .NET CLR 3.5.30729;
> .NET4.0C)"},
>          {"X-Requested-With","XMLHttpRequest"}]
>
> [Sat, 08 Jan 2011 20:27:56 GMT] [debug] [<0.785.0>] OAuth Params:
> [{"db","sofa"}]
>
> [Sat, 08 Jan 2011 20:27:56 GMT] [debug] [<0.785.0>] timeout 600
>
> [Sat, 08 Jan 2011 20:27:56 GMT] [debug] [<0.785.0>] Successful cookie auth
> as: "couchdb"
>
> [Sat, 08 Jan 2011 20:27:56 GMT] [debug] [<0.785.0>] Minor error in HTTP
> request: {bad_ctype,
>                                 "Content-Type must be multipart/form-data"}
>