You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by Aurélien Bénel <au...@utt.fr> on 2014/01/08 15:31:40 UTC

HTTP redirection

Hi everybody,

On CouchDB 1.2, I wrote an HTTP redirection (in a list) that worked fine:

    start({
      code: 302,
      headers: {Location: "?by=" + normalize(req.query.by)}
    });

The same code fails on CouchDB 1.5. Would any of you know why?

I understand that “locations” are supposed to be absolute. But absolute URIs are a pain to build when you are behind a proxy… And this doesn’t explain why it worked on CouchDB 1.2.


Regards,

Aurélien


P. S. Before you ask for it, here are the logs:

[Wed, 08 Jan 2014 14:19:02 GMT] [debug] [<0.179.0>] OS Process #Port<0.3426> Output :: ["start",[],{"code":302,"headers":{"Location":"?by=MARIE CURIE”}}]
[Wed, 08 Jan 2014 14:19:02 GMT] [debug] [<0.179.0>] OS Process #Port<0.3426> Input  :: ["list_end"]
[Wed, 08 Jan 2014 14:19:02 GMT] [debug] [<0.179.0>] OS Process #Port<0.3426> Output :: ["end",[]]
[Wed, 08 Jan 2014 14:19:02 GMT] [error] [<0.13678.161>] Uncaught error in HTTP request: {error,undef}
[Wed, 08 Jan 2014 14:19:02 GMT] [info] [<0.13678.161>] Stacktrace: [{undefined,write_chunk,[[]]},
                                    {couch_httpd,last_chunk,1},
                                    {couch_mrview_show,list_cb,2},
                                    {couch_mrview,finish_fold,2},
                                    {couch_query_servers,with_ddoc_proc,2},
                                    {couch_httpd,etag_maybe,2},
                                    {couch_httpd_db,do_db_req,2},
                                    {couch_httpd,handle_request_int,5}]

Re: HTTP redirection

Posted by Aurélien Bénel <au...@utt.fr>.
>  you need to return something back, Like: (…)

>      return 'redirecting...';

Yes! That made it!

Thank you very much, Alexander!


Regards,

Aurélien


Re: HTTP redirection

Posted by Alexander Shorin <kx...@gmail.com>.
Hi,

What is you list function code? If it contains only start(...)  call,
than you need to return something back, Like:

function(head, req) {
  start({"code": 301, "headers": {"Location": "http://google.com"}});
  return 'redirecting...';
}


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


On Wed, Jan 8, 2014 at 6:31 PM, Aurélien Bénel <au...@utt.fr> wrote:
> Hi everybody,
>
> On CouchDB 1.2, I wrote an HTTP redirection (in a list) that worked fine:
>
>     start({
>       code: 302,
>       headers: {Location: "?by=" + normalize(req.query.by)}
>     });
>
> The same code fails on CouchDB 1.5. Would any of you know why?
>
> I understand that “locations” are supposed to be absolute. But absolute URIs are a pain to build when you are behind a proxy… And this doesn’t explain why it worked on CouchDB 1.2.
>
>
> Regards,
>
> Aurélien
>
>
> P. S. Before you ask for it, here are the logs:
>
> [Wed, 08 Jan 2014 14:19:02 GMT] [debug] [<0.179.0>] OS Process #Port<0.3426> Output :: ["start",[],{"code":302,"headers":{"Location":"?by=MARIE CURIE”}}]
> [Wed, 08 Jan 2014 14:19:02 GMT] [debug] [<0.179.0>] OS Process #Port<0.3426> Input  :: ["list_end"]
> [Wed, 08 Jan 2014 14:19:02 GMT] [debug] [<0.179.0>] OS Process #Port<0.3426> Output :: ["end",[]]
> [Wed, 08 Jan 2014 14:19:02 GMT] [error] [<0.13678.161>] Uncaught error in HTTP request: {error,undef}
> [Wed, 08 Jan 2014 14:19:02 GMT] [info] [<0.13678.161>] Stacktrace: [{undefined,write_chunk,[[]]},
>                                     {couch_httpd,last_chunk,1},
>                                     {couch_mrview_show,list_cb,2},
>                                     {couch_mrview,finish_fold,2},
>                                     {couch_query_servers,with_ddoc_proc,2},
>                                     {couch_httpd,etag_maybe,2},
>                                     {couch_httpd_db,do_db_req,2},
>                                     {couch_httpd,handle_request_int,5}]