[ 
https://issues.apache.org/jira/browse/COUCHDB-2204?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13940476#comment-13940476
 ] 

Benoit Chesneau commented on COUCHDB-2204:
------------------------------------------

This error is expected. How the rewriter could know that a specific parameter 
can be encoded to json or something else?

For now only views parameter can be encoded. A specific rules cn eventually 
been added to the format properties if this is something wanted. So the full 
rewrite rule would be:

{code}
{ 
        "from": "server_lib/:~name",
        "to": "_list/sub/design",
        "query": {
            "path": ["lib", ":~name" ]
        },
        "formats": { "path": "json" }
}
{code}


Would it works for you?

> rewrite of lists fail when not for key
> --------------------------------------
>
>                 Key: COUCHDB-2204
>                 URL: https://issues.apache.org/jira/browse/COUCHDB-2204
>             Project: CouchDB
>          Issue Type: Bug
>      Security Level: public(Regular issues) 
>          Components: HTTP Interface
>            Reporter: richard delorenzi
>
> I have the following fragment in rewrite.json, 
> {code:javascript|title=this rewrite.json does not work}
> { 
>       "from": "server_lib/:~name",
>       "to": "_list/sub/design",
>       "query": {
>           "path": ["lib", ":~name" ]
>       }
> }
> {code}
> when I try to fetch the page with
> {code: title=http get}
> curl  -s -D /dev/stderr -H "Accept: application/json" 
> 'http://localhost:5984/q-couch-test/_design/couch-experiment/_rewrite/server_lib/myLib'
> {code}
> I get this error
> {code: title=error}
> log error:
> [Tue, 18 Mar 2014 09:54:31 GMT] [info] [<0.5037.0>] Stacktrace: 
> [{erlang,iolist_to_binary,
>                                      [[<<"myLib">>,{[]}]],
>                                      []},
>                                  {couch_httpd_rewrite,
>                                      '-maybe_encode_bindings/1-fun-0-',2,
>                                      [{file,"couch_httpd_rewrite.erl"},
>                                       {line,453}]},
>                                  {lists,foldl,3,
>                                      [{file,"lists.erl"},{line,1197}]},
>                                  {couch_httpd_rewrite,handle_rewrite_req,3,
>                                      [{file,"couch_httpd_rewrite.erl"},
>                                       {line,147}]},
>                                  {couch_httpd_db,do_db_req,2,
>                                      
> [{file,"couch_httpd_db.erl"},{line,230}]},
>                                  {couch_httpd,handle_request_int,5,
>                                      [{file,"couch_httpd.erl"},{line,317}]},
>                                  {mochiweb_http,headers,5,
>                                      [{file,"mochiweb_http.erl"},{line,136}]},
>                                  {proc_lib,init_p_do_apply,3,
>                                      [{file,"proc_lib.erl"},{line,227}]}]
> {code}
> The bug seems to be in couch_httpd_rewrite.erl in maybe_json. It treats keys 
> specially, so we can represent keys as lists but not other query strings.
> e.g. this rewrite fragment works
> {code: javascript|title=working rewrite.json example}
>  { 
>       "from": "view/by_name/:~type",
>       "to":  "_view/all-by-name",
>       "query": { 
>           "startkey": [ ":~type", null ],
>           "endkey":   [ ":~type", {} ]
>       } 
> }
> {code}



--
This message was sent by Atlassian JIRA
(v6.2#6252)

Reply via email to