Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Auto recv post body fuction that ignor auto_recv_body option. #103

Open
wants to merge 1 commit into from

2 participants

@egobrain

Here is my solution for my previous issue.

@ostinelli
Owner

thank you for this.

misultin has been discontinued, my reasons here.

r.

@ostinelli
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
Commits on Feb 14, 2012
  1. @egobrain
This page is out of date. Refresh to see the latest.
Showing with 38 additions and 3 deletions.
  1. +31 −2 src/misultin_http.erl
  2. +7 −1 src/misultin_req.erl
View
33 src/misultin_http.erl
@@ -36,6 +36,7 @@
% API
-export([handle_data/11, build_error_message/4, build_error_message/5, build_error_message_body/1, build_error_message_body/2, get_reqinfo/2, session_cmd/2, body_recv/1]).
+-export([auto_body_recv/2]).
% internal
-export([request/2]).
@@ -156,6 +157,11 @@ session_cmd(SocketPid, SessionCmd) ->
body_recv(SocketPid) ->
misultin_utility:call(SocketPid, body_recv).
+% call {auto_body_recv,PostMaxSize} on the http process handler
+-spec auto_body_recv(SocketPid::pid(),PostMaxSize::non_neg_integer()) -> ok | {error, Reason::term()}.
+auto_body_recv(SocketPid,PostMaxSize) ->
+ misultin_utility:call(SocketPid,{auto_body_recv,PostMaxSize}).
+
% ============================ /\ API ======================================================================
@@ -436,8 +442,7 @@ read_post_body(C, #req{content_length = ContentLength} = Req, NoContentNoChunkOu
"chunked" ->
?LOG_DEBUG("chunked content being sent by the client",[]),
chunked_body;
- _ ->
- NoContentNoChunkOutput
+ _ -> NoContentNoChunkOutput
end
end;
Len ->
@@ -655,6 +660,30 @@ socket_loop(#c{compress = Compress} = C, #req{socket = Sock, socket_mode = Socke
misultin_utility:respond(CallerPid, read_body(chunk, C, Req)),
% loop
socket_loop(C, Req, LoopPid, ReqOptions, AppHeaders, HttpCodeSent, SizeSent);
+ {CallerPid,{auto_body_recv,PostMaxSize}} ->
+ ?LOG_DEBUG("automatically read body of request",[]),
+ case read_body(full, C#c{post_max_size=PostMaxSize}, Req) of
+ {ok, Bin} ->
+ ?LOG_DEBUG("full body read: ~p", [Bin]),
+ Req0 = Req#req{body = Bin},
+ misultin_utility:respond(CallerPid,ok),
+ socket_loop(C, Req0, LoopPid, ReqOptions, AppHeaders, HttpCodeSent, SizeSent);
+ {error, timeout} ->
+ ?LOG_WARNING("request timeout, sending error", []),
+ misultin_utility:respond(CallerPid,{error,timeout}),
+ % misultin_socket:send(Sock, build_error_message(408, Req, C#c.table_date_ref, C#c.access_log), SocketMode),
+ handle_keepalive(close, C, Req);
+ {error, post_max_size} ->
+ ?LOG_WARNING("post request entity too large", []),
+ misultin_utility:respond(CallerPid,{error,post_max_size}),
+ % misultin_socket:send(Sock, build_error_message(413, Req#req{connection = close}, C#c.table_date_ref, C#c.access_log), SocketMode),
+ handle_keepalive(close, C, Req);
+ {error, Reason} ->
+ ?LOG_ERROR("tcp error treating post data: ~p, send bad request error back", [Reason]),
+ misultin_utility:respond(CallerPid,{error,Reason}),
+ % misultin_socket:send(Sock, build_error_message(400, Req#req{connection = close}, C#c.table_date_ref, C#c.access_log), SocketMode),
+ handle_keepalive(close, C, Req)
+ end;
{set_cookie, CookieHeader} ->
?LOG_DEBUG("received a cookie: ~p", [CookieHeader]),
% add cookie header
View
8 src/misultin_req.erl
@@ -42,7 +42,7 @@
-export([chunk/2, chunk/3, stream/2, stream/3, stream/4]).
-export([raw/1, get/2]).
-export([get_variable/3, get_cookies/1, get_cookie_value/3, set_cookie/3, set_cookie/4, delete_cookie/2]).
--export([body_recv/1]).
+-export([body_recv/1,auto_body_recv/2]).
-export([session/1, session/2, save_session_state/3]).
-export([uri_unquote/1, parse_qs/1, parse_qs/2, parse_post/1, parse_post/2, file/2, file/3, file/4, resource/2]).
@@ -253,6 +253,12 @@ stream(head, HttpCode, Headers, {misultin_req, SocketPid, _TableDateRef}) ->
body_recv({misultin_req, SocketPid, _TableDateRef}) ->
misultin_http:body_recv(SocketPid).
+% auto recv body of request ignoring auto_recv_body option
+-spec auto_body_recv(PostMaxSize::non_neg_integer(),reqt()) -> ok | {error, Reason::term()}.
+auto_body_recv(PostMaxSize,{misultin_req, SocketPid, _TableDateRef}) ->
+ misultin_http:auto_body_recv(SocketPid,PostMaxSize).
+
+
% Sends a file to the browser.
-spec file
(FilePath::string(), reqt()) -> term().
Something went wrong with that request. Please try again.