Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use Req:parse_post() with {auto_recv_body,false} ? #97

Open
egobrain opened this issue Feb 2, 2012 · 5 comments
Open

How to use Req:parse_post() with {auto_recv_body,false} ? #97

egobrain opened this issue Feb 2, 2012 · 5 comments

Comments

@egobrain
Copy link
Contributor

egobrain commented Feb 2, 2012

Some times i need to auto receive request body. For example for getting vars from "/login" POST request.
And also i need to upload big files on server and save it in special folder. (Big means > 100MB).
In this cases i need to have different post_max_size. And in first case i need to allow auto_recv_body.

Here is a part of sample code.

start(Port) ->
    misultin:start_link([{port, Port}, {auto_recv_body, false}, {loop, fun(Req) -> handle_http(Req) end}]).

stop() ->
    misultin:stop().

handle_http(Req) ->
    handle(Req:get(method), Req:resource([lowercase, urldecode]), Req).

handle('GET',["login"],Req) ->
    Req:file("login.html");
handle('POST',["login"],Req) ->
    Args = Req:parse_post(),
    case Req:get_variable("login",Args) of
    undefined ->
        Req:ok("Error. You need to login.");
    Login ->
        Req:ok("Hello, "++Login)
    end;
handle('POST',["upload_big_file"],Req) ->
    get_body_and_save_to_file(Req).

Every time I try to login using POST-request I get the message "Error. You need to login.".
Do I need to manually load each time the body of the request and process it to get the variables. Or there is a way to use parse_post() ??

@ostinelli
Copy link
Owner

why would querystring have anything to do with the body? are you experiencing an error? what are you trying to achieve?

if you ask for help you should consider an extra important 20 seconds of your life to formulate a question :)

thank you.

@egobrain
Copy link
Contributor Author

egobrain commented Feb 2, 2012

Sorry! It was my browser mistake. :(
I re posted question.

@ostinelli
Copy link
Owner

you are using Req:parse_qs, which does what it actually states: parses a QueryString.

if you want to parse a body, use the appropriate Req:parse_body method.

All of this is in examples/docs, for instance here's an example:
https://github.com/ostinelli/misultin/blob/master/examples/misultin_echo.erl#L45

Exports here:
https://github.com/ostinelli/misultin/blob/master/EXPORTS.md

Does this solve your issue?

r.

@egobrain
Copy link
Contributor Author

egobrain commented Feb 3, 2012

That's really hard to write question after vocation.
Of course it's my mistake. Not Req:parse_qs(), but Req:parse_post().
But using parse_post() doesn't solve my issue.

I'm looking for some function like Req:get_body(post_max_size). Which will automatically upload body of request, ignoring {auto_recv_body,false}.

@ostinelli ostinelli reopened this Feb 3, 2012
@ostinelli
Copy link
Owner

thank you for this.

misultin has been discontinued, my reasons here.

r.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants