Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

made backwards incompatible change to parse_post_data

git-svn-id: https://erlyaws.svn.sourceforge.net/svnroot/erlyaws/trunk/yaws@210 9fbdc01b-0d2c-0410-bfb7-fb27d70d8b52
  • Loading branch information...
commit 86b7d1619a3a1c10fb33b2014388e01b9d6db395 1 parent f0341a3
Claes Wikstrom authored
Showing with 128 additions and 35 deletions.
  1. +3 −2 include/yaws_api.hrl
  2. +120 −30 src/yaws_api.erl
  3. +5 −3 src/yaws_server.erl
5 include/yaws_api.hrl
View
@@ -19,8 +19,8 @@
fullpath, %% full path to yaws file
cont, %% Continuation for chunked multipart uploads
state, %% State for use by users of the out/1 callback
- pid %% pid of the yaws process
-
+ pid, %% pid of the yaws process
+ opaque %% useful for embedded mode to pass static data
}).
@@ -45,6 +45,7 @@
cookie = [],
keep_alive,
content_length,
+ content_type,
authorization,
other = [] %% misc other headers
}).
150 src/yaws_api.erl
View
@@ -16,8 +16,11 @@
-include("yaws_debug.hrl").
--export([parse_post_data/1, parse_query/1,
- code_to_phrase/1, ssi/2, redirect/1]).
+-export([parse_post_data/1]).
+
+
+-export([parse_query/1, parse_post/1, parse_multipart_post/1]).
+-export([code_to_phrase/1, ssi/2, redirect/1]).
-export([setcookie/2, setcookie/3, setcookie/4, setcookie/5]).
-export([pre_ssi_files/2, pre_ssi_string/1, pre_ssi_string/2,
htmlize/1, htmlize_char/1, f/2, fl/1]).
@@ -33,6 +36,84 @@
%% these are a bunch of function that are useful inside
%% yaws scripts
+
+parse_post_data(Arg) ->
+
+ yawslog:infolog("Warning Warning !!!! function "
+ "yaws_api:parse_post_data will be removed ", []),
+
+
+ Headers = Arg#arg.headers,
+ Req = Arg#arg.req,
+ case lists:keysearch('Content-Type', 3, Headers#headers.other) of
+ {value, {_,_,_,_,"multipart/form-data"++Line}} ->
+ case Arg#arg.cont of
+ {cont, Cont} ->
+ parse_multipart(
+ binary_to_list(un_partial(Arg#arg.clidata)),
+ {cont, Cont});
+ undefined ->
+ LineArgs = parse_arg_line(Line),
+ {value, {_, Boundary}} =
+ lists:keysearch(boundary, 1, LineArgs),
+ parse_multipart(
+ binary_to_list(un_partial(Arg#arg.clidata)), Boundary)
+ end;
+ _ ->
+ case Req#http_request.method of
+ 'POST' ->
+ parse_post_data_urlencoded(un_partial(Arg#arg.clidata));
+ _ ->
+ %% kinda weird default bahaviour here
+ parse_post_data_urlencoded(Arg#arg.querydata)
+ end
+ end.
+
+
+
+
+
+%% parse the command line query data
+parse_query(Arg) ->
+ D = Arg#arg.querydata,
+ Req = Arg#arg.req,
+ case Req#http_request.method of
+ 'GET' ->
+ if
+ D == [] ->
+ yawslog:errlog("Tried to parse_query with "
+ "no query data ",[]),
+ [];
+ true ->
+ parse_post_data_urlencoded(D)
+ end;
+ Other ->
+ yawslogg:errlog("Can't parse url query if we get a ~p",[Other]),
+ []
+ end.
+
+%% parse url encoded POST data
+parse_post(Arg) ->
+ D = Arg#arg.clidata,
+ Req = Arg#arg.req,
+ case Req#http_request.method of
+ 'POST' ->
+ if
+ D == [] ->
+ yawslog:errlog("Tried to parse_post with "
+ "no POST data ",[]),
+ [];
+ true ->
+ parse_post_data_urlencoded(D)
+ end;
+ Other ->
+ yawslogg:errlog("Can't parse post body if get a ~p",[Other]),
+ []
+ end.
+
+
+
+
%
% Changed implementation of multipart form data. There is a new config
% parameter called
@@ -47,7 +128,7 @@
% out/1 user by returning {get_more, Cont, State}.
%
%
-% yaws_api:parse_post_data/1 will return either:
+% yaws_api:parse_multipart_post/1 will return either:
%
% {cont, Cont, Res} where Res is new result(s) from this segment. This
% indicates that there is more data to come and the out/1 function
@@ -63,7 +144,7 @@
% <erl>
%
% out(A) ->
-% case yaws_api:parse_post_data(A) of
+% case yaws_api:parse_multipart_post(A) of
% {cont, Cont, Res} ->
% St = handle_res(A, Res),
% {get_more, Cont, St};
@@ -86,36 +167,45 @@
%
% </erl>
-parse_post_data(Arg) ->
- Headers = Arg#arg.headers,
+
+
+parse_multipart_post(Arg) ->
+ H = Arg#arg.headers,
+ CT = H#headers.content_type,
Req = Arg#arg.req,
- case lists:keysearch('Content-Type', 3, Headers#headers.other) of
- {value, {_,_,_,_,"multipart/form-data"++Line}} ->
- case Arg#arg.cont of
- {cont, Cont} ->
- parse_multipart(
- binary_to_list(un_partial(Arg#arg.clidata)),
- {cont, Cont});
+ case Req#http_request.method of
+ 'POST' ->
+ case CT of
undefined ->
- LineArgs = parse_arg_line(Line),
- {value, {_, Boundary}} =
- lists:keysearch(boundary, 1, LineArgs),
- parse_multipart(
- binary_to_list(un_partial(Arg#arg.clidata)), Boundary)
+ yawslog:errlog("Can't parse multipart if we "
+ "have no Content-Type header",[]),
+ [];
+ "multipart/form-data"++Line ->
+ case Arg#arg.cont of
+ {cont, Cont} ->
+ parse_multipart(
+ binary_to_list(un_partial(Arg#arg.clidata)),
+ {cont, Cont});
+ undefined ->
+ LineArgs = parse_arg_line(Line),
+ {value, {_, Boundary}} =
+ lists:keysearch(boundary, 1, LineArgs),
+ parse_multipart(
+ binary_to_list(un_partial(Arg#arg.clidata)),
+ Boundary)
+ end;
+ Other ->
+ yawslog:errlog("Can't parse multipart if we "
+ "find no multipart/form-data",[]),
+ []
end;
- _ ->
- case Req#http_request.method of
- 'POST' ->
- parse_post_data_urlencoded(un_partial(Arg#arg.clidata));
- _ ->
- %% kinda weird default bahaviour here
- parse_post_data_urlencoded(Arg#arg.querydata)
- end
+ Other ->
+ yawslogg:errlog("Can't parse multipart if get a ~p",[Other]),
+ []
end.
-
-%% parse the command line query data
-parse_query(Arg) ->
- parse_post_data_urlencoded(Arg#arg.querydata).
+
+
+
un_partial({partial, Bin}) ->
8 src/yaws_server.erl
View
@@ -788,6 +788,8 @@ http_get_headers(CliSock, Req, GC, H) ->
http_get_headers(CliSock, Req, GC, H#headers{keep_alive = X});
{ok, {http_header, _Num, 'Content-Length', _, X}} ->
http_get_headers(CliSock, Req, GC, H#headers{content_length = X});
+ {ok, {http_header, _Num, 'Content-Type', _, X}} ->
+ http_get_headers(CliSock, Req, GC, H#headers{content_type = X});
{ok, {http_header, _Num, 'Authorization', _, X}} ->
http_get_headers(CliSock, Req, GC,
H#headers{authorization = parse_auth(X)});
@@ -1173,8 +1175,8 @@ req_to_dcc(Req) ->
{1, 1} -> make_chunked(),
{false, true}
end,
- DCC = #dcc{doclose = DoClose,
- chunked = Chunked}.
+ #dcc{doclose = DoClose,
+ chunked = Chunked}.
%% do the header and continue
deliver_dyn_file(CliSock, GC, SC, Req, Head, Specs, ARG, UT, N) ->
@@ -2067,7 +2069,7 @@ conc_path([H|T]) ->
H ++ conc_path(T).
-ret_app_mod(SC, Path, Mod, PrePath) ->
+ret_app_mod(_SC, Path, Mod, PrePath) ->
{PathData, Query} = q_splitpath(Path, []),
#urltype{type = appmod,
data = {Mod, PathData},
Please sign in to comment.
Something went wrong with that request. Please try again.