Anonymous avatar Anonymous committed 37f7453

initial upload

Comments (0)

Files changed (24)

+% -*- mode: erlang -*-
+{["src/*"], 
+ [{i, "include"},
+  {outdir, "ebin"},
+  debug_info]
+}.
+ERL          ?= erl
+EBIN_DIRS    := $(wildcard deps/*/ebin)
+APP          := httptest
+
+all: erl ebin/$(APP).app
+
+erl:
+	@$(ERL) -pa $(EBIN_DIRS) -noinput +B \
+	  -eval 'case make:all() of up_to_date -> halt(0); error -> halt(1) end.'
+
+docs:
+	@erl -noshell -run edoc_run application '$(APP)' '"."' '[]'
+
+clean: 
+	@echo "removing:"
+	@rm -fv ebin/*.beam ebin/*.app
+
+ebin/$(APP).app: src/$(APP).app
+	@cp -v src/$(APP).app $@
+/home/fedtech/webmachine-read-only/scripts/../ebin/..

ebin/httptest.app

+{application, httptest,
+ [{description, "httptest"},
+  {vsn, "0.1"},
+  {modules, [
+    httptest,
+    httptest_app,
+    httptest_sup,
+    httptest_deps,
+    httptest_resource
+  ]},
+  {registered, []},
+  {mod, {httptest_app, []}},
+  {env, []},
+  {applications, [kernel, stdlib, crypto]}]}.

Binary file added.

Binary file added.

Add a comment to this file

ebin/httptest_deps.beam

Binary file added.

Add a comment to this file

ebin/httptest_resource.beam

Binary file added.

Binary file added.

priv/dispatch.conf

+{[], httptest_resource, []}.

priv/dispatch.conf~

+{[], httptest_resource, []}.

priv/log/access.log.2010_06_07_16

+127.0.0.1 - - [07/Jun/2010:17:33:10 +0100] "GET / HTTP/1.1" 200 42 "" "Mozilla/5.0 (X11; U; Linux i686; en-GB; rv:1.9.0.8) Gecko/2009032608 Firefox/3.0.8"

priv/log/access.log.2010_06_07_17

+127.0.0.1 - - [07/Jun/2010:18:07:50 +0100] "GET / HTTP/1.1" 200 8610 "" "Mozilla/5.0 (X11; U; Linux i686; en-GB; rv:1.9.0.8) Gecko/2009032608 Firefox/3.0.8"
+127.0.0.1 - - [07/Jun/2010:18:07:50 +0100] "GET /style/style.css HTTP/1.1" 404 193 "http://localhost:8000/" "Mozilla/5.0 (X11; U; Linux i686; en-GB; rv:1.9.0.8) Gecko/2009032608 Firefox/3.0.8"
+127.0.0.1 - - [07/Jun/2010:18:07:50 +0100] "GET /js/jquery.js HTTP/1.1" 404 193 "http://localhost:8000/" "Mozilla/5.0 (X11; U; Linux i686; en-GB; rv:1.9.0.8) Gecko/2009032608 Firefox/3.0.8"
+127.0.0.1 - - [07/Jun/2010:18:07:50 +0100] "GET /js/jquery.timeago.js HTTP/1.1" 404 193 "http://localhost:8000/" "Mozilla/5.0 (X11; U; Linux i686; en-GB; rv:1.9.0.8) Gecko/2009032608 Firefox/3.0.8"
+127.0.0.1 - - [07/Jun/2010:18:07:50 +0100] "GET /js/jquery.corner.js HTTP/1.1" 404 193 "http://localhost:8000/" "Mozilla/5.0 (X11; U; Linux i686; en-GB; rv:1.9.0.8) Gecko/2009032608 Firefox/3.0.8"
+127.0.0.1 - - [07/Jun/2010:18:07:50 +0100] "GET /js/userp.js HTTP/1.1" 404 193 "http://localhost:8000/" "Mozilla/5.0 (X11; U; Linux i686; en-GB; rv:1.9.0.8) Gecko/2009032608 Firefox/3.0.8"
+127.0.0.1 - - [07/Jun/2010:18:07:50 +0100] "GET /images/userp-logo.png HTTP/1.1" 404 193 "http://localhost:8000/" "Mozilla/5.0 (X11; U; Linux i686; en-GB; rv:1.9.0.8) Gecko/2009032608 Firefox/3.0.8"
+127.0.0.1 - - [07/Jun/2010:18:07:50 +0100] "GET /images/feed-icon-14x14.png HTTP/1.1" 404 193 "http://localhost:8000/" "Mozilla/5.0 (X11; U; Linux i686; en-GB; rv:1.9.0.8) Gecko/2009032608 Firefox/3.0.8"
+127.0.0.1 - - [07/Jun/2010:18:07:50 +0100] "GET /images/seth-hood2.jpg HTTP/1.1" 404 193 "http://localhost:8000/" "Mozilla/5.0 (X11; U; Linux i686; en-GB; rv:1.9.0.8) Gecko/2009032608 Firefox/3.0.8"
+127.0.0.1 - - [07/Jun/2010:18:08:01 +0100] "GET / HTTP/1.1" 200 8610 "" "Mozilla/5.0 (X11; U; Linux i686; en-GB; rv:1.9.0.8) Gecko/2009032608 Firefox/3.0.8"
+127.0.0.1 - - [07/Jun/2010:18:08:01 +0100] "GET /style/style.css HTTP/1.1" 404 193 "http://localhost:8000/" "Mozilla/5.0 (X11; U; Linux i686; en-GB; rv:1.9.0.8) Gecko/2009032608 Firefox/3.0.8"
+127.0.0.1 - - [07/Jun/2010:18:08:01 +0100] "GET /js/jquery.js HTTP/1.1" 404 193 "http://localhost:8000/" "Mozilla/5.0 (X11; U; Linux i686; en-GB; rv:1.9.0.8) Gecko/2009032608 Firefox/3.0.8"
+127.0.0.1 - - [07/Jun/2010:18:08:01 +0100] "GET /js/jquery.timeago.js HTTP/1.1" 404 193 "http://localhost:8000/" "Mozilla/5.0 (X11; U; Linux i686; en-GB; rv:1.9.0.8) Gecko/2009032608 Firefox/3.0.8"
+127.0.0.1 - - [07/Jun/2010:18:08:01 +0100] "GET /js/jquery.corner.js HTTP/1.1" 404 193 "http://localhost:8000/" "Mozilla/5.0 (X11; U; Linux i686; en-GB; rv:1.9.0.8) Gecko/2009032608 Firefox/3.0.8"
+127.0.0.1 - - [07/Jun/2010:18:08:01 +0100] "GET /js/userp.js HTTP/1.1" 404 193 "http://localhost:8000/" "Mozilla/5.0 (X11; U; Linux i686; en-GB; rv:1.9.0.8) Gecko/2009032608 Firefox/3.0.8"
+127.0.0.1 - - [07/Jun/2010:18:08:01 +0100] "GET /images/userp-logo.png HTTP/1.1" 404 193 "http://localhost:8000/" "Mozilla/5.0 (X11; U; Linux i686; en-GB; rv:1.9.0.8) Gecko/2009032608 Firefox/3.0.8"
+127.0.0.1 - - [07/Jun/2010:18:08:01 +0100] "GET /images/feed-icon-14x14.png HTTP/1.1" 404 193 "http://localhost:8000/" "Mozilla/5.0 (X11; U; Linux i686; en-GB; rv:1.9.0.8) Gecko/2009032608 Firefox/3.0.8"
+127.0.0.1 - - [07/Jun/2010:18:08:01 +0100] "GET /images/seth-hood2.jpg HTTP/1.1" 404 193 "http://localhost:8000/" "Mozilla/5.0 (X11; U; Linux i686; en-GB; rv:1.9.0.8) Gecko/2009032608 Firefox/3.0.8"
+127.0.0.1 - - [08/Jun/2010:11:30:26 +0100] "GET / HTTP/1.1" 200 8610 "" "Mozilla/5.0 (X11; U; Linux i686; en-GB; rv:1.9.0.8) Gecko/2009032608 Firefox/3.0.8"
+127.0.0.1 - - [08/Jun/2010:11:30:26 +0100] "GET /style/style.css HTTP/1.1" 404 193 "http://localhost:8000/" "Mozilla/5.0 (X11; U; Linux i686; en-GB; rv:1.9.0.8) Gecko/2009032608 Firefox/3.0.8"
+127.0.0.1 - - [08/Jun/2010:11:30:26 +0100] "GET /js/jquery.js HTTP/1.1" 404 193 "http://localhost:8000/" "Mozilla/5.0 (X11; U; Linux i686; en-GB; rv:1.9.0.8) Gecko/2009032608 Firefox/3.0.8"
+127.0.0.1 - - [08/Jun/2010:11:30:26 +0100] "GET /js/jquery.timeago.js HTTP/1.1" 404 193 "http://localhost:8000/" "Mozilla/5.0 (X11; U; Linux i686; en-GB; rv:1.9.0.8) Gecko/2009032608 Firefox/3.0.8"
+127.0.0.1 - - [08/Jun/2010:11:30:26 +0100] "GET /js/jquery.corner.js HTTP/1.1" 404 193 "http://localhost:8000/" "Mozilla/5.0 (X11; U; Linux i686; en-GB; rv:1.9.0.8) Gecko/2009032608 Firefox/3.0.8"
+127.0.0.1 - - [08/Jun/2010:11:30:26 +0100] "GET /js/userp.js HTTP/1.1" 404 193 "http://localhost:8000/" "Mozilla/5.0 (X11; U; Linux i686; en-GB; rv:1.9.0.8) Gecko/2009032608 Firefox/3.0.8"
+127.0.0.1 - - [08/Jun/2010:11:30:26 +0100] "GET /images/userp-logo.png HTTP/1.1" 404 193 "http://localhost:8000/" "Mozilla/5.0 (X11; U; Linux i686; en-GB; rv:1.9.0.8) Gecko/2009032608 Firefox/3.0.8"
+127.0.0.1 - - [08/Jun/2010:11:30:27 +0100] "GET /images/feed-icon-14x14.png HTTP/1.1" 404 193 "http://localhost:8000/" "Mozilla/5.0 (X11; U; Linux i686; en-GB; rv:1.9.0.8) Gecko/2009032608 Firefox/3.0.8"
+127.0.0.1 - - [08/Jun/2010:11:30:27 +0100] "GET /images/seth-hood2.jpg HTTP/1.1" 404 193 "http://localhost:8000/" "Mozilla/5.0 (X11; U; Linux i686; en-GB; rv:1.9.0.8) Gecko/2009032608 Firefox/3.0.8"

priv/www/index.html

+<html>
+<head>
+<title>It Worked</title>
+</head>
+<body>
+MochiWeb running.
+</body>
+</html>
+{application, httptest,
+ [{description, "httptest"},
+  {vsn, "0.1"},
+  {modules, [
+    httptest,
+    httptest_app,
+    httptest_sup,
+    httptest_deps,
+    httptest_resource
+  ]},
+  {registered, []},
+  {mod, {httptest_app, []}},
+  {env, []},
+  {applications, [kernel, stdlib, crypto]}]}.
+%% @author author <author@example.com>
+%% @copyright YYYY author.
+
+%% @doc TEMPLATE.
+
+-module(httptest).
+-author('author <author@example.com>').
+-export([start/0, start_link/0, stop/0]).
+
+ensure_started(App) ->
+    case application:start(App) of
+	ok ->
+	    ok;
+	{error, {already_started, App}} ->
+	    ok
+    end.
+
+%% @spec start_link() -> {ok,Pid::pid()}
+%% @doc Starts the app for inclusion in a supervisor tree
+start_link() ->
+    httptest_deps:ensure(),
+    ensure_started(crypto),
+    ensure_started(webmachine),
+    httptest_sup:start_link().
+
+%% @spec start() -> ok
+%% @doc Start the httptest server.
+start() ->
+    httptest_deps:ensure(),
+    ensure_started(crypto),
+    ensure_started(webmachine),
+    application:start(httptest).
+
+%% @spec stop() -> ok
+%% @doc Stop the httptest server.
+stop() ->
+    Res = application:stop(httptest),
+    application:stop(webmachine),
+    application:stop(crypto),
+    Res.
+

src/httptest_app.erl

+%% @author author <author@example.com>
+%% @copyright YYYY author.
+
+%% @doc Callbacks for the httptest application.
+
+-module(httptest_app).
+-author('author <author@example.com>').
+
+-behaviour(application).
+-export([start/2,stop/1]).
+
+
+%% @spec start(_Type, _StartArgs) -> ServerRet
+%% @doc application start callback for httptest.
+start(_Type, _StartArgs) ->
+    httptest_deps:ensure(),
+    httptest_sup:start_link().
+
+%% @spec stop(_State) -> ServerRet
+%% @doc application stop callback for httptest.
+stop(_State) ->
+    ok.

src/httptest_deps.erl

+%% @author author <author@example.com>
+%% @copyright YYYY author.
+
+%% @doc Ensure that the relatively-installed dependencies are on the code
+%%      loading path, and locate resources relative
+%%      to this application's path.
+
+-module(httptest_deps).
+-author('author <author@example.com>').
+
+-export([ensure/0, ensure/1]).
+-export([get_base_dir/0, get_base_dir/1]).
+-export([local_path/1, local_path/2]).
+-export([deps_on_path/0, new_siblings/1]).
+
+%% @spec deps_on_path() -> [ProjNameAndVers]
+%% @doc List of project dependencies on the path.
+deps_on_path() ->
+    F = fun (X, Acc) ->
+                ProjDir = filename:dirname(X),
+                case {filename:basename(X),
+                      filename:basename(filename:dirname(ProjDir))} of
+                    {"ebin", "deps"} ->
+                        [filename:basename(ProjDir) | Acc];
+                    _ ->
+                        Acc
+                end
+        end,
+    ordsets:from_list(lists:foldl(F, [], code:get_path())).
+    
+%% @spec new_siblings(Module) -> [Dir]
+%% @doc Find new siblings paths relative to Module that aren't already on the
+%%      code path.
+new_siblings(Module) ->
+    Existing = deps_on_path(),
+    SiblingEbin = filelib:wildcard(local_path(["deps", "*", "ebin"], Module)),
+    Siblings = [filename:dirname(X) || X <- SiblingEbin,
+                           ordsets:is_element(
+                             filename:basename(filename:dirname(X)),
+                             Existing) =:= false],
+    lists:filter(fun filelib:is_dir/1, 
+                 lists:append([[filename:join([X, "ebin"]),
+                                filename:join([X, "include"])] ||
+                                  X <- Siblings])).
+        
+
+%% @spec ensure(Module) -> ok
+%% @doc Ensure that all ebin and include paths for dependencies
+%%      of the application for Module are on the code path.
+ensure(Module) ->
+    code:add_paths(new_siblings(Module)),
+    code:clash(),
+    ok.
+
+%% @spec ensure() -> ok
+%% @doc Ensure that the ebin and include paths for dependencies of
+%%      this application are on the code path. Equivalent to
+%%      ensure(?Module).
+ensure() ->
+    ensure(?MODULE).
+
+%% @spec get_base_dir(Module) -> string()
+%% @doc Return the application directory for Module. It assumes Module is in
+%%      a standard OTP layout application in the ebin or src directory.
+get_base_dir(Module) ->
+    {file, Here} = code:is_loaded(Module),
+    filename:dirname(filename:dirname(Here)).
+
+%% @spec get_base_dir() -> string()
+%% @doc Return the application directory for this application. Equivalent to
+%%      get_base_dir(?MODULE).
+get_base_dir() ->
+    get_base_dir(?MODULE).
+
+%% @spec local_path([string()], Module) -> string()
+%% @doc Return an application-relative directory from Module's application.
+local_path(Components, Module) ->
+    filename:join([get_base_dir(Module) | Components]).
+
+%% @spec local_path(Components) -> string()
+%% @doc Return an application-relative directory for this application.
+%%      Equivalent to local_path(Components, ?MODULE).
+local_path(Components) ->
+    local_path(Components, ?MODULE).

src/httptest_resource.erl

+%% @author author <author@example.com>
+%% @copyright YYYY author.
+%% @doc Example webmachine_resource.
+
+-module(httptest_resource).
+-export([init/1, to_html/2]).
+
+-include_lib("webmachine/include/webmachine.hrl").
+
+init([]) -> {ok, undefined}.
+
+%% trying out the http request in erlang
+%% this will be useful when interacting with external apis
+%% based on http://userprimary.net/posts/2009/04/04/exploring-erlangs-http-client/
+%% just returns the html found in the body tag of another site, in this case userprimary.net
+
+to_html(ReqData, Context) ->
+    application:start(inets),
+    UA = "Mozilla/5.0 (X11; U; Linux i686; en-GB; rv:1.9.0.8) Gecko/2009032608 Firefox/3.0.8",
+    Url = "http://userprimary.net",
+    {ok, {{HttpVer, Code, Msg}, Headers, Body}} =
+    http:request(get, {Url, [{"User-Agent", UA}]}, [], []),
+    {Body, ReqData, Context}.
+

src/httptest_resource.erl~

+%% @author author <author@example.com>
+%% @copyright YYYY author.
+%% @doc Example webmachine_resource.
+
+-module(httptest_resource).
+-export([init/1, to_html/2]).
+
+-include_lib("webmachine/include/webmachine.hrl").
+
+init([]) -> {ok, undefined}.
+
+%% trying out the http request in erlang
+%% this will be useful when interacting with external apis
+%% based on http://userprimary.net/posts/2009/04/04/exploring-erlangs-http-client/
+%% just returns the html found in the body tag
+
+to_html(ReqData, Context) ->
+    application:start(inets),
+    UA = "Mozilla/5.0 (X11; U; Linux i686; en-GB; rv:1.9.0.8) Gecko/2009032608 Firefox/3.0.8",
+    Url = "http://userprimary.net",
+    {ok, {{HttpVer, Code, Msg}, Headers, Body}} =
+    http:request(get, {Url, [{"User-Agent", UA}]}, [], []),
+    {Body, ReqData, Context}.
+

src/httptest_sup.erl

+%% @author author <author@example.com>
+%% @copyright YYYY author.
+
+%% @doc Supervisor for the httptest application.
+
+-module(httptest_sup).
+-author('author <author@example.com>').
+
+-behaviour(supervisor).
+
+%% External exports
+-export([start_link/0, upgrade/0]).
+
+%% supervisor callbacks
+-export([init/1]).
+
+%% @spec start_link() -> ServerRet
+%% @doc API for starting the supervisor.
+start_link() ->
+    supervisor:start_link({local, ?MODULE}, ?MODULE, []).
+
+%% @spec upgrade() -> ok
+%% @doc Add processes if necessary.
+upgrade() ->
+    {ok, {_, Specs}} = init([]),
+
+    Old = sets:from_list(
+	    [Name || {Name, _, _, _} <- supervisor:which_children(?MODULE)]),
+    New = sets:from_list([Name || {Name, _, _, _, _, _} <- Specs]),
+    Kill = sets:subtract(Old, New),
+
+    sets:fold(fun (Id, ok) ->
+		      supervisor:terminate_child(?MODULE, Id),
+		      supervisor:delete_child(?MODULE, Id),
+		      ok
+	      end, ok, Kill),
+
+    [supervisor:start_child(?MODULE, Spec) || Spec <- Specs],
+    ok.
+
+%% @spec init([]) -> SupervisorTree
+%% @doc supervisor callback.
+init([]) ->
+    Ip = case os:getenv("WEBMACHINE_IP") of false -> "0.0.0.0"; Any -> Any end,
+    {ok, Dispatch} = file:consult(filename:join(
+                         [filename:dirname(code:which(?MODULE)),
+                          "..", "priv", "dispatch.conf"])),
+    WebConfig = [
+		 {ip, Ip},
+		 {port, 8000},
+                 {log_dir, "priv/log"},
+		 {dispatch, Dispatch}],
+    Web = {webmachine_mochiweb,
+	   {webmachine_mochiweb, start, [WebConfig]},
+	   permanent, 5000, worker, dynamic},
+    Processes = [Web],
+    {ok, {{one_for_one, 10, 10}, Processes}}.
+#!/bin/sh
+cd `dirname $0`
+exec erl -pa $PWD/ebin $PWD/deps/*/ebin $PWD/deps/*/deps/*/ebin -boot start_sasl -s reloader -s httptest
+#!/bin/sh
+cd `dirname $0`
+exec erl -pa $PWD/ebin $PWD/deps/*/ebin $PWD/deps/*/deps/*/ebin -boot start_sasl -s httptest
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.