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 2010/11/29 19:49:19 UTC

Sending a redirect from a list

Hi there,

I'm trying to send a redirect from a list with the following code:

function (head, req) {
 var row = getRow();
 if (row) {
   var url = "/";   // Will be computed from row
   return {"code": 302, "headers":{ "Location": url}};
 } else {
   return({"code": 404, "body": "Not here"});
 }
}

I got an error 500 in both case, but the process output seems fine to me: 

1> [debug] [<0.1243.0>] OS Process #Port<0.1834> Output :: ["end",[{"code":302,"headers":{"Location":"/"}}]]
1> [error] [<0.936.0>] Badarg error in HTTP request

1> [debug] [<0.1243.0>] OS Process #Port<0.1834> Output :: ["end",[{"code":404,"body":"Not here"}]]
1> [error] [<0.1224.0>] Badarg error in HTTP request

I got a look at <http://wiki.apache.org/couchdb/Formatting_with_Show_and_List#Sending_a_Redirect>, however it's not very clear to me if "start" has replaced "return" in 0.10 and was replaced again by "return" in 0.11... Or maybe it's just a random use...
Anyway, I tried with "start" and I was not luckier. 

Anyone who tried to send a redirect?


Regards,

Aurélien


Re: Sending a redirect from a list

Posted by Zachary Zolton <za...@gmail.com>.
IIRC, this would require a change in the view server protocol.

Here's the prior discussion of making the change:
https://issues.apache.org/jira/browse/COUCHDB-514

On Tue, Nov 30, 2010 at 12:58 AM, Paul Davis
<pa...@gmail.com> wrote:
> On Tue, Nov 30, 2010 at 1:51 AM, Aurélien Bénel <au...@utt.fr> wrote:
>> Thanks for your answer, Paul.
>>
>>> Unfortunately, the current list behaviour doesn't allow you to modify response headers after calling getRow().
>>
>>
>> Oh, too bad...
>> Is there a plan to change this behaviour?
>>
>
> There have been suggestions to changing that API. I would currently
> rate the timescale for such a change on the order of months to a year.
> Definitely no discussions have suggested anything in the next couple
> releases.
>
> Although, an interested developer that provided patches might be able
> to seriously contract that timeline ;)
>
> HTH,
> Paul Davis
>
>>
>> Aurélien
>>
>>
>>>> I'm trying to send a redirect from a list with the following code:
>>>>
>>>> function (head, req) {
>>>>  var row = getRow();
>>>>  if (row) {
>>>>   var url = "/";   // Will be computed from row
>>>>   return {"code": 302, "headers":{ "Location": url}};
>>>>  } else {
>>>>   return({"code": 404, "body": "Not here"});
>>>>  }
>>>> }
>>
>

Re: Sending a redirect from a list

Posted by Paul Davis <pa...@gmail.com>.
On Tue, Nov 30, 2010 at 1:51 AM, Aurélien Bénel <au...@utt.fr> wrote:
> Thanks for your answer, Paul.
>
>> Unfortunately, the current list behaviour doesn't allow you to modify response headers after calling getRow().
>
>
> Oh, too bad...
> Is there a plan to change this behaviour?
>

There have been suggestions to changing that API. I would currently
rate the timescale for such a change on the order of months to a year.
Definitely no discussions have suggested anything in the next couple
releases.

Although, an interested developer that provided patches might be able
to seriously contract that timeline ;)

HTH,
Paul Davis

>
> Aurélien
>
>
>>> I'm trying to send a redirect from a list with the following code:
>>>
>>> function (head, req) {
>>>  var row = getRow();
>>>  if (row) {
>>>   var url = "/";   // Will be computed from row
>>>   return {"code": 302, "headers":{ "Location": url}};
>>>  } else {
>>>   return({"code": 404, "body": "Not here"});
>>>  }
>>> }
>

Re: Sending a redirect from a list

Posted by Aurélien Bénel <au...@utt.fr>.
Thanks for your answer, Paul.

> Unfortunately, the current list behaviour doesn't allow you to modify response headers after calling getRow(). 


Oh, too bad... 
Is there a plan to change this behaviour?


Aurélien


>> I'm trying to send a redirect from a list with the following code:
>> 
>> function (head, req) {
>>  var row = getRow();
>>  if (row) {
>>   var url = "/";   // Will be computed from row
>>   return {"code": 302, "headers":{ "Location": url}};
>>  } else {
>>   return({"code": 404, "body": "Not here"});
>>  }
>> }

Re: Sending a redirect from a list

Posted by Paul Davis <pa...@gmail.com>.
On Mon, Nov 29, 2010 at 1:49 PM, Aurélien Bénel <au...@utt.fr> wrote:
> Hi there,
>
> I'm trying to send a redirect from a list with the following code:
>
> function (head, req) {
>  var row = getRow();
>  if (row) {
>   var url = "/";   // Will be computed from row
>   return {"code": 302, "headers":{ "Location": url}};
>  } else {
>   return({"code": 404, "body": "Not here"});
>  }
> }
>
> I got an error 500 in both case, but the process output seems fine to me:
>
> 1> [debug] [<0.1243.0>] OS Process #Port<0.1834> Output :: ["end",[{"code":302,"headers":{"Location":"/"}}]]
> 1> [error] [<0.936.0>] Badarg error in HTTP request
>
> 1> [debug] [<0.1243.0>] OS Process #Port<0.1834> Output :: ["end",[{"code":404,"body":"Not here"}]]
> 1> [error] [<0.1224.0>] Badarg error in HTTP request
>
> I got a look at <http://wiki.apache.org/couchdb/Formatting_with_Show_and_List#Sending_a_Redirect>, however it's not very clear to me if "start" has replaced "return" in 0.10 and was replaced again by "return" in 0.11... Or maybe it's just a random use...
> Anyway, I tried with "start" and I was not luckier.
>
> Anyone who tried to send a redirect?
>
>
> Regards,
>
> Aurélien
>
>

Unfortunately, the current list behaviour doesn't allow you to modify
response headers after calling getRow(). This is probably what's
causing the 500, but I don't have a test handy.

Paul Davis