[bknr-cvs] hans changed trunk/projects/pch/src/pch

BKNR Commits bknr at bknr.net
Sun Sep 21 05:13:44 UTC 2008


Revision: 3928
Author: hans
URL: http://bknr.net/trac/changeset/3928

Checkpoint some old changes from weeks ago.

U   trunk/projects/pch/src/pch.erl
U   trunk/projects/pch/src/pch_cache_mgr.erl
U   trunk/projects/pch/src/pch_front.erl

Modified: trunk/projects/pch/src/pch.erl
===================================================================
--- trunk/projects/pch/src/pch.erl	2008-09-19 06:24:57 UTC (rev 3927)
+++ trunk/projects/pch/src/pch.erl	2008-09-21 05:13:44 UTC (rev 3928)
@@ -2,16 +2,16 @@
 %%% http://www.rsaccon.com/2007/09/mochiweb-erlang-based-webserver-toolkit.html
 
 -module(pch).
--export([start/0, loop/2, stop/0]).
+-export([start/0, stop/0]).
 -define(HTTP_PORT, 9888).
 -define(MANAGEMENT_PORT, 9889).
 
 start() ->
     Cache = ets:new(table, [set, public]),
-    pch_cache_mgr:start(?MANAGEMENT_PORT, Cache),
+%%    pch_cache_mgr:start(?MANAGEMENT_PORT, Cache),
     pch_front:start(?HTTP_PORT, Cache).
 
 stop() ->
-    pch_front:stop(),
-    pch_cache_mgr:stop().
+    pch_front:stop().
+%%    pch_cache_mgr:stop().
 

Modified: trunk/projects/pch/src/pch_cache_mgr.erl
===================================================================
--- trunk/projects/pch/src/pch_cache_mgr.erl	2008-09-19 06:24:57 UTC (rev 3927)
+++ trunk/projects/pch/src/pch_cache_mgr.erl	2008-09-21 05:13:44 UTC (rev 3928)
@@ -1,5 +1,5 @@
 -module(pch_cache_mgr).
--export([start/1, loop/2, stop/0]).
+-export([start/2, loop/2, stop/0]).
 
 start(Port, Cache) ->
     mochiweb_http:start([{loop, fun (Req) ->
@@ -10,10 +10,30 @@
 stop() ->
     mochiweb_http:stop(?MODULE).
 
+fetch_from_backend(Path) ->
+    io:format("Fetching ~p~n", [Path]),
+    {ok, {{_Version, 200, _ReasonPhrase}, Headers, Body}} =
+        http:request("http://127.0.0.1:8080" ++ Path),
+    io:format("Got ~p~n", [Headers]),
+    {ok, Headers, Body}.
+
+backend_request(Req, Cache) ->
+    Path = Req:get(path),
+    case ets:lookup(Cache, Path) of
+        [{Path, Headers, Body}] ->
+            io:format("cache HIT for ~p~n", [Path]),
+            Req:respond({200, Headers, Body});
+        _ ->
+            io:format("cache MISS for ~p~n", [Path]),
+            {ok, Headers, Body} = fetch_from_backend(Path),
+            ets:insert(Cache, {Path, Headers, Body}),
+            Req:respond({200, Headers, Body})
+    end.
+
 loop(Req, Cache) ->
     case Req:get(method) of
-        M when M =:= 'GET' ->
-            backend_request(Req, Cache);
+%%         M when M =:= 'GET' ->
+%%             backend_request(Req, Cache);
         _ ->
             Req:respond({501, [], ""})
     end.

Modified: trunk/projects/pch/src/pch_front.erl
===================================================================
--- trunk/projects/pch/src/pch_front.erl	2008-09-19 06:24:57 UTC (rev 3927)
+++ trunk/projects/pch/src/pch_front.erl	2008-09-21 05:13:44 UTC (rev 3928)
@@ -1,5 +1,5 @@
 -module(pch_front).
--export([start/0, loop/2, stop/0]).
+-export([start/2, loop/2, stop/0]).
 
 start(Port, Cache) ->
     mochiweb_http:start([{loop, fun (Req) ->
@@ -8,26 +8,8 @@
                          {name, ?MODULE}]).
 
 stop() ->
-    mochiweb_http:stop(?MODULE),
+    mochiweb_http:stop(?MODULE).
 
-fetch_from_backend(Path) ->
-    {ok, {{_Version, 200, _ReasonPhrase}, Headers, Body}} =
-        http:request("http://test.createrainforest.org" ++ Path),
-    {ok, Headers, Body}.
-
-backend_request(Req, Cache) ->
-    Path = Req:get(path),
-    case ets:lookup(Cache, Path) of
-        [{Path, Headers, Body}] ->
-            io:format("cache HIT for ~p~n", [Path]),
-            Req:respond({200, Headers, Body});
-        _ ->
-            io:format("cache MISS for ~p~n", [Path]),
-            {ok, Headers, Body} = fetch_from_backend(Path),
-            ets:insert(Cache, {Path, Headers, Body}),
-            Req:respond({200, Headers, Body})
-    end.
-
 loop(Req, Cache) ->
     case Req:get(method) of
         M when M =:= 'GET' ->




More information about the Bknr-cvs mailing list