Repository navigation
Expand file tree
/
Copy pathwebmachine.erl
More file actions
66 lines (55 loc) · 2.24 KB
/
Copy pathwebmachine.erl
File metadata and controls
66 lines (55 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
%% @author Justin Sheehy <justin@basho.com>
%% @author Andy Gross <andy@basho.com>
%% @copyright 2007-2009 Basho Technologies
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
%% You may obtain a copy of the License at
%%
%% http://www.apache.org/licenses/LICENSE-2.0
%%
%% Unless required by applicable law or agreed to in writing, software
%% distributed under the License is distributed on an "AS IS" BASIS,
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
%% See the License for the specific language governing permissions and
%% limitations under the License.
-module(webmachine).
-author('Justin Sheehy <justin@basho.com>').
-author('Andy Gross <andy@basho.com>').
-export([start/0, stop/0]).
-export([new_request/2]).
-include("webmachine_logger.hrl").
-include("wm_reqstate.hrl").
-include("wm_reqdata.hrl").
%% @spec start() -> ok
%% @doc Start the webmachine server.
start() ->
webmachine_deps:ensure(),
application:start(crypto),
application:start(webmachine).
%% @spec stop() -> ok
%% @doc Stop the webmachine server.
stop() ->
application:stop(webmachine).
new_request(mochiweb, Request) ->
Socket = Request:get(socket),
Method = Request:get(method),
Scheme = Request:get(scheme),
RawPath = Request:get(raw_path),
Version = Request:get(version),
Headers = Request:get(headers),
InitState = #wm_reqstate{socket=Socket,
reqdata=wrq:create(Method,Scheme,Version,RawPath,Headers)},
InitReq = {webmachine_request,InitState},
{Peer, ReqState} = InitReq:get_peer(),
PeerState = ReqState#wm_reqstate{reqdata=wrq:set_peer(Peer,
ReqState#wm_reqstate.reqdata)},
LogData = #wm_log_data{start_time=now(),
method=Method,
headers=Headers,
peer=PeerState#wm_reqstate.peer,
path=RawPath,
version=Version,
response_code=404,
response_length=0},
webmachine_request:new(PeerState#wm_reqstate{log_data=LogData}).