Erlang Mailing Lists

Author Message

<  Erlyweb mailing list  ~  {replace,..} blocks headers from being sent

ketralnis
Posted: Tue Nov 06, 2007 4:16 pm Reply with quote
User Joined: 20 Jul 2007 Posts: 151 Location: San Francisco, CA
I have a login_controller that is addressed by its URL at /login.
Since users get confused by URLs that look like /login/login, I'd
like the 'index' function to behave just like the 'login' function.
(That is, I should be able to accept GET and POST actions at /login/
login and /login.) So I do this:

-module(login_controller).
-export([index/1,
login/1,login/2,
logout/1,
signup/1]).
index(A) -> {replace,{ewc,login,login,[A]}}.
login(A) ->
case yaws_arg:method(A) of
'GET' ->
{data,{[]}};
'POST' ->
[...]

In theory, that makes 'index' do all of the same things as 'login',
by actually {replace}ing itself with 'login'.

This seems to work, except that the controller that calls this one
(myapp_app_controller) actually calls it like this:

case Ewc of
{page,_}=Page ->
Page;
_ ->
{phased, Ewc,
fun(_Ewc, Data) ->
{ewc,
html_container,
[A1,
{ewc,
sidebar_container,
[A1,
{data, Data}]}]}
end}
end.

I do this so that I can send headers from my controller (the 'login'
controller must send set_cookie and {ewr,...}). While this works for /
login/login, trying it for /login or /login/index fails with:

ERROR erlang code crashed:
File: appmod:0
Reason: {invalid_response,
[{header,
{set_cookie,
["myapp_session",61,"5",
59,32,112,97,116,104,61,"/"]}},
{redirect_local,[[],47,"author/show/1941"]}],
"Response values other than 'data' and 'ewc' tuples must
be enclosed a 'response' tuple. In addition, subcomponents may only
return 'data' and/or 'ewc' tuples."}
Req: {http_request,'POST',{abs_path,"/login/index"},{1,1}}

This means that only the content of the {replace}d {ewc,...} has been
replaced, not the other behaviours (such as the ability to send
headers).

Is this a bug, or am I going about it all wrong?

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "erlyweb" group.
To post to this group, send email to erlyweb@googlegroups.com
To unsubscribe from this group, send email to erlyweb-unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/erlyweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Post recived from mailinglist
View user's profile Send private message AIM Address
Guest
Posted: Wed Nov 07, 2007 1:11 am Reply with quote
Guest
On Nov 6, 11:15 am, David King <dk...@ketralnis.com> wrote:
> I have a login_controller that is addressed by its URL at /login.
> Since users get confused by URLs that look like /login/login, I'd
> like the 'index' function to behave just like the 'login' function.
> (That is, I should be able to accept GET and POST actions at /login/
> login and /login.) So I do this:
>
> -module(login_controller).
> -export([index/1,
> login/1,login/2,
> logout/1,
> signup/1]).
> index(A) -> {replace,{ewc,login,login,[A]}}.
> login(A) ->
> case yaws_arg:method(A) of
> 'GET' ->
> {data,{[]}};
> 'POST' ->
> [...]
>
> In theory, that makes 'index' do all of the same things as 'login',
> by actually {replace}ing itself with 'login'.

I actually had the same problem a couple of months ago. It and other
things are discussed in this thread:

http://groups.google.com/group/erlyweb/browse_thread/thread/68535fdf10e41e9d

Scroll down until you see my post starting with "Okay, I finally
understand." That post describes the same problem you're seeing, and
Yariv's reply right after it describes the solution.

To save you time, though, it basically boils down to replace tuples
being rendered as subcomponents, which aren't allowed to return
anything but data and ewc tuples. The solution is to have index/1
call login/1 directly, rather than using a replace tuple. You'll then
have to do the same in the view code.

-Bryan


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "erlyweb" group.
To post to this group, send email to erlyweb@googlegroups.com
To unsubscribe from this group, send email to erlyweb-unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/erlyweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Post recived from mailinglist

Display posts from previous:  

All times are GMT
Page 1 of 1
This forum is locked: you cannot post, reply to, or edit topics.

Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum