Permalink
Browse files

Compiles.

  • Loading branch information...
mworrell committed Jul 29, 2011
1 parent 3c918a0 commit 27a432a31591d2fcea33b85b523d7d2be5ef23cf
View
@@ -1,22 +1,23 @@
ERL ?= erl
-EBIN_DIRS := $(wildcard deps/*/ebin)
-APP := webmachine
+APP := webzmachine
-all: erl ebin/$(APP).app
+.PHONY: deps
-mochi:
- @(cd deps/mochiweb;$(MAKE))
+all: deps
+ @(./rebar compile)
-erl:
- @$(ERL) -pa $(EBIN_DIRS) -noinput +B \
- -eval 'case make:all() of up_to_date -> halt(0); error -> halt(1) end.'
+deps:
+ @(./rebar get-deps)
+
+clean:
+ @(./rebar clean)
+
+distclean: clean
+ @(./rebar delete-deps)
edoc:
@$(ERL) -noshell -run edoc_run application '$(APP)' '"."' '[{preprocess, true},{includes, ["."]}]'
-clean:
- @echo "removing:"
- rm -f ebin/*.beam ebin/*.app
+test: all
+ @(./rebar skip_deps=true eunit)
-ebin/$(APP).app: src/$(APP).app
- cp src/$(APP).app $@
View
@@ -1,8 +1,8 @@
-{application, webmachine,
- [{description, "webmachine"},
+{application, webzmachine,
+ [{description, "webzmachine"},
{vsn, "1.5"},
{modules, [
- webmachine,
+ webzmachine,
webmachine_app,
webmachine_decision_core,
webmachine_deps,
@@ -12,12 +12,12 @@
webmachine_perf_logger,
webmachine_resource,
webmachine_request,
- webmachine_request_srv,
webmachine_skel,
webmachine_sup,
webmachine_mochiweb,
webmachine_multipart,
webmachine_util,
+ webmachine_id,
wrq,
wmtrace_resource
]},
View
@@ -1,5 +1,4 @@
-record(wm_reqdata, {
-
% Reqstate
socket=undefined,
metadata=dict:new(),
View
@@ -20,25 +20,23 @@ ensure_started(App) ->
start_link() ->
skel_deps:ensure(),
ensure_started(crypto),
- application:set_env(webmachine, webmachine_logger_module,
- webmachine_logger),
- ensure_started(webmachine),
+ application:set_env(webzmachine, webmachine_logger_module, webmachine_logger),
+ ensure_started(webzmachine),
skel_sup:start_link().
%% @spec start() -> ok
%% @doc Start the skel server.
start() ->
skel_deps:ensure(),
ensure_started(crypto),
- application:set_env(webmachine, webmachine_logger_module,
- webmachine_logger),
+ application:set_env(webzmachine, webmachine_logger_module, webmachine_logger),
ensure_started(webmachine),
application:start(skel).
%% @spec stop() -> ok
%% @doc Stop the skel server.
stop() ->
Res = application:stop(skel),
- application:stop(webmachine),
+ application:stop(wezbmachine),
application:stop(crypto),
Res.
@@ -72,7 +72,7 @@ d(DecisionID, Rs, Rd) ->
respond(Code, Rs, Rd) ->
{RsCode, RdCode} = case Code of
Code when Code == 403; Code == 404 ->
- {ok, ErrorHandler} = application:get_env(webmachine, error_handler),
+ {ok, ErrorHandler} = application:get_env(webzmachine, error_handler),
Reason = {none, none, []},
{ErrorHTML, RdError} = ErrorHandler:render_error(Code, Rd, Reason),
{Rs, wrq:set_resp_body(ErrorHTML, RdError)};
@@ -100,7 +100,7 @@ respond(Code, Headers, Rs, Rd) ->
respond(Code, Rs, RdHs).
error_response(Code, Reason, Rs, Rd) ->
- {ok, ErrorHandler} = application:get_env(webmachine, error_handler),
+ {ok, ErrorHandler} = application:get_env(webzmachine, error_handler),
{ErrorHTML, Rd1} = ErrorHandler:render_error(Code, Rd, Reason),
Rd2 = wrq:set_resp_body(ErrorHTML, Rd1),
respond(Code, Rs, Rd2).
@@ -129,11 +129,11 @@ decision_flow({ErrCode, Reason}, _TestResult, Rs, Rd) when is_integer(ErrCode) -
error_response(ErrCode, Reason, Rs, Rd).
do_log(LogData) ->
- case application:get_env(webmachine, webmachine_logger_module) of
+ case application:get_env(webzmachine, webmachine_logger_module) of
{ok, LoggerModule} -> LoggerModule:log_access(LogData);
_ -> nop
end,
- case application:get_env(webmachine, enable_perf_logger) of
+ case application:get_env(webzmachine, enable_perf_logger) of
{ok, true} ->
webmachine_perf_logger:log(LogData);
_ ->
View
@@ -19,7 +19,7 @@
generate() ->
NodeId =
- case application:get_env(webmachine, node_id) of
+ case application:get_env(webzmachine, node_id) of
undefined -> 9;
{ok, NodeId_} -> NodeId_
end,
@@ -48,11 +48,31 @@ stop() ->
stop(Name) ->
mochiweb_http:stop(Name).
-
+
+init_reqdata(MochiReq) ->
+ Socket = MochiReq:get(socket),
+ Method = MochiReq:get(method),
+ RawPath = MochiReq:get(raw_path),
+ Version = MochiReq:get(version),
+ Headers = MochiReq:get(headers),
+ %
+ ReqData0 = wrq:create(Socket,Method,Version,RawPath,Headers),
+ {Peer, ReqData} = webmachine_request:get_peer(ReqData0),
+ PeerState = wrq:set_peer(Peer, ReqData),
+ LogData = #wm_log_data{req_id=webmachine_id:generate(),
+ start_time=now(),
+ method=Method,
+ headers=Headers,
+ peer=PeerState#wm_reqdata.peer,
+ path=RawPath,
+ version=Version,
+ response_code=404,
+ response_length=0},
+ PeerState#wm_reqdata{log_data=LogData}.
loop(MochiReq, LoopOpts) ->
reset_process_dictionary(),
- ReqData = webmachine:init_reqdata(mochiweb, MochiReq),
+ ReqData = init_reqdata(MochiReq),
Host = case host_headers(ReqData) of
[H|_] -> H;
[] -> []
@@ -67,12 +87,12 @@ loop(MochiReq, LoopOpts) ->
end,
case Dispatch of
{no_dispatch_match, _UnmatchedHost, _UnmatchedPathTokens} ->
- {ok, ErrorHandler} = application:get_env(webmachine, error_handler),
+ {ok, ErrorHandler} = application:get_env(webzmachine, error_handler),
{ErrorHTML,ReqState1} = ErrorHandler:render_error(404, ReqDispatch, {none, none, []}),
ReqState2 = webmachine_request:append_to_response_body(ErrorHTML, ReqState1),
{ok,ReqState3} = webmachine_request:send_response(404, ReqState2),
LogData = webmachine_request:log_data(ReqState3),
- case application:get_env(webmachine,webmachine_logger_module) of
+ case application:get_env(webzmachine,webmachine_logger_module) of
{ok, LogModule} ->
spawn(LogModule, log_access, [LogData]);
_ -> nop
@@ -102,7 +122,7 @@ loop(MochiReq, LoopOpts) ->
?WM_DBG({error, erlang:get_stacktrace()}),
{ok,RD3} = webmachine_request:send_response(500, RD2),
Resource:stop(RD3),
- case application:get_env(webmachine, webmachine_logger_module) of
+ case application:get_env(webzmachine, webmachine_logger_module) of
{ok, LogModule} ->
spawn(LogModule, log_access, [webmachine_request:log_data(RD3)]);
_ ->
@@ -126,7 +146,8 @@ host_headers(ReqData) ->
"host"]],
V /= undefined].
-
+
+
%% @doc Sometimes a connection gets re-used for different sites. Make sure that no information
%% leaks from on request to another.
reset_process_dictionary() ->
@@ -156,7 +156,7 @@ suffix({Y, M, D, H}) ->
HS = zeropad(H, 2),
lists:flatten([$., YS, $_, MS, $_, DS, $_, HS]).
-fmt_plog(Time, ReqId, Ip, Method, Path, {VM,Vm}, Status, Length, Mod, TTPD, TTPS) ->
+fmt_plog(Time, ReqId, Ip, Method, Path, {VM,Vm}, Status, Length, Mod, TTPD, _TTPS) ->
[fmt_ip(Ip), " - ", [$\s], Time, [$\s, $"], Method, " ", Path,
" HTTP/", integer_to_list(VM), ".", integer_to_list(Vm), [$",$\s],
Status, [$\s], Length, " " , Mod, " ", TTPD, " ", integer_to_list(ReqId), $\n].
@@ -21,8 +21,6 @@
-author('Justin Sheehy <justin@basho.com>').
-author('Andy Gross <andy@basho.com>').
--include("../../../include/zotonic_release.hrl").
-
-export([get_peer/1]). % used in initialization
% actual interface for resource functions
@@ -79,7 +77,6 @@
-include_lib("include/wm_reqdata.hrl").
-define(WMVSN, "1.7.3 (compat)").
--define(QUIP, "humming along").
-define(IDLE_TIMEOUT, infinity).
get_peer(ReqData) ->
@@ -561,7 +558,7 @@ make_headers(Code, Transfer, Length, RD) ->
LengthHeaders
end
end,
- ServerHeader = "MochiWeb/1.1 WebMachine/" ++ ?WMVSN ++ " Zotonic/" ++ ?ZOTONIC_VERSION,
+ ServerHeader = "MochiWeb/1.1 WebZMachine/" ++ ?WMVSN, % ++ " Zotonic/" ++ ?ZOTONIC_VERSION,
WithSrv = mochiweb_headers:enter("Server", ServerHeader, Hdrs0),
Hdrs = case mochiweb_headers:get_value("date", WithSrv) of
undefined ->
View
@@ -35,7 +35,7 @@ start_link() ->
supervisor:start_link({local, ?MODULE}, ?MODULE, []).
start_logger(BaseDir) ->
- case application:get_env(webmachine, webmachine_logger_module) of
+ case application:get_env(webzmachine, webmachine_logger_module) of
{ok, LoggerModule} ->
ChildSpec =
{webmachine_logger,
View
@@ -14,11 +14,10 @@
%% See the License for the specific language governing permissions and
%% limitations under the License.
--module(webmachine).
+-module(webzmachine).
-author('Justin Sheehy <justin@basho.com>').
-author('Andy Gross <andy@basho.com>').
-export([start/0, stop/0]).
--export([init_reqdata/2]).
-include("webmachine_logger.hrl").
-include_lib("include/wm_reqdata.hrl").
@@ -28,36 +27,9 @@
start() ->
webmachine_deps:ensure(),
application:start(crypto),
- application:start(webmachine).
+ application:start(webzmachine).
%% @spec stop() -> ok
%% @doc Stop the webmachine server.
stop() ->
- application:stop(webmachine).
-
-init_reqdata(mochiweb, Request) ->
- ReqId = webmachine_id:generate(),
- Socket = Request:get(socket),
- Method = Request:get(method),
- RawPath = Request:get(raw_path),
- Version = Request:get(version),
- Headers = Request:get(headers),
- InitState0 = wrq:create(Method,Version,RawPath,Headers),
- InitReq = InitState0#wm_reqdata{socket=Socket},
- {Peer, ReqData} = webmachine_request:get_peer(InitReq),
- PeerState = wrq:set_peer(Peer, ReqData),
- LogData = #wm_log_data{req_id=ReqId,
- start_time=now(),
- method=Method,
- headers=Headers,
- peer=PeerState#wm_reqdata.peer,
- path=RawPath,
- version=Version,
- response_code=404,
- response_length=0},
- PeerState#wm_reqdata{log_data=LogData}.
-
-
-
-
-
+ application:stop(webzmachine).
View
@@ -53,11 +53,11 @@ remove_dispatch_rules() ->
M /= ?MODULE ]).
get_dispatch_list() ->
- {ok, Dispatch} = application:get_env(webmachine, dispatch_list),
+ {ok, Dispatch} = application:get_env(webzmachine, dispatch_list),
Dispatch.
set_dispatch_list(NewList) when is_list(NewList) ->
- application:set_env(webmachine, dispatch_list, NewList).
+ application:set_env(webzmachine, dispatch_list, NewList).
%%
%% Resource
View
@@ -16,7 +16,7 @@
-module(wrq).
-author('Justin Sheehy <justin@basho.com>').
--export([create/4,load_dispatch_data/7]).
+-export([create/5,load_dispatch_data/7]).
-export([method/1,version/1,peer/1,disp_path/1,path/1,raw_path/1,path_info/1,
response_code/1,req_cookie/1,req_qs/1,req_headers/1,req_body/1,
stream_req_body/2,resp_redirect/1,resp_headers/1,resp_body/1,
@@ -32,8 +32,9 @@
% @type reqdata(). The opaque data type used for req/resp data structures.
-include_lib("include/wm_reqdata.hrl").
-create(Method,Version,RawPath,Headers) ->
+create(Socket,Method,Version,RawPath,Headers) ->
create(#wm_reqdata{
+ socket=Socket,
method=Method,version=Version,
raw_path=RawPath,req_headers=prepare_headers(Headers),
path="defined_in_create",

0 comments on commit 27a432a

Please sign in to comment.