Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add support for deactivation of cache in reentrant calls

  • Loading branch information...
commit 7da74818b11690b4f71c96d588522fd299510666 1 parent d748f92
@capflam capflam authored
View
13 doc/yaws.tex
@@ -1747,9 +1747,16 @@ \section{All out/1 return values}
and can contain a query-string.
\item \verb+{page, {Options, Page}}+ Like the above, but supplying an
- additional deep list of options. For now, the only type of option
- is \verb+{header, H}+ with the effect of accumulating the HTTP
- header \verb+H+ for page \verb+Page+.
+ additional deep list of options. Supported options types are:
+
+ \begin{itemize}
+ \item \verb+{status, C}+ - Set the HTTP response status code \verb+C+ for
+ page \verb+Page+.
+ \item \verb+{header, H}+ - Accumulate the HTTP header \verb+H+ for page
+ \verb+Page+.
+ \item \verb+{disable_cache, Bool}+ - if set to \verb+true+, disable the
+ cache of \verb+Page+ for this call.
+ \end{itemize}
\item \verb+{websocket, CallbackModule, Options}+ Tell \Yaws\ to use
\verb+CallbackModule+ as a WebSockets Protocol handler for traffic
View
13 man/yaws_api.5
@@ -929,9 +929,16 @@ Request-URI, so it must be url-encoded and can contain a query-string.
.TP
\fB{page, {Options, Page}}\fR
-Like the above, but supplying an additional deep list of options. For
-now, the only type of option is \fI{header, H}\fR with the effect of
-accumulating the HTTP header \fIH\fR for page \fIPage\fR.
+Like the above, but supplying an additional deep list of options. Supported
+option types are:
+
+\fI{status, C}\fR - Set the HTTP response status code \fIC\fR for page
+\fIPage\fR.
+
+\fI{header, H}\fR - Accumulate the HTTP header \fIH\fR for page \fIPage\fR.
+
+\fI{disable_cache, Bool}\fR - if set to \fItrue\fR, disable the cache of
+\fIPage\fR for this call.
.TP
View
25 src/yaws_server.erl
@@ -4009,14 +4009,33 @@ url_type(GetPath, ArgDocroot, VirtualDir) ->
SC=get(sc),
GC=get(gc),
E = SC#sconf.ets,
+
+ %% In reentrant call, the cache can be disabled. It could be useful in case
+ %% of "proxy" appmod.
+ NoCache = case get(is_reentrant_request) of
+ true ->
+ case get(page_options) of
+ undefined -> false;
+ Opts -> proplists:get_bool(disable_cache, Opts)
+ end;
+ _ ->
+ false
+ end,
+
case ets:lookup(E, {url, GetPath}) of
[] ->
UT = do_url_type(SC, GetPath, ArgDocroot, VirtualDir),
?TC([{record, UT, urltype}]),
?Debug("UT=~s\n", [?format_record(UT, urltype)]),
- CF = cache_file(SC, GC, GetPath, UT),
- ?Debug("CF=~s\n", [?format_record(CF, urltype)]),
- CF;
+ if
+ NoCache ->
+ ?Debug("Cache disabled\n", []),
+ UT;
+ true ->
+ CF = cache_file(SC, GC, GetPath, UT),
+ ?Debug("CF=~s\n", [?format_record(CF, urltype)]),
+ CF
+ end;
[{_, When, UT}] ->
N = now_secs(),
Refresh = GC#gconf.cache_refresh_secs,
View
7 test/conf/stdconf.conf
@@ -212,6 +212,13 @@ keepalive_timeout = 10000
</server>
<server localhost>
+ port = 8013
+ listen = 0.0.0.0
+ docroot = %YTOP%/www
+ appmods = </index.yaws, cache_appmod_test>
+</server>
+
+<server localhost>
port = 8443
listen = 0.0.0.0
docroot = %YTOP%/www
View
2  test/t2/Makefile
@@ -5,7 +5,7 @@ include ../support/include.mk
#
all: conf setup app_test.beam streamtest.beam jsontest.beam posttest.beam \
reentranttest.beam phptest.beam rewritetest.beam shapertest.beam \
- flushtest.beam throwtest.beam dispatchmod_tester.beam \
+ flushtest.beam throwtest.beam dispatchmod_tester.beam cache_appmod_test.beam \
appmod1.beam appmod2.beam appmod3.beam
@echo "all ok"
View
19 test/t2/app_test.erl
@@ -39,6 +39,7 @@ start() ->
test_websocket(),
test_embedded_id_dir(),
test_chained_appmods(),
+ test_cache_appmod(),
ibrowse:stop().
@@ -960,6 +961,24 @@ test_chained_appmods() ->
proplists:get_value("X-AppMods", Hdrs),
ok.
+test_cache_appmod() ->
+ io:format("test_cache_appmod\n", []),
+ Uri1 = "http://localhost:8013/index.yaws?no-cache=1",
+ Uri2 = "http://localhost:8013/index.yaws",
+
+ %% call cache_appmod_test and disable page cache
+ ?line {ok, "200", Hdrs1, _} = ibrowse:send_req(Uri1, [], get),
+ ?line "cache_appmod_test" = proplists:get_value("X-Appmod", Hdrs1),
+
+ %% check that index.yaws is not cached
+ ?line {ok, "200", Hdrs2, _} = ibrowse:send_req(Uri2, [], get),
+ ?line "cache_appmod_test" = proplists:get_value("X-Appmod", Hdrs2),
+
+ %% retrieve index.yaws from the cache, so cache_appmod_test is not called
+ ?line {ok, "200", Hdrs3, _} = ibrowse:send_req(Uri2, [], get),
+ ?line undefined = proplists:get_value("X-Appmod", Hdrs3),
+
+ ok.
%% used for appmod tests
%%
View
14 test/t2/cache_appmod_test.erl
@@ -0,0 +1,14 @@
+-module(cache_appmod_test).
+-export([out/1]).
+
+-include("../../include/yaws_api.hrl").
+
+out(Arg) ->
+ {abs_path, Path} = (Arg#arg.req)#http_request.path,
+ Opts0 = case yaws_api:queryvar(Arg, "no-cache") of
+ {ok, "1"} -> [{disable_cache, true}];
+ _ -> []
+ end,
+ Opts1 = [{header, {"X-Appmod", "cache_appmod_test"}}|Opts0],
+ {page, {Opts1, Path}}.
+
Please sign in to comment.
Something went wrong with that request. Please try again.