Skip to content
Browse files

Move webmachine -> webzmachine in its own repository.

  • Loading branch information...
1 parent fac3ae8 commit feca8729f69036454e86c04331b4e496b51007cc @arjan arjan committed Dec 21, 2011
Showing with 17 additions and 7,736 deletions.
  1. +3 −0 .gitmodules
  2. +1 −1 Emakefile
  3. +4 −4 Makefile
  4. +0 −6 deps/webmachine/Emakefile
  5. +0 −178 deps/webmachine/LICENSE
  6. +0 −22 deps/webmachine/Makefile
  7. +0 −19 deps/webmachine/THANKS
  8. +0 −6 deps/webmachine/demo/Emakefile
  9. +0 −19 deps/webmachine/demo/Makefile
  10. +0 −1 deps/webmachine/demo/ebin/.empty
  11. +0 −1 deps/webmachine/demo/priv/.empty
  12. +0 −157 deps/webmachine/demo/src/demo_fs_resource.erl
  13. +0 −14 deps/webmachine/demo/src/webmachine_demo.app
  14. +0 −27 deps/webmachine/demo/src/webmachine_demo.erl
  15. +0 −1 deps/webmachine/demo/src/webmachine_demo.hrl
  16. +0 −20 deps/webmachine/demo/src/webmachine_demo_app.erl
  17. +0 −49 deps/webmachine/demo/src/webmachine_demo_resource.erl
  18. +0 −42 deps/webmachine/demo/src/webmachine_demo_sup.erl
  19. +0 −3 deps/webmachine/demo/start.sh
  20. +0 −1 deps/webmachine/deps/.empty
  21. +0 −1 deps/webmachine/docs/.empty
  22. BIN deps/webmachine/docs/http-headers-status-v3.png
  23. +0 −1 deps/webmachine/ebin/.empty
  24. +0 −8 deps/webmachine/include/webmachine.hrl
  25. +0 −16 deps/webmachine/include/webmachine_logger.hrl
  26. +0 −23 deps/webmachine/include/wm_reqdata.hrl
  27. +0 −6 deps/webmachine/priv/skel/Emakefile
  28. +0 −19 deps/webmachine/priv/skel/Makefile
  29. 0 deps/webmachine/priv/skel/deps/.empty
  30. 0 deps/webmachine/priv/skel/ebin/.empty
  31. +0 −1 deps/webmachine/priv/skel/priv/dispatch.conf
  32. +0 −8 deps/webmachine/priv/skel/priv/www/index.html
  33. +0 −14 deps/webmachine/priv/skel/src/skel.app
  34. +0 −44 deps/webmachine/priv/skel/src/skel.erl
  35. +0 −1 deps/webmachine/priv/skel/src/skel.hrl
  36. +0 −22 deps/webmachine/priv/skel/src/skel_app.erl
  37. +0 −84 deps/webmachine/priv/skel/src/skel_deps.erl
  38. +0 −13 deps/webmachine/priv/skel/src/skel_resource.erl
  39. +0 −57 deps/webmachine/priv/skel/src/skel_sup.erl
  40. +0 −3 deps/webmachine/priv/skel/start-dev.sh
  41. +0 −3 deps/webmachine/priv/skel/start.sh
  42. +0 −8 deps/webmachine/priv/www/index.html
  43. +0 −32 deps/webmachine/scripts/new_webmachine.erl
  44. +0 −27 deps/webmachine/src/webmachine.app
  45. +0 −63 deps/webmachine/src/webmachine.erl
  46. +0 −36 deps/webmachine/src/webmachine_app.erl
  47. +0 −710 deps/webmachine/src/webmachine_decision_core.erl
  48. +0 −92 deps/webmachine/src/webmachine_deps.erl
  49. +0 −203 deps/webmachine/src/webmachine_dispatcher.erl
  50. +0 −72 deps/webmachine/src/webmachine_error_handler.erl
  51. +0 −28 deps/webmachine/src/webmachine_id.erl
  52. +0 −242 deps/webmachine/src/webmachine_logger.erl
  53. +0 −149 deps/webmachine/src/webmachine_mochiweb.erl
  54. +0 −165 deps/webmachine/src/webmachine_multipart.erl
  55. +0 −211 deps/webmachine/src/webmachine_perf_logger.erl
  56. +0 −717 deps/webmachine/src/webmachine_request.erl
  57. +0 −250 deps/webmachine/src/webmachine_resource.erl
  58. +0 −89 deps/webmachine/src/webmachine_skel.erl
  59. +0 −85 deps/webmachine/src/webmachine_sup.erl
  60. +0 −303 deps/webmachine/src/webmachine_util.erl
  61. +0 −363 deps/webmachine/src/wmtrace_resource.erl
  62. +0 −231 deps/webmachine/src/wrq.erl
  63. +0 −3 deps/webmachine/start-dev.sh
  64. +0 −3 deps/webmachine/start.sh
  65. +0 −107 deps/webmachine/trace/wmtrace.css
  66. +0 −713 deps/webmachine/trace/wmtrace.js
  67. +0 −67 deps/webmachine/www/blogs.html
  68. +0 −48 deps/webmachine/www/contact.html
  69. +0 −103 deps/webmachine/www/css/style-1c.css
  70. +0 −103 deps/webmachine/www/css/style.css
  71. +0 −292 deps/webmachine/www/debugging.html
  72. +0 −57 deps/webmachine/www/diagram.html
  73. +0 −121 deps/webmachine/www/dispatcher.html
  74. +0 −58 deps/webmachine/www/docs.html
  75. +0 −250 deps/webmachine/www/example_resources.html
  76. BIN deps/webmachine/www/favicon.ico
  77. BIN deps/webmachine/www/images/WM200-crop.png
  78. BIN deps/webmachine/www/images/basho-landscape.gif
  79. BIN deps/webmachine/www/images/basic-trace-decision-tab.png
  80. BIN deps/webmachine/www/images/basic-trace-labeled.png
  81. BIN deps/webmachine/www/images/basic-trace-request-tab.png
  82. BIN deps/webmachine/www/images/basic-trace-response-tab.png
  83. BIN deps/webmachine/www/images/bg.gif
  84. BIN deps/webmachine/www/images/blankbox.gif
  85. BIN deps/webmachine/www/images/chash.gif
  86. BIN deps/webmachine/www/images/easy-ops.gif
  87. BIN deps/webmachine/www/images/gossip4.gif
  88. BIN deps/webmachine/www/images/halfblankbox.gif
  89. BIN deps/webmachine/www/images/http-headers-status-v3.png
  90. BIN deps/webmachine/www/images/more.gif
  91. BIN deps/webmachine/www/images/site.gif
  92. BIN deps/webmachine/www/images/splash250.gif
  93. BIN deps/webmachine/www/images/vclock.gif
  94. +0 −73 deps/webmachine/www/index.html
  95. +0 −62 deps/webmachine/www/intros.html
  96. +0 −108 deps/webmachine/www/mechanics.html
  97. +0 −77 deps/webmachine/www/quickstart.html
  98. +0 −52 deps/webmachine/www/reftrans.html
  99. +0 −143 deps/webmachine/www/reqdata.html
  100. +0 −141 deps/webmachine/www/resources.html
  101. +0 −176 deps/webmachine/www/streambody.html
  102. +1 −0 deps/webzmachine
  103. +1 −1 include/zotonic.hrl
  104. +1 −1 modules/mod_development/mod_development.erl
  105. +2 −2 src/zotonic.erl
  106. +3 −3 src/zotonic_sup.erl
  107. +1 −1 start.cmd
View
3 .gitmodules
@@ -0,0 +1,3 @@
+[submodule "deps/webzmachine"]
+ path = deps/webzmachine
+ url = git://github.com/zotonic/webzmachine.git
View
2 Emakefile
@@ -17,7 +17,7 @@
],
[ {i, "include"},
{i, "src/dbdrivers/postgresql/include"},
- {i, "deps/webmachine/include"},
+ {i, "deps/webzmachine/include"},
{outdir, "ebin"},
debug_info
]
View
8 Makefile
@@ -6,7 +6,7 @@ PARSER =src/erlydtl/erlydtl_parser
MAKEFILES := $(shell find -L modules/ priv/sites/ priv/modules/ priv/sites/*/modules/ -maxdepth 2 -name Makefile)
-all: gen_smtp iconv z_logger mochiweb webmachine module-deps $(PARSER).erl erl ebin/$(APP).app
+all: gen_smtp iconv z_logger mochiweb webzmachine module-deps $(PARSER).erl erl ebin/$(APP).app
erl:
@$(ERL) -pa $(EBIN_DIRS) -pa ebin -noinput +B \
@@ -27,8 +27,8 @@ z_logger:
mochiweb:
cd deps/mochiweb && $(MAKE)
-webmachine:
- cd deps/webmachine && $(MAKE)
+webzmachine:
+ cd deps/webzmachine && $(MAKE)
module-deps:
@if [ "${MAKEFILES}" != "" ]; then for f in ${MAKEFILES}; do echo $$f; $(MAKE) -C `dirname $$f`; done; fi
@@ -42,7 +42,7 @@ clean:
(cd deps/gen_smtp; $(MAKE) clean)
(cd deps/z_logger; $(MAKE) clean)
(cd deps/mochiweb; $(MAKE) clean)
- (cd deps/webmachine; $(MAKE) clean)
+ (cd deps/webzmachine; $(MAKE) clean)
(cd deps/iconv; ./rebar clean)
@if [ "${MAKEFILES}" != "" ]; then for f in ${MAKEFILES}; do echo $$f; $(MAKE) -C `dirname $$f` clean; done; fi
rm -f ebin/*.beam ebin/*.app
View
6 deps/webmachine/Emakefile
@@ -1,6 +0,0 @@
-% -*- mode: erlang -*-
-{["src/*"],
- [{i, "include"},
- {outdir, "ebin"},
- debug_info]
-}.
View
178 deps/webmachine/LICENSE
@@ -1,178 +0,0 @@
-
- Apache License
- Version 2.0, January 2004
- http://www.apache.org/licenses/
-
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
-
- 1. Definitions.
-
- "License" shall mean the terms and conditions for use, reproduction,
- and distribution as defined by Sections 1 through 9 of this document.
-
- "Licensor" shall mean the copyright owner or entity authorized by
- the copyright owner that is granting the License.
-
- "Legal Entity" shall mean the union of the acting entity and all
- other entities that control, are controlled by, or are under common
- control with that entity. For the purposes of this definition,
- "control" means (i) the power, direct or indirect, to cause the
- direction or management of such entity, whether by contract or
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
- outstanding shares, or (iii) beneficial ownership of such entity.
-
- "You" (or "Your") shall mean an individual or Legal Entity
- exercising permissions granted by this License.
-
- "Source" form shall mean the preferred form for making modifications,
- including but not limited to software source code, documentation
- source, and configuration files.
-
- "Object" form shall mean any form resulting from mechanical
- transformation or translation of a Source form, including but
- not limited to compiled object code, generated documentation,
- and conversions to other media types.
-
- "Work" shall mean the work of authorship, whether in Source or
- Object form, made available under the License, as indicated by a
- copyright notice that is included in or attached to the work
- (an example is provided in the Appendix below).
-
- "Derivative Works" shall mean any work, whether in Source or Object
- form, that is based on (or derived from) the Work and for which the
- editorial revisions, annotations, elaborations, or other modifications
- represent, as a whole, an original work of authorship. For the purposes
- of this License, Derivative Works shall not include works that remain
- separable from, or merely link (or bind by name) to the interfaces of,
- the Work and Derivative Works thereof.
-
- "Contribution" shall mean any work of authorship, including
- the original version of the Work and any modifications or additions
- to that Work or Derivative Works thereof, that is intentionally
- submitted to Licensor for inclusion in the Work by the copyright owner
- or by an individual or Legal Entity authorized to submit on behalf of
- the copyright owner. For the purposes of this definition, "submitted"
- means any form of electronic, verbal, or written communication sent
- to the Licensor or its representatives, including but not limited to
- communication on electronic mailing lists, source code control systems,
- and issue tracking systems that are managed by, or on behalf of, the
- Licensor for the purpose of discussing and improving the Work, but
- excluding communication that is conspicuously marked or otherwise
- designated in writing by the copyright owner as "Not a Contribution."
-
- "Contributor" shall mean Licensor and any individual or Legal Entity
- on behalf of whom a Contribution has been received by Licensor and
- subsequently incorporated within the Work.
-
- 2. Grant of Copyright License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- copyright license to reproduce, prepare Derivative Works of,
- publicly display, publicly perform, sublicense, and distribute the
- Work and such Derivative Works in Source or Object form.
-
- 3. Grant of Patent License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- (except as stated in this section) patent license to make, have made,
- use, offer to sell, sell, import, and otherwise transfer the Work,
- where such license applies only to those patent claims licensable
- by such Contributor that are necessarily infringed by their
- Contribution(s) alone or by combination of their Contribution(s)
- with the Work to which such Contribution(s) was submitted. If You
- institute patent litigation against any entity (including a
- cross-claim or counterclaim in a lawsuit) alleging that the Work
- or a Contribution incorporated within the Work constitutes direct
- or contributory patent infringement, then any patent licenses
- granted to You under this License for that Work shall terminate
- as of the date such litigation is filed.
-
- 4. Redistribution. You may reproduce and distribute copies of the
- Work or Derivative Works thereof in any medium, with or without
- modifications, and in Source or Object form, provided that You
- meet the following conditions:
-
- (a) You must give any other recipients of the Work or
- Derivative Works a copy of this License; and
-
- (b) You must cause any modified files to carry prominent notices
- stating that You changed the files; and
-
- (c) You must retain, in the Source form of any Derivative Works
- that You distribute, all copyright, patent, trademark, and
- attribution notices from the Source form of the Work,
- excluding those notices that do not pertain to any part of
- the Derivative Works; and
-
- (d) If the Work includes a "NOTICE" text file as part of its
- distribution, then any Derivative Works that You distribute must
- include a readable copy of the attribution notices contained
- within such NOTICE file, excluding those notices that do not
- pertain to any part of the Derivative Works, in at least one
- of the following places: within a NOTICE text file distributed
- as part of the Derivative Works; within the Source form or
- documentation, if provided along with the Derivative Works; or,
- within a display generated by the Derivative Works, if and
- wherever such third-party notices normally appear. The contents
- of the NOTICE file are for informational purposes only and
- do not modify the License. You may add Your own attribution
- notices within Derivative Works that You distribute, alongside
- or as an addendum to the NOTICE text from the Work, provided
- that such additional attribution notices cannot be construed
- as modifying the License.
-
- You may add Your own copyright statement to Your modifications and
- may provide additional or different license terms and conditions
- for use, reproduction, or distribution of Your modifications, or
- for any such Derivative Works as a whole, provided Your use,
- reproduction, and distribution of the Work otherwise complies with
- the conditions stated in this License.
-
- 5. Submission of Contributions. Unless You explicitly state otherwise,
- any Contribution intentionally submitted for inclusion in the Work
- by You to the Licensor shall be under the terms and conditions of
- this License, without any additional terms or conditions.
- Notwithstanding the above, nothing herein shall supersede or modify
- the terms of any separate license agreement you may have executed
- with Licensor regarding such Contributions.
-
- 6. Trademarks. This License does not grant permission to use the trade
- names, trademarks, service marks, or product names of the Licensor,
- except as required for reasonable and customary use in describing the
- origin of the Work and reproducing the content of the NOTICE file.
-
- 7. Disclaimer of Warranty. Unless required by applicable law or
- agreed to in writing, Licensor provides the Work (and each
- Contributor provides its Contributions) on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
- implied, including, without limitation, any warranties or conditions
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
- PARTICULAR PURPOSE. You are solely responsible for determining the
- appropriateness of using or redistributing the Work and assume any
- risks associated with Your exercise of permissions under this License.
-
- 8. Limitation of Liability. In no event and under no legal theory,
- whether in tort (including negligence), contract, or otherwise,
- unless required by applicable law (such as deliberate and grossly
- negligent acts) or agreed to in writing, shall any Contributor be
- liable to You for damages, including any direct, indirect, special,
- incidental, or consequential damages of any character arising as a
- result of this License or out of the use or inability to use the
- Work (including but not limited to damages for loss of goodwill,
- work stoppage, computer failure or malfunction, or any and all
- other commercial damages or losses), even if such Contributor
- has been advised of the possibility of such damages.
-
- 9. Accepting Warranty or Additional Liability. While redistributing
- the Work or Derivative Works thereof, You may choose to offer,
- and charge a fee for, acceptance of support, warranty, indemnity,
- or other liability obligations and/or rights consistent with this
- License. However, in accepting such obligations, You may act only
- on Your own behalf and on Your sole responsibility, not on behalf
- of any other Contributor, and only if You agree to indemnify,
- defend, and hold each Contributor harmless for any liability
- incurred by, or claims asserted against, such Contributor by reason
- of your accepting any such warranty or additional liability.
-
- END OF TERMS AND CONDITIONS
-
View
22 deps/webmachine/Makefile
@@ -1,22 +0,0 @@
-ERL ?= erl
-EBIN_DIRS := $(wildcard deps/*/ebin)
-APP := webmachine
-
-all: erl ebin/$(APP).app
-
-mochi:
- @(cd deps/mochiweb;$(MAKE))
-
-erl:
- @$(ERL) -pa $(EBIN_DIRS) -noinput +B \
- -eval 'case make:all() of up_to_date -> halt(0); error -> halt(1) end.'
-
-edoc:
- @$(ERL) -noshell -run edoc_run application '$(APP)' '"."' '[{preprocess, true},{includes, ["."]}]'
-
-clean:
- @echo "removing:"
- rm -f ebin/*.beam ebin/*.app
-
-ebin/$(APP).app: src/$(APP).app
- cp src/$(APP).app $@
View
19 deps/webmachine/THANKS
@@ -1,19 +0,0 @@
-The following people have contributed to Webmachine:
-
-Andy Gross
-Justin Sheehy
-John Muellerleile
-Robert Ahrens
-Jeremy Latt
-Bryan Fink
-Ryan Tilder
-Taavi Talvik
-Marc Worrell
-Seth Falcon
-Tuncer Ayaz
-Martin Scholl
-Paul Mineiro
-Dave Smith
-Arjan Scherpenisse
-Benjamin Black
-
View
6 deps/webmachine/demo/Emakefile
@@ -1,6 +0,0 @@
-% -*- mode: erlang -*-
-{["src/*"],
- [{i, "include"},
- {outdir, "ebin"},
- debug_info]
-}.
View
19 deps/webmachine/demo/Makefile
@@ -1,19 +0,0 @@
-ERL ?= erl
-EBIN_DIRS := $(wildcard webmachine/ebin)
-APP := webmachine_demo
-
-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 src/$(APP).app $@
View
1 deps/webmachine/demo/ebin/.empty
@@ -1 +0,0 @@
-
View
1 deps/webmachine/demo/priv/.empty
@@ -1 +0,0 @@
-
View
157 deps/webmachine/demo/src/demo_fs_resource.erl
@@ -1,157 +0,0 @@
-%% @author Bryan Fink <bryan@basho.com>
-%% @author Andy Gross <andy@basho.com>
-%% @author Justin Sheehy <justin@basho.com>
-%% @copyright 2008-2009 Basho Technologies, Inc.
-
--module(demo_fs_resource).
--export([init/1]).
--export([allowed_methods/2,
- resource_exists/2,
- last_modified/2,
- content_types_provided/2,
- content_types_accepted/2,
- delete_resource/2,
- post_is_create/2,
- create_path/2,
- provide_content/2,
- accept_content/2,
- generate_etag/2]).
-
--record(context, {root,response_body=undefined,metadata=[]}).
-
--include_lib("kernel/include/file.hrl").
--include_lib("webmachine/include/webmachine.hrl").
-
-init(ConfigProps) ->
- {root, Root} = proplists:lookup(root, ConfigProps),
- {ok, #context{root=Root}}.
-
-allowed_methods(ReqData, Context) ->
- {['HEAD', 'GET', 'PUT', 'DELETE', 'POST'], ReqData, Context}.
-
-file_path(Context, Name) ->
- RelName = case hd(Name) of
- "/" -> tl(Name);
- _ -> Name
- end,
- filename:join([Context#context.root, RelName]).
-
-file_exists(Context, Name) ->
- NamePath = file_path(Context, Name),
- case filelib:is_regular(NamePath) of
- true ->
- {true, NamePath};
- false ->
- false
- end.
-
-resource_exists(ReqData, Context) ->
- Path = wrq:disp_path(ReqData),
- case file_exists(Context, Path) of
- {true, _} ->
- {true, ReqData, Context};
- _ ->
- case Path of
- "p" -> {true, ReqData, Context};
- _ -> {false, ReqData, Context}
- end
- end.
-
-maybe_fetch_object(Context, Path) ->
- % if returns {true, NewContext} then NewContext has response_body
- case Context#context.response_body of
- undefined ->
- case file_exists(Context, Path) of
- {true, FullPath} ->
- {ok, Value} = file:read_file(FullPath),
- {true, Context#context{response_body=Value}};
- false ->
- {false, Context}
- end;
- _Body ->
- {true, Context}
- end.
-
-content_types_provided(ReqData, Context) ->
- CT = webmachine_util:guess_mime(wrq:disp_path(ReqData)),
- {[{CT, provide_content}], ReqData,
- Context#context{metadata=[{'content-type', CT}|Context#context.metadata]}}.
-
-content_types_accepted(ReqData, Context) ->
- CT = case wrq:get_req_header_lc("content-type", ReqData) of
- undefined -> "application/octet-stream";
- X -> X
- end,
- {MT, _Params} = webmachine_util:media_type_to_detail(CT),
- {[{MT, accept_content}], ReqData,
- Context#context{metadata=[{'content-type', MT}|Context#context.metadata]}}.
-
-accept_content(ReqData, Context) ->
- Path = wrq:disp_path(ReqData),
- FP = file_path(Context, Path),
- ok = filelib:ensure_dir(filename:dirname(FP)),
- ReqData1 = case file_exists(Context, Path) of
- {true, _} ->
- ReqData;
- _ ->
- LOC = "http://" ++
- wrq:get_req_header_lc("host", ReqData) ++
- "/fs/" ++ Path,
- wrq:set_resp_header("Location", LOC, ReqData)
- end,
- Value = wrq:req_body(ReqData1),
- case file:write_file(FP, Value) of
- ok ->
- {true, wrq:set_resp_body(Value, ReqData1), Context};
- Err ->
- {{error, Err}, ReqData1, Context}
- end.
-
-post_is_create(ReqData, Context) ->
- {true, ReqData, Context}.
-
-create_path(ReqData, Context) ->
- case wrq:get_req_header_lc("slug", ReqData) of
- undefined -> {undefined, ReqData, Context};
- Slug ->
- case file_exists(Context, Slug) of
- {true, _} -> {undefined, ReqData, Context};
- _ -> {Slug, ReqData, Context}
- end
- end.
-
-delete_resource(ReqData, Context) ->
- case file:delete(file_path(
- Context, wrq:disp_path(ReqData))) of
- ok -> {true, ReqData, Context};
- _ -> {false, ReqData, Context}
- end.
-
-provide_content(ReqData, Context) ->
- case maybe_fetch_object(Context, wrq:disp_path(ReqData)) of
- {true, NewContext} ->
- Body = NewContext#context.response_body,
- {Body, ReqData, Context};
- {false, NewContext} ->
- {error, ReqData, NewContext}
- end.
-
-last_modified(ReqData, Context) ->
- {true, FullPath} = file_exists(Context,
- wrq:disp_path(ReqData)),
- LMod = filelib:last_modified(FullPath),
- {LMod, ReqData, Context#context{metadata=[{'last-modified',
- httpd_util:rfc1123_date(LMod)}|Context#context.metadata]}}.
-
-hash_body(Body) -> mochihex:to_hex(binary_to_list(crypto:sha(Body))).
-
-generate_etag(ReqData, Context) ->
- case maybe_fetch_object(Context, wrq:disp_path(ReqData)) of
- {true, BodyContext} ->
- ETag = hash_body(BodyContext#context.response_body),
- {ETag, ReqData,
- BodyContext#context{metadata=[{etag,ETag}|
- BodyContext#context.metadata]}};
- _ ->
- {undefined, ReqData, Context}
- end.
View
14 deps/webmachine/demo/src/webmachine_demo.app
@@ -1,14 +0,0 @@
-{application, webmachine_demo,
- [{description, "webmachine_demo"},
- {vsn, "0.1"},
- {modules, [
- webmachine_demo,
- webmachine_demo_app,
- webmachine_demo_sup,
- webmachine_demo_resource,
- demo_fs_resource
- ]},
- {registered, []},
- {mod, {webmachine_demo_app, []}},
- {env, []},
- {applications, [kernel, stdlib, crypto]}]}.
View
27 deps/webmachine/demo/src/webmachine_demo.erl
@@ -1,27 +0,0 @@
--module(webmachine_demo).
--author('Andy Gross <andy@basho.com>').
--author('Justin Sheehy <justin@@basho.com>').
--export([start/0, stop/0]).
-
-ensure_started(App) ->
- case application:start(App) of
- ok ->
- ok;
- {error, {already_started, App}} ->
- ok
- end.
-
-%% @spec start() -> ok
-%% @doc Start the webmachine_demo server.
-start() ->
- ensure_started(crypto),
- ensure_started(webmachine),
- application:start(webmachine_demo).
-
-%% @spec stop() -> ok
-%% @doc Stop the webmachine_demo server.
-stop() ->
- Res = application:stop(webmachine_demo),
- application:stop(webmachine),
- application:stop(crypto),
- Res.
View
1 deps/webmachine/demo/src/webmachine_demo.hrl
@@ -1 +0,0 @@
-
View
20 deps/webmachine/demo/src/webmachine_demo_app.erl
@@ -1,20 +0,0 @@
-%% @author Andy Gross <andy@basho.com>
-%% @author Justin Sheehy <justin@basho.com>
-
-%% @doc Callbacks for the webmachine_demo application.
-
--module(webmachine_demo_app).
-
--behaviour(application).
--export([start/2,stop/1]).
-
-
-%% @spec start(_Type, _StartArgs) -> ServerRet
-%% @doc application start callback for webmachine_demo.
-start(_Type, _StartArgs) ->
- webmachine_demo_sup:start_link().
-
-%% @spec stop(_State) -> ServerRet
-%% @doc application stop callback for webmachine_demo.
-stop(_State) ->
- ok.
View
49 deps/webmachine/demo/src/webmachine_demo_resource.erl
@@ -1,49 +0,0 @@
-%% @author Justin Sheehy <justin@basho.com>
-%% @copyright 2007-2009 Basho Technologies, Inc. All Rights Reserved.
-%% @doc Example webmachine_resource.
-
--module(webmachine_demo_resource).
--author('Justin Sheehy <justin@basho.com>').
--export([init/1, to_html/2, to_text/2, content_types_provided/2,
- is_authorized/2, generate_etag/2, expires/2]).
-
--include_lib("webmachine/include/webmachine.hrl").
-
-init([]) -> {ok, undefined}.
-
-content_types_provided(ReqData, Context) ->
- {[{"text/html", to_html},{"text/plain",to_text}], ReqData, Context}.
-
-to_text(ReqData, Context) ->
- Path = wrq:disp_path(ReqData),
- Body = io_lib:format("Hello ~s from webmachine.~n", [Path]),
- {Body, ReqData, Context}.
-
-to_html(ReqData, Context) ->
- {Body, _RD, Ctx2} = to_text(ReqData, Context),
- HBody = io_lib:format("<html><body>~s</body></html>~n",
- [erlang:iolist_to_binary(Body)]),
- {HBody, ReqData, Ctx2}.
-
-is_authorized(ReqData, Context) ->
- case wrq:disp_path(ReqData) of
- "authdemo" ->
- case wrq:get_req_header_lc("authorization", ReqData) of
- "Basic "++Base64 ->
- Str = base64:mime_decode_to_string(Base64),
- case string:tokens(Str, ":") of
- ["authdemo", "demo1"] ->
- {true, ReqData, Context};
- _ ->
- {"Basic realm=webmachine", ReqData, Context}
- end;
- _ ->
- {"Basic realm=webmachine", ReqData, Context}
- end;
- _ -> {true, ReqData, Context}
- end.
-
-expires(ReqData, Context) -> {{{2021,1,1},{0,0,0}}, ReqData, Context}.
-
-generate_etag(ReqData, Context) -> {wrq:raw_path(ReqData), ReqData, Context}.
-
View
42 deps/webmachine/demo/src/webmachine_demo_sup.erl
@@ -1,42 +0,0 @@
-%% @author Justin Sheehy <justin@basho.com>
-%% @author Andy Gross <andy@basho.com>
-%% @copyright 2007-2008 Basho Technologies
-
-%% @doc Supervisor for the webmachine_demo application.
-
--module(webmachine_demo_sup).
--author('Justin Sheehy <justin@basho.com>').
--author('Andy Gross <andy@basho.com>').
-
--behaviour(supervisor).
-
-%% External exports
--export([start_link/0]).
-
-%% supervisor callbacks
--export([init/1]).
-
-%% @spec start_link() -> ServerRet
-%% @doc API for starting the supervisor.
-start_link() ->
- supervisor:start_link({local, ?MODULE}, ?MODULE, []).
-
-dispatch_map() ->
- [{["demo", '*'], webmachine_demo_resource, []},
- {["fs", '*'], demo_fs_resource, [{root, "/tmp/fs"}]}
- ].
-
-%% @doc supervisor callback.
-init([]) ->
- Ip = case os:getenv("WEBMACHINE_IP") of false -> "0.0.0.0"; Any -> Any end,
- WebConfig = [
- {ip, Ip},
- {backlog, 1000},
- {port, 8000},
- {log_dir, "priv/log"},
- {dispatch, dispatch_map()}],
- Web = {webmachine_mochiweb,
- {webmachine_mochiweb, start, [WebConfig]},
- permanent, 5000, worker, dynamic},
- Processes = [Web],
- {ok, {{one_for_one, 10, 10}, Processes}}.
View
3 deps/webmachine/demo/start.sh
@@ -1,3 +0,0 @@
-#!/bin/sh
-cd `dirname $0`
-exec erl -pa $PWD/ebin $PWD/mochiweb/ebin $PWD/webmachine/ebin -boot start_sasl -s webmachine_demo
View
1 deps/webmachine/deps/.empty
@@ -1 +0,0 @@
-
View
1 deps/webmachine/docs/.empty
@@ -1 +0,0 @@
-
View
BIN deps/webmachine/docs/http-headers-status-v3.png
Deleted file not rendered
View
1 deps/webmachine/ebin/.empty
@@ -1 +0,0 @@
-
View
8 deps/webmachine/include/webmachine.hrl
@@ -1,8 +0,0 @@
--export([ping/2]).
-
--include_lib("webmachine/include/wm_reqdata.hrl").
-
-ping(ReqData, State) ->
- {pong, ReqData, State}.
-
-
View
16 deps/webmachine/include/webmachine_logger.hrl
@@ -1,16 +0,0 @@
--define(WMTRACE_CONF_TBL, wmtrace_conf).
-
--record(wm_log_data,
- {req_id :: integer(),
- resource_module :: atom(),
- start_time :: tuple(),
- method :: atom(),
- headers,
- peer,
- path :: string(),
- version,
- response_code,
- response_length,
- end_time :: tuple(),
- finish_time :: tuple()}).
-
View
23 deps/webmachine/include/wm_reqdata.hrl
@@ -1,23 +0,0 @@
--record(wm_reqdata, {
-
- % Reqstate
- socket=undefined,
- metadata=dict:new(),
- range=undefined,
- peer=undefined,
- bodyfetch=undefined,
- log_data=undefined,
-
- % Reqdata
- method, version,
- disp_path, path, raw_path, path_info, path_tokens,
- app_root,response_code,max_recv_body,
- req_cookie, req_qs, req_headers, req_body,
- resp_redirect, resp_headers, resp_body,
- host_tokens, port,
-
- %% Cache of resource calls
- cache=[]
-}).
-
--define(WM_DBG(Msg), error_logger:info_msg("DEBUG: ~p:~p ~p~n", [?MODULE, ?LINE, Msg])).
View
6 deps/webmachine/priv/skel/Emakefile
@@ -1,6 +0,0 @@
-% -*- mode: erlang -*-
-{["src/*"],
- [{i, "include"},
- {outdir, "ebin"},
- debug_info]
-}.
View
19 deps/webmachine/priv/skel/Makefile
@@ -1,19 +0,0 @@
-ERL ?= erl
-EBIN_DIRS := $(wildcard deps/*/ebin)
-APP := skel
-
-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 src/$(APP).app $@
View
0 deps/webmachine/priv/skel/deps/.empty
No changes.
View
0 deps/webmachine/priv/skel/ebin/.empty
No changes.
View
1 deps/webmachine/priv/skel/priv/dispatch.conf
@@ -1 +0,0 @@
-{[], skel_resource, []}.
View
8 deps/webmachine/priv/skel/priv/www/index.html
@@ -1,8 +0,0 @@
-<html>
-<head>
-<title>It Worked</title>
-</head>
-<body>
-MochiWeb running.
-</body>
-</html>
View
14 deps/webmachine/priv/skel/src/skel.app
@@ -1,14 +0,0 @@
-{application, skel,
- [{description, "skel"},
- {vsn, "0.1"},
- {modules, [
- skel,
- skel_app,
- skel_sup,
- skel_deps,
- skel_resource
- ]},
- {registered, []},
- {mod, {skel_app, []}},
- {env, []},
- {applications, [kernel, stdlib, crypto]}]}.
View
44 deps/webmachine/priv/skel/src/skel.erl
@@ -1,44 +0,0 @@
-%% @author author <author@example.com>
-%% @copyright YYYY author.
-
-%% @doc TEMPLATE.
-
--module(skel).
--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() ->
- skel_deps:ensure(),
- ensure_started(crypto),
- application:set_env(webmachine, webmachine_logger_module,
- webmachine_logger),
- ensure_started(webmachine),
- 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),
- ensure_started(webmachine),
- application:start(skel).
-
-%% @spec stop() -> ok
-%% @doc Stop the skel server.
-stop() ->
- Res = application:stop(skel),
- application:stop(webmachine),
- application:stop(crypto),
- Res.
View
1 deps/webmachine/priv/skel/src/skel.hrl
@@ -1 +0,0 @@
-
View
22 deps/webmachine/priv/skel/src/skel_app.erl
@@ -1,22 +0,0 @@
-%% @author author <author@example.com>
-%% @copyright YYYY author.
-
-%% @doc Callbacks for the skel application.
-
--module(skel_app).
--author('author <author@example.com>').
-
--behaviour(application).
--export([start/2,stop/1]).
-
-
-%% @spec start(_Type, _StartArgs) -> ServerRet
-%% @doc application start callback for skel.
-start(_Type, _StartArgs) ->
- skel_deps:ensure(),
- skel_sup:start_link().
-
-%% @spec stop(_State) -> ServerRet
-%% @doc application stop callback for skel.
-stop(_State) ->
- ok.
View
84 deps/webmachine/priv/skel/src/skel_deps.erl
@@ -1,84 +0,0 @@
-%% @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(skel_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).
View
13 deps/webmachine/priv/skel/src/skel_resource.erl
@@ -1,13 +0,0 @@
-%% @author author <author@example.com>
-%% @copyright YYYY author.
-%% @doc Example webmachine_resource.
-
--module(skel_resource).
--export([init/1, to_html/2]).
-
--include_lib("webmachine/include/webmachine.hrl").
-
-init([]) -> {ok, undefined}.
-
-to_html(ReqData, State) ->
- {"<html><body>Hello, new world</body></html>", ReqData, State}.
View
57 deps/webmachine/priv/skel/src/skel_sup.erl
@@ -1,57 +0,0 @@
-%% @author author <author@example.com>
-%% @copyright YYYY author.
-
-%% @doc Supervisor for the skel application.
-
--module(skel_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}}.
View
3 deps/webmachine/priv/skel/start-dev.sh
@@ -1,3 +0,0 @@
-#!/bin/sh
-cd `dirname $0`
-exec erl -pa $PWD/ebin $PWD/deps/*/ebin $PWD/deps/*/deps/*/ebin -boot start_sasl -s reloader -s skel
View
3 deps/webmachine/priv/skel/start.sh
@@ -1,3 +0,0 @@
-#!/bin/sh
-cd `dirname $0`
-exec erl -pa $PWD/ebin $PWD/deps/*/ebin $PWD/deps/*/deps/*/ebin -boot start_sasl -s skel
View
8 deps/webmachine/priv/www/index.html
@@ -1,8 +0,0 @@
-<html>
-<head>
-<title>It Worked</title>
-</head>
-<body>
-Running.
-</body>
-</html>
View
32 deps/webmachine/scripts/new_webmachine.erl
@@ -1,32 +0,0 @@
-#!/usr/bin/env escript
-%% -*- mode: erlang -*-
--export([main/1]).
-
-%% External API
-
-main([Name]) ->
- case Name of
- "." ++ _Rest -> usage();
- "~" ++ _Rest -> usage();
- "/" ++ _Rest -> usage();
- _Any -> main([Name, "."])
- end;
-main([Name, Dest]) ->
- ensure(),
- DestDir = filename:absname(Dest),
- ok = webmachine_skel:skelcopy(DestDir, Name);
-main(_) ->
- usage().
-
-%% Internal API
-
-ensure() ->
- code:add_patha(filename:join(filename:dirname(escript:script_name()),
- "../ebin")).
-
-usage() ->
- io:format("usage: ~s name [destdir]~n",
- [filename:basename(escript:script_name())]),
- halt(1).
-
-
View
27 deps/webmachine/src/webmachine.app
@@ -1,27 +0,0 @@
-{application, webmachine,
- [{description, "webmachine"},
- {vsn, "1.5"},
- {modules, [
- webmachine,
- webmachine_app,
- webmachine_decision_core,
- webmachine_deps,
- webmachine_dispatcher,
- webmachine_error_handler,
- webmachine_logger,
- webmachine_perf_logger,
- webmachine_resource,
- webmachine_request,
- webmachine_request_srv,
- webmachine_skel,
- webmachine_sup,
- webmachine_mochiweb,
- webmachine_multipart,
- webmachine_util,
- wrq,
- wmtrace_resource
- ]},
- {registered, []},
- {mod, {webmachine_app, []}},
- {env, [{node_id, 1}]},
- {applications, [kernel, stdlib, crypto]}]}.
View
63 deps/webmachine/src/webmachine.erl
@@ -1,63 +0,0 @@
-%% @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([init_reqdata/2]).
-
--include("webmachine_logger.hrl").
--include_lib("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).
-
-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}.
-
-
-
-
-
View
36 deps/webmachine/src/webmachine_app.erl
@@ -1,36 +0,0 @@
-%% @author Justin Sheehy <justin@basho.com>
-%% @author Andy Gross <andy@basho.com>
-%% @copyright 2007-2008 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.
-
-%% @doc Callbacks for the webmachine application.
-
--module(webmachine_app).
--author('Justin Sheehy <justin@basho.com>').
--author('Andy Gross <andy@basho.com>').
-
--behaviour(application).
--export([start/2,stop/1]).
-
-
-%% @spec start(_Type, _StartArgs) -> ServerRet
-%% @doc application start callback for webmachine.
-start(_Type, _StartArgs) ->
- webmachine_deps:ensure(),
- webmachine_sup:start_link().
-
-%% @spec stop(_State) -> ServerRet
-%% @doc application stop callback for webmachine.
-stop(_State) ->
- ok.
View
710 deps/webmachine/src/webmachine_decision_core.erl
@@ -1,710 +0,0 @@
-%% @author Justin Sheehy <justin@basho.com>
-%% @author Andy Gross <andy@basho.com>
-%% @author Bryan Fink <bryan@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.
-
-%% @doc Decision core for webmachine
-
--module(webmachine_decision_core).
--author('Justin Sheehy <justin@basho.com>').
--author('Andy Gross <andy@basho.com>').
--author('Bryan Fink <bryan@basho.com>').
--export([handle_request/2]).
--export([do_log/1]).
--include("webmachine_logger.hrl").
--include("wm_reqdata.hrl").
-
-handle_request(Resource, ReqData) ->
- try
- d(v3b13, Resource, ReqData)
- catch
- error:X ->
- ?WM_DBG(X),
- error_response(erlang:get_stacktrace(), Resource, ReqData)
- end.
-
-%% @doc Call the resource or a default.
-%% @spec resource_call(atom(), Resource, ReqData) -> {term(), NewResource, NewReqData}
-resource_call(Fun, Rs, Rd) ->
- case cacheable(Fun) of
- true ->
- case proplists:lookup(Fun, Rd#wm_reqdata.cache) of
- none ->
- {T, Rs1, Rd1} = Rs:do(Fun, Rd),
- {T, Rs1, Rd1#wm_reqdata{cache=[{Fun,T}|Rd1#wm_reqdata.cache]}};
- {Fun, Cached} ->
- {Cached, Rs, Rd}
- end;
- false ->
- Rs:do(Fun, Rd)
- end.
-
-cacheable(charsets_provided) -> true;
-cacheable(content_types_provided) -> true;
-cacheable(encodings_provided) -> true;
-cacheable(last_modified) -> true;
-cacheable(generate_etag) -> true;
-cacheable(_) -> false.
-
-
-get_header_val(H, Rd) ->
- wrq:get_req_header_lc(H, Rd).
-
-method(Rd) ->
- wrq:method(Rd).
-
-d(DecisionID, Rs, Rd) ->
- Rs:log_d(DecisionID),
- decision(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),
- Reason = {none, none, []},
- {ErrorHTML, RdError} = ErrorHandler:render_error(Code, Rd, Reason),
- {Rs, wrq:set_resp_body(ErrorHTML, RdError)};
- 304 ->
- RdNoCT = wrq:remove_resp_header("Content-Type", Rd),
- {Etag, RsEt, RdEt0} = resource_call(generate_etag, Rs, RdNoCT),
- RdEt = case Etag of
- undefined -> RdEt0;
- ETag -> wrq:set_resp_header("ETag", ETag, RdEt0)
- end,
- {Expires, RsExp, RdExp0} = resource_call(expires, RsEt, RdEt),
- RdExp = case Expires of
- undefined -> RdExp0;
- Exp -> wrq:set_resp_header("Expires", httpd_util:rfc1123_date(calendar:universal_time_to_local_time(Exp)), RdExp0)
- end,
- {RsExp, RdExp};
- _ ->
- {Rs, Rd}
- end,
- RdRespCode = wrq:set_response_code(Code, RdCode),
- resource_call(finish_request, RsCode, RdRespCode).
-
-respond(Code, Headers, Rs, Rd) ->
- RdHs = wrq:set_resp_headers(Headers, Rd),
- respond(Code, Rs, RdHs).
-
-error_response(Code, Reason, Rs, Rd) ->
- {ok, ErrorHandler} = application:get_env(webmachine, error_handler),
- {ErrorHTML, Rd1} = ErrorHandler:render_error(Code, Rd, Reason),
- Rd2 = wrq:set_resp_body(ErrorHTML, Rd1),
- respond(Code, Rs, Rd2).
-error_response(Reason, Rs, Rd) ->
- error_response(500, Reason, Rs, Rd).
-
-decision_test({Test, Rs, Rd}, TestVal, TrueFlow, FalseFlow) ->
- decision_test(Test, TestVal, TrueFlow, FalseFlow, Rs, Rd).
-
-decision_test(Test,TestVal,TrueFlow,FalseFlow, Rs, Rd) ->
- case Test of
- {error, Reason} -> error_response(Reason, Rs, Rd);
- {error, Reason0, Reason1} -> error_response({Reason0, Reason1}, Rs, Rd);
- {halt, Code} -> respond(Code, Rs, Rd);
- TestVal -> decision_flow(TrueFlow, Test, Rs, Rd);
- _ -> decision_flow(FalseFlow, Test, Rs, Rd)
- end.
-
-decision_flow(X, TestResult, Rs, Rd) when is_integer(X) ->
- if X >= 500 -> error_response(X, TestResult, Rs, Rd);
- true -> respond(X, Rs, Rd)
- end;
-decision_flow(X, _TestResult, Rs, Rd) when is_atom(X) ->
- d(X, Rs, Rd);
-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
- {ok, LoggerModule} -> LoggerModule:log_access(LogData);
- _ -> nop
- end,
- case application:get_env(webmachine, enable_perf_logger) of
- {ok, true} ->
- webmachine_perf_logger:log(LogData);
- _ ->
- ignore
- end.
-
-
-%% "Service Available"
-decision(v3b13, Rs, Rd) ->
- decision_test(resource_call(ping, Rs, Rd), pong, v3b13b, 503);
-decision(v3b13b, Rs, Rd) ->
- decision_test(resource_call(service_available, Rs, Rd), true, v3b12, 503);
-%% "Known method?"
-decision(v3b12, Rs, Rd) ->
- {Methods, Rs1, Rd1} = resource_call(known_methods, Rs, Rd),
- decision_test(lists:member(method(Rd1), Methods), true, v3b11, 501, Rs1, Rd1);
-%% "URI too long?"
-decision(v3b11, Rs, Rd) ->
- decision_test(resource_call(uri_too_long, Rs, Rd), true, 414, v3b10);
-%% "Method allowed?"
-decision(v3b10, Rs, Rd) ->
- {Methods, Rs1, Rd1} = resource_call(allowed_methods, Rs, Rd),
- case lists:member(method(Rd1), Methods) of
- true ->
- d(v3b9, Rs1, Rd1);
- false ->
- RdAllow = wrq:set_resp_header("Allow", string:join([atom_to_list(M) || M <- Methods], ", "), Rd1),
- respond(405, Rs1, RdAllow)
- end;
-%% "Malformed?"
-decision(v3b9, Rs, Rd) ->
- decision_test(resource_call(malformed_request, Rs, Rd), true, 400, v3b8);
-%% "Authorized?"
-decision(v3b8, Rs, Rd) ->
- {IsAuthorized, Rs1, Rd1} = resource_call(is_authorized, Rs, Rd),
- case IsAuthorized of
- true ->
- d(v3b7, Rs1, Rd1);
- {error, Reason} ->
- error_response(Reason, Rs1, Rd1);
- {halt, Code} ->
- respond(Code, Rs1, Rd1);
- AuthHead ->
- RdAuth = wrq:set_resp_header("WWW-Authenticate", AuthHead, Rd1),
- respond(401, Rs1, RdAuth)
- end;
-%% "Forbidden?"
-decision(v3b7, Rs, Rd) ->
- decision_test(resource_call(forbidden, Rs, Rd), true, 403, v3b6_upgrade);
-%% "Upgrade?"
-decision(v3b6_upgrade, Rs, Rd) ->
- case get_header_val("upgrade", Rd) of
- undefined ->
- decision(v3b6, Rs, Rd);
- UpgradeHdr ->
- case get_header_val("connection", Rd) of
- undefined ->
- decision(v3b6, Rs, Rd);
- Connection ->
- case string:strip(string:to_lower(Connection)) of
- "upgrade" ->
- {Choosen, Rs1, Rd1} = choose_upgrade(UpgradeHdr, Rs, Rd),
- case Choosen of
- none ->
- decision(v3b6, Rs1, Rd1);
- {_Protocol, UpgradeFunc} ->
- %% TODO: log the upgrade action
- {upgrade, UpgradeFunc, Rs1, Rd1}
- end;
- _ ->
- decision(v3b6, Rs, Rd)
- end
- end
- end;
-%% "Okay Content-* Headers?"
-decision(v3b6, Rs, Rd) ->
- decision_test(resource_call(valid_content_headers, Rs, Rd), true, v3b5, 501);
-%% "Known Content-Type?"
-decision(v3b5, Rs, Rd) ->
- decision_test(resource_call(known_content_type, Rs, Rd), true, v3b4, 415);
-%% "Req Entity Too Large?"
-decision(v3b4, Rs, Rd) ->
- decision_test(resource_call(valid_entity_length, Rs, Rd), true, v3b3, 413);
-%% "OPTIONS?"
-decision(v3b3, Rs, Rd) ->
- case wrq:method(Rd) of
- 'OPTIONS' ->
- {Hdrs, Rs1, Rd1} = resource_call(options, Rs, Rd),
- respond(200, Hdrs, Rs1, Rd1);
- _ ->
- d(v3c3, Rs, Rd)
- end;
-%% Accept exists?
-decision(v3c3, Rs, Rd) ->
- {ContentTypes, Rs1, Rd1} = resource_call(content_types_provided, Rs, Rd),
- PTypes = [Type || {Type,_Fun} <- ContentTypes],
- case get_header_val("accept", Rd1) of
- undefined ->
- {ok, RdCT} = webmachine_request:set_metadata('content-type', hd(PTypes), Rd1),
- d(v3d4, Rs1, RdCT);
- _ ->
- d(v3c4, Rs1, Rd1)
- end;
-%% Acceptable media type available?
-decision(v3c4, Rs, Rd) ->
- {ContentTypesProvided, Rs1, Rd1} = resource_call(content_types_provided, Rs, Rd),
- PTypes = [Type || {Type,_Fun} <- ContentTypesProvided],
- AcceptHdr = get_header_val("accept", Rd1),
- case webmachine_util:choose_media_type(PTypes, AcceptHdr) of
- none ->
- respond(406, Rs1, Rd1);
- MType ->
- {ok, RdCT} = webmachine_request:set_metadata('content-type', MType, Rd1),
- d(v3d4, Rs, RdCT)
- end;
-%% Accept-Language exists?
-decision(v3d4, Rs, Rd) ->
- decision_test(get_header_val("accept-language", Rd), undefined, v3e5, v3d5, Rs, Rd);
-%% Acceptable Language available? %% WMACH-46 (do this as proper conneg)
-decision(v3d5, Rs, Rd) ->
- decision_test(resource_call(language_available, Rs, Rd), true, v3e5, 406);
-%% Accept-Charset exists?
-decision(v3e5, Rs, Rd) ->
- case get_header_val("accept-charset", Rd) of
- undefined -> decision_test(choose_charset("*", Rs, Rd), none, 406, v3f6);
- _ -> d(v3e6, Rs, Rd)
- end;
-%% Acceptable Charset available?
-decision(v3e6, Rs, Rd) ->
- decision_test(choose_charset(get_header_val("accept-charset", Rd), Rs, Rd), none, 406, v3f6);
-%% Accept-Encoding exists?
-% (also, set content-type header here, now that charset is chosen)
-decision(v3f6, Rs, Rd) ->
- CType = webmachine_request:get_metadata('content-type', Rd),
- CSet = case webmachine_request:get_metadata('chosen-charset', Rd) of
- undefined -> "";
- CS -> "; charset=" ++ CS
- end,
- Rd1 = wrq:set_resp_header("Content-Type", CType ++ CSet, Rd),
- case get_header_val("accept-encoding", Rd1) of
- undefined -> decision_test(choose_encoding("identity;q=1.0,*;q=0.5", Rs, Rd1), none, 406, v3g7);
- _ -> d(v3f7, Rs, Rd1)
- end;
-%% Acceptable encoding available?
-decision(v3f7, Rs, Rd) ->
- decision_test(choose_encoding(get_header_val("accept-encoding", Rd), Rs, Rd), none, 406, v3g7);
-%% "Resource exists?"
-decision(v3g7, Rs, Rd) ->
- % this is the first place after all conneg, so set Vary here
- {Variances, Rs1, Rd1} = variances(Rs, Rd),
- RdVar = case Variances of
- [] -> Rd1;
- _ -> wrq:set_resp_header("Vary", string:join(Variances, ", "), Rd1)
- end,
- decision_test(resource_call(resource_exists, Rs1, RdVar), true, v3g8, v3h7);
-%% "If-Match exists?"
-decision(v3g8, Rs, Rd) ->
- decision_test(get_header_val("if-match", Rd), undefined, v3h10, v3g9, Rs, Rd);
-%% "If-Match: * exists"
-decision(v3g9, Rs, Rd) ->
- decision_test(get_header_val("if-match", Rd), "*", v3h10, v3g11, Rs, Rd);
-%% "ETag in If-Match"
-decision(v3g11, Rs, Rd) ->
- ReqETag = webmachine_util:unquote_header(get_header_val("if-match", Rd)),
- decision_test(resource_call(generate_etag, Rs, Rd), ReqETag, v3h10, 412);
-%% "If-Match: * exists"
-decision(v3h7, Rs, Rd) ->
- decision_test(get_header_val("if-match", Rd), "*", 412, v3i7, Rs, Rd);
-%% "If-unmodified-since exists?"
-decision(v3h10, Rs, Rd) ->
- decision_test(get_header_val("if-unmodified-since", Rd), undefined, v3i12, v3h11, Rs, Rd);
-%% "I-UM-S is valid date?"
-decision(v3h11, Rs, Rd) ->
- IUMSDate = get_header_val("if-unmodified-since", Rd),
- decision_test(webmachine_util:convert_request_date(IUMSDate), bad_date, v3i12, v3h12, Rs, Rd);
-%% "Last-Modified > I-UM-S?"
-decision(v3h12, Rs, Rd) ->
- ReqDate = get_header_val("if-unmodified-since", Rd),
- ReqErlDate = webmachine_util:convert_request_date(ReqDate),
- {ResErlDate, Rs1, Rd1} = resource_call(last_modified, Rs, Rd),
- decision_test(ResErlDate > ReqErlDate, true, 412, v3i12, Rs1, Rd1);
-%% "Moved permanently? (apply PUT to different URI)"
-decision(v3i4, Rs, Rd) ->
- {MovedPermanently, Rs1, Rd1} = resource_call(moved_permanently, Rs, Rd),
- case MovedPermanently of
- {true, MovedURI} ->
- RdLoc = wrq:set_resp_header("Location", MovedURI, Rd1),
- respond(301, Rs1, RdLoc);
- false ->
- d(v3p3, Rs1, Rd1);
- {error, Reason} ->
- error_response(Reason, Rs1, Rd1);
- {halt, Code} ->
- respond(Code, Rs1, Rd1)
- end;
-%% PUT?
-decision(v3i7, Rs, Rd) ->
- decision_test(method(Rd), 'PUT', v3i4, v3k7, Rs, Rd);
-%% "If-none-match exists?"
-decision(v3i12, Rs, Rd) ->
- decision_test(get_header_val("if-none-match", Rd), undefined, v3l13, v3i13, Rs, Rd);
-%% "If-None-Match: * exists?"
-decision(v3i13, Rs, Rd) ->
- decision_test(get_header_val("if-none-match", Rd), "*", v3j18, v3k13, Rs, Rd);
-%% GET or HEAD?
-decision(v3j18, Rs, Rd) ->
- decision_test(lists:member(method(Rd),['GET','HEAD']), true, 304, 412, Rs, Rd);
-%% "Moved permanently?"
-decision(v3k5, Rs, Rd) ->
- {MovedPermanently, Rs1, Rd1} = resource_call(moved_permanently, Rs, Rd),
- case MovedPermanently of
- {true, MovedURI} ->
- RdLoc = wrq:set_resp_header("Location", MovedURI, Rd1),
- respond(301, Rs1, RdLoc);
- false ->
- d(v3l5, Rs1, Rd1);
- {error, Reason} ->
- error_response(Reason, Rs1, Rd1);
- {halt, Code} ->
- respond(Code, Rs1, Rd1)
- end;
-%% "Previously existed?"
-decision(v3k7, Rs, Rd) ->
- decision_test(resource_call(previously_existed, Rs, Rd), true, v3k5, v3l7);
-%% "Etag in if-none-match?"
-decision(v3k13, Rs, Rd) ->
- ReqETag = webmachine_util:unquote_header(get_header_val("if-none-match", Rd)),
- decision_test(resource_call(generate_etag, Rs, Rd), ReqETag, v3j18, v3l13);
-%% "Moved temporarily?"
-decision(v3l5, Rs, Rd) ->
- {MovedTemporarily, Rs1, Rd1} = resource_call(moved_temporarily, Rs, Rd),
- case MovedTemporarily of
- {true, MovedURI} ->
- RdLoc = wrq:set_resp_header("Location", MovedURI, Rd1),
- respond(307, Rs1, RdLoc);
- false ->
- d(v3m5, Rs1, Rd1);
- {error, Reason} ->
- error_response(Reason, Rs1, Rd1);
- {halt, Code} ->
- respond(Code, Rs1, Rd1)
- end;
-%% "POST?"
-decision(v3l7, Rs, Rd) ->
- decision_test(method(Rd), 'POST', v3m7, 404, Rs, Rd);
-%% "IMS exists?"
-decision(v3l13, Rs, Rd) ->
- decision_test(get_header_val("if-modified-since", Rd), undefined, v3m16, v3l14, Rs, Rd);
-%% "IMS is valid date?"
-decision(v3l14, Rs, Rd) ->
- IMSDate = get_header_val("if-modified-since", Rd),
- decision_test(webmachine_util:convert_request_date(IMSDate), bad_date, v3m16, v3l15, Rs, Rd);
-%% "IMS > Now?"
-decision(v3l15, Rs, Rd) ->
- NowDateTime = calendar:universal_time(),
- ReqDate = get_header_val("if-modified-since", Rd),
- ReqErlDate = webmachine_util:convert_request_date(ReqDate),
- decision_test(ReqErlDate > NowDateTime, true, v3m16, v3l17, Rs, Rd);
-%% "Last-Modified > IMS?"
-decision(v3l17, Rs, Rd) ->
- ReqDate = get_header_val("if-modified-since", Rd),
- ReqErlDate = webmachine_util:convert_request_date(ReqDate),
- {ResErlDate, Rs1, Rd1} = resource_call(last_modified, Rs, Rd),
- decision_test(ResErlDate =:= undefined orelse ResErlDate > ReqErlDate,
- true, v3m16, 304, Rs1, Rd1);
-%% "POST?"
-decision(v3m5, Rs, Rd) ->
- decision_test(method(Rd), 'POST', v3n5, 410, Rs, Rd);
-%% "Server allows POST to missing resource?"
-decision(v3m7, Rs, Rd) ->
- decision_test(resource_call(allow_missing_post, Rs, Rd), true, v3n11, 404);
-%% "DELETE?"
-decision(v3m16, Rs, Rd) ->
- decision_test(method(Rd), 'DELETE', v3m20, v3n16, Rs, Rd);
-%% DELETE enacted immediately?
-%% Also where DELETE is forced.
-decision(v3m20, Rs, Rd) ->
- decision_test(resource_call(delete_resource, Rs, Rd), true, v3m20b, 500);
-decision(v3m20b, Rs, Rd) ->
- decision_test(resource_call(delete_completed, Rs, Rd), true, v3o20, 202);
-%% "Server allows POST to missing resource?"
-decision(v3n5, Rs, Rd) ->
- decision_test(resource_call(allow_missing_post, Rs, Rd), true, v3n11, 410);
-%% "Redirect?"
-decision(v3n11, Rs, Rd) ->
- {PostIsCreate, Rs1, Rd1} = resource_call(post_is_create, Rs, Rd),
- {Stage1, RsStage1, RdStage1} = case PostIsCreate of
- true ->
- {CreatePath, Rs2, Rd2} = resource_call(create_path, Rs1, Rd1),
- case CreatePath of
- undefined ->
- error_response("post_is_create w/o create_path", Rs2, Rd2);
- NewPath ->
- case is_list(NewPath) of
- false ->
- error_response("create_path not a string", Rs2, Rd2);
- true ->
- RdPath = wrq:set_disp_path(NewPath, Rd2),
- {Res, Rs3, Rd3} = accept_helper(Rs2, RdPath),
- case Res of
- {respond, Code} -> respond(Code, Rs3, Rd3);
- {halt, Code} -> respond(Code, Rs3, Rd3);
- {error, _,_} -> error_response(Res, Rs3, Rd3);
- {error, _} -> error_response(Res, Rs3, Rd3);
- _ -> {stage1_ok, Rs3, Rd3}
- end
- end
- end;
- _ ->
- {ProcessPost, Rs2, Rd2} = resource_call(process_post, Rs1, Rd1),
- case ProcessPost of
- true ->
- {_, Rs3, Rd3} = encode_body_if_set(Rs2, Rd2),
- {stage1_ok, Rs3, Rd3};
- {halt, Code} -> respond(Code, Rs2, Rd2);
- Err -> error_response(Err, Rs2, Rd2)
- end
- end,
- case Stage1 of
- stage1_ok ->
- case wrq:resp_redirect(RdStage1) of
- true ->
- case wrq:get_resp_header("Location", RdStage1) of
- undefined ->
- respond(500, "Response had do_redirect but no Location", RsStage1, RdStage1);
- _ ->
- respond(303, RsStage1, RdStage1)
- end;
- _ ->
- d(v3p11, RsStage1, RdStage1)
- end;
- _ ->
- {nop, RsStage1, RdStage1}
- end;
-%% "POST?"
-decision(v3n16, Rs, Rd) ->
- decision_test(method(Rd), 'POST', v3n11, v3o16, Rs, Rd);
-%% Conflict?
-decision(v3o14, Rs, Rd) ->
- {IsConflict, Rs1, Rd1} = resource_call(is_conflict, Rs, Rd),
- case IsConflict of
- true -> respond(409, Rs1, Rd1);
- _ ->
- {Res, RsHelp, RdHelp} = accept_helper(Rs1, Rd1),
- case Res of
- {respond, Code} -> respond(Code, RsHelp, RdHelp);
- {halt, Code} -> respond(Code, RsHelp, RdHelp);
- {error, _,_} -> error_response(Res, RsHelp, RdHelp);
- {error, _} -> error_response(Res, RsHelp, RdHelp);
- _ -> d(v3p11, RsHelp, RdHelp)
- end
- end;
-%% "PUT?"
-decision(v3o16, Rs, Rd) ->
- decision_test(method(Rd), 'PUT', v3o14, v3o18, Rs, Rd);
-%% Multiple representations?
-% (also where body generation for GET and HEAD is done)
-decision(v3o18, Rs, Rd) ->
- BuildBody = case method(Rd) of
- 'GET' -> true;
- 'HEAD' -> true;
- _ -> false
- end,
- {FinalBody, RsBody, RdBody} = case BuildBody of
- true ->
- {Etag, RsEtag, RdEtag0} = resource_call(generate_etag, Rs, Rd),
- RdEtag = case Etag of
- undefined -> RdEtag0;
- ETag -> wrq:set_resp_header("ETag", ETag, RdEtag0)
- end,
-
- {LastModified, RsLM, RdLM0} = resource_call(last_modified, RsEtag, RdEtag),
- RdLM = case LastModified of
- undefined -> RdLM0;
- LM -> wrq:set_resp_header("Last-Modified", httpd_util:rfc1123_date(calendar:universal_time_to_local_time(LM)), RdLM0)
- end,
-
- {Expires, RsExp, RdExp0} = resource_call(expires, RsLM, RdLM),
- RdExp = case Expires of
- undefined -> RdExp0;
- Exp -> wrq:set_resp_header("Expires", httpd_util:rfc1123_date(calendar:universal_time_to_local_time(Exp)), RdExp0)
- end,
-
- CT = webmachine_request:get_metadata('content-type', RdExp),
- {ContentTypesProvided, RsCT, RdCT} = resource_call(content_types_provided, RsExp, RdExp),
- F = hd([Fun || {Type,Fun} <- ContentTypesProvided, CT =:= Type]),
- resource_call(F, RsCT, RdCT);
- false ->
- {nop, Rs, Rd}
- end,
- case FinalBody of
- {error, _} -> error_response(FinalBody, RsBody, RdBody);
- {error, _,_} -> error_response(FinalBody, RsBody, RdBody);
- {halt, Code} -> respond(Code, RsBody, RdBody);
- nop -> d(v3o18b, RsBody, RdBody);
- _ ->
- {EncodedBody, RsEB, RdEB} = encode_body(FinalBody, RsBody, RdBody),
- d(v3o18b, RsEB, wrq:set_resp_body(EncodedBody, RdEB))
- end;
-
-decision(v3o18b, Rs, Rd) ->
- decision_test(resource_call(multiple_choices, Rs, Rd), true, 300, 200);
-%% Response includes an entity?
-decision(v3o20, Rs, Rd) ->
- decision_test(webmachine_request:has_resp_body(Rd), true, v3o18, 204, Rs, Rd);
-%% Conflict?
-decision(v3p3, Rs, Rd) ->
- {IsConflict, Rs1, Rd1} = resource_call(is_conflict, Rs, Rd),
- case IsConflict of
- true -> respond(409, Rs1, Rd1);
- _ ->
- {Res, RsHelp, RdHelp} = accept_helper(Rs1, Rd1),
- case Res of
- {respond, Code} -> respond(Code, RsHelp, RdHelp);
- {halt, Code} -> respond(Code, RsHelp, RdHelp);
- {error, _,_} -> error_response(Res, RsHelp, RdHelp);
- {error, _} -> error_response(Res, RsHelp, RdHelp);
- _ -> d(v3p11, RsHelp, RdHelp)
- end
- end;
-
-%% New resource? (at this point boils down to "has location header")
-decision(v3p11, Rs, Rd) ->
- case wrq:get_resp_header("Location", Rd) of
- undefined -> d(v3o20, Rs, Rd);
- _ -> respond(201, Rs, Rd)
- end.
-
-accept_helper(Rs, Rd) ->
- CT = case get_header_val("content-type", Rd) of
- undefined -> "application/octet-stream";
- Other -> Other
- end,
- {MT, MParams} = webmachine_util:media_type_to_detail(CT),
- {ok, RdMParams} = webmachine_request:set_metadata('mediaparams', MParams, Rd),
- {ContentTypesAccepted, Rs1, Rd1} = resource_call(content_types_accepted, Rs, RdMParams),
- case [Fun || {Type,Fun} <- ContentTypesAccepted, MT =:= Type] of
- [] ->
- {{respond, 415}, Rs1, Rd1};
- AcceptedContentList ->
- F = hd(AcceptedContentList),
- {Result, Rs2, Rd2} = resource_call(F, Rs1, Rd1),
- case Result of
- true ->
- {_, RsEncoded, RdEncoded} = encode_body_if_set(Rs2, Rd2),
- {true, RsEncoded, RdEncoded};
- _ ->
- {Result, Rs2, Rd2}
- end
- end.
-
-encode_body_if_set(Rs, Rd) ->
- case webmachine_request:has_resp_body(Rd) of
- true ->
- Body = wrq:resp_body(Rd),
- {Encoded, Rs1, Rd1} = encode_body(Body, Rs, Rd),
- {true, Rs1, wrq:set_resp_body(Encoded, Rd1)};
- _ ->
- {false, Rs, Rd}
- end.
-
-encode_body(Body, Rs, Rd) ->
- ChosenCSet = webmachine_request:get_metadata('chosen-charset', Rd),
- {CharSetsProvided, Rs1, Rd1} = resource_call(charsets_provided, Rs, Rd),
- Charsetter =
- case CharSetsProvided of
- no_charset -> fun(X) -> X end;
- CP -> hd([Fun || {CSet,Fun} <- CP, ChosenCSet =:= CSet])
- end,
- ChosenEnc = webmachine_request:get_metadata('content-encoding', Rd1),
- {EncodingsProvided, Rs2, Rd2} = resource_call(encodings_provided, Rs1, Rd1),
- Encoder = hd([Fun || {Enc,Fun} <- EncodingsProvided, ChosenEnc =:= Enc]),
- case Body of
- {stream, StreamBody} ->
- {{stream, make_encoder_stream(Encoder, Charsetter, StreamBody)}, Rs2, Rd2};
- {stream, Size, Fun} ->
- {stream, Size, make_size_encoder_stream(Encoder, Charsetter, Fun)};
- {writer, BodyFun} ->
- {{writer, {Encoder, Charsetter, BodyFun}}, Rs2, Rd2};
- {writer, Size, BodyFun} ->
- {{writer, Size, {Encoder, Charsetter, BodyFun}}, Rs2, Rd2};
- _ ->
- {Encoder(Charsetter(to_binary(Body))), Rs2, Rd2}
- end.
-
- to_binary(Body) when is_tuple(Body) -> Body;
- to_binary(Body) -> iolist_to_binary(Body).
-
-make_size_encoder_stream(Encoder, Charsetter, Fun) ->
- fun(Start, End) ->
- make_encoder_stream(Encoder, Charsetter, Fun(Start, End))
- end.
-
-make_encoder_stream(Encoder, Charsetter, {Body, done}) ->
- {Encoder(Charsetter(Body)), done};
-make_encoder_stream(Encoder, Charsetter, {Body, Next}) ->
- {Encoder(Charsetter(Body)), fun() -> make_encoder_stream(Encoder, Charsetter, Next()) end}.
-
-choose_encoding(AccEncHdr, Rs, Rd) ->
- {EncodingsProvided, Rs1, Rd1} = resource_call(encodings_provided, Rs, Rd),
- Encs = [Enc || {Enc,_Fun} <- EncodingsProvided],
- case webmachine_util:choose_encoding(Encs, AccEncHdr) of
- none ->
- {none, Rs1, Rd1};
- ChosenEnc ->
- RdEnc = case ChosenEnc of
- "identity" -> Rd1;
- _ -> wrq:set_resp_header("Content-Encoding",ChosenEnc, Rd1)
- end,
- {ok, RdEnc1} = webmachine_request:set_metadata('content-encoding',ChosenEnc,RdEnc),
- {ChosenEnc, Rs1, RdEnc1}
- end.
-
-choose_charset(AccCharHdr, Rs, Rd) ->
- {CharsetsProvided, Rs1, Rd1} = resource_call(charsets_provided, Rs, Rd),
- case CharsetsProvided of
- no_charset ->
- {no_charset, Rs1, Rd1};
- CL ->
- CSets = [CSet || {CSet,_Fun} <- CL],
- case webmachine_util:choose_charset(CSets, AccCharHdr) of
- none ->
- {none, Rs1, Rd1};
- Charset ->
- {ok, RdCSet} = webmachine_request:set_metadata('chosen-charset', Charset, Rd1),
- {Charset, Rs1, RdCSet}
- end
- end.
-
-choose_upgrade(UpgradeHdr, Rs, Rd) ->
- {UpgradesProvided, Rs1, Rd1} = resource_call(upgrades_provided, Rs, Rd),
- Provided1 = [ {string:to_lower(Prot), Prot, PFun} || {Prot, PFun} <- UpgradesProvided],
- Requested = [ string:to_lower(string:strip(Up)) || Up <- string:tokens(UpgradeHdr, ",") ],
- {choose_upgrade1(Requested, Provided1), Rs1, Rd1}.
-
- choose_upgrade1([], _) ->
- none;
- choose_upgrade1([Req|Requested], Provided) ->
- case lists:keysearch(Req, 1, Provided) of
- false ->
- choose_upgrade1(Requested, Provided);
- {value, {_, Protocol, UpgradeFun}} ->
- {Protocol, UpgradeFun}
- end.
-
-
-variances(Rs, Rd) ->
- {ContentTypesProvided, Rs1, Rd1} = resource_call(content_types_provided, Rs, Rd),
- Accept = case length(ContentTypesProvided) of
- 1 -> [];
- 0 -> [];
- _ -> ["Accept"]
- end,
- {EncodingsProvided, Rs2, Rd2} = resource_call(encodings_provided, Rs1, Rd1),
- AcceptEncoding = case length(EncodingsProvided) of
- 1 -> [];
- 0 -> [];
- _ -> ["Accept-Encoding"]
- end,
- {CharsetsProvided, Rs3, Rd3} = resource_call(charsets_provided, Rs2, Rd2),
- AcceptCharset = case CharsetsProvided of
- no_charset ->
- [];
- CP ->
- case length(CP) of
- 1 -> [];
- 0 -> [];
- _ -> ["Accept-Charset"]
- end
- end,
- {Variances, Rs4, Rd4} = resource_call(variances, Rs3, Rd3),
- {Accept ++ AcceptEncoding ++ AcceptCharset ++ Variances, Rs4, Rd4}.
-
-
View
92 deps/webmachine/src/webmachine_deps.erl
@@ -1,92 +0,0 @@
-%% @author Justin Sheehy <justin@basho.com>
-%% @author Andy Gross <andy@basho.com>
-%% @copyright 2007-2008 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.
-
-%% @doc Ensure that the relatively-installed dependencies are on the code
-%% loading path, and locate resources relative
-%% to this application's path.
-
--module(webmachine_deps).
--author('Justin Sheehy <justin@basho.com>').
--author('Andy Gross <andy@basho.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() ->
- ordsets:from_list([filename:basename(filename:dirname(X)) || X <- 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 = [ X || X <- filelib:wildcard(local_path(["deps", "*", "ebin"], Module)),
- filename:basename(filename:dirname(X)) /= %% don't include self
- filename:basename(filename:dirname(
- filename:dirname(
- filename:dirname(X)))) ],
- 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_bas