You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ro...@apache.org on 2015/06/29 23:46:20 UTC
[14/50] couch commit: updated refs/heads/COUCHDB-2734-header-date to
f3e022c
more improvements to #114 test coverage
Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch/commit/4b77ea0b
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch/tree/4b77ea0b
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch/diff/4b77ea0b
Branch: refs/heads/COUCHDB-2734-header-date
Commit: 4b77ea0b7c4d797798d8ae9f189444191bf1bf61
Parents: 8bb260f
Author: Bob Ippolito <bo...@redivi.com>
Authored: Thu Aug 1 16:11:38 2013 -0700
Committer: Bob Ippolito <bo...@redivi.com>
Committed: Thu Aug 1 16:11:38 2013 -0700
----------------------------------------------------------------------
src/mochiweb.erl | 55 ++++++++++++++++----------------------------
test/mochiweb_tests.erl | 22 +++++++++++++++++-
2 files changed, 41 insertions(+), 36 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/4b77ea0b/src/mochiweb.erl
----------------------------------------------------------------------
diff --git a/src/mochiweb.erl b/src/mochiweb.erl
index 76e5953..927322d 100644
--- a/src/mochiweb.erl
+++ b/src/mochiweb.erl
@@ -32,46 +32,31 @@ all_loaded(Base) ->
end,
lists:foldl(F, [], code:all_loaded()).
+%% See the erlang:decode_packet/3 docs for the full type
+-spec uri(HttpUri :: term()) -> string().
+uri({abs_path, Uri}) ->
+ Uri;
+%% TODO:
+%% This makes it hard to implement certain kinds of proxies with mochiweb,
+%% perhaps a field could be added to the mochiweb_request record to preserve
+%% this information in raw_path.
+uri({absoluteURI, _Protocol, _Host, _Port, Uri}) ->
+ Uri;
+%% From http://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html#sec5.1.2
+uri('*') ->
+ "*";
+%% Erlang decode_packet will return this for requests like `CONNECT host:port`
+uri({scheme, Hostname, Port}) ->
+ Hostname ++ ":" ++ Port;
+uri(HttpString) when is_list(HttpString) ->
+ HttpString.
%% @spec new_request({Socket, Request, Headers}) -> MochiWebRequest
%% @doc Return a mochiweb_request data structure.
-new_request({Socket, {Method, {abs_path, Uri}, Version}, Headers}) ->
- mochiweb_request:new(Socket,
- Method,
- Uri,
- Version,
- mochiweb_headers:make(Headers));
-% this case probably doesn't "exist".
-new_request({Socket, {Method, {absoluteURI, _Protocol, _Host, _Port, Uri},
- Version}, Headers}) ->
- mochiweb_request:new(Socket,
- Method,
- Uri,
- Version,
- mochiweb_headers:make(Headers));
-%% Request-URI is "*"
-%% From http://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html#sec5.1.2
-new_request({Socket, {Method, '*'=Uri, Version}, Headers}) ->
- mochiweb_request:new(Socket,
- Method,
- Uri,
- Version,
- mochiweb_headers:make(Headers));
-%% Request URI is a scheme
-%% Erlang decode_package will return this for requests like `CONNECT example:port`
-new_request({Socket, {Method, {scheme, Hostname, Port}, Version}, Headers}) ->
- Uri = Hostname ++ ":" ++ Port,
- mochiweb_request:new(Socket,
- Method,
- Uri,
- Version,
- mochiweb_headers:make(Headers));
-%% Request is an HTTP string
-%% Erlang decode_package will return this for requests like `GET example`
-new_request({Socket, {Method, HttpString, Version}, Headers}) when is_list(HttpString) ->
+new_request({Socket, {Method, HttpUri, Version}, Headers}) ->
mochiweb_request:new(Socket,
Method,
- HttpString,
+ uri(HttpUri),
Version,
mochiweb_headers:make(Headers)).
http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/4b77ea0b/test/mochiweb_tests.erl
----------------------------------------------------------------------
diff --git a/test/mochiweb_tests.erl b/test/mochiweb_tests.erl
index 57587d0..a272eed 100644
--- a/test/mochiweb_tests.erl
+++ b/test/mochiweb_tests.erl
@@ -83,14 +83,34 @@ hundred_128_https_POST_test_() -> % note the underscore
{timeout, ?LARGE_TIMEOUT,
fun() -> ?assertEqual(ok, do_POST(ssl, 128, 100)) end}.
-single_GET_relative_test_() ->
+single_GET_scheme_test_() ->
[{"ssl", ?_assertEqual(ok, do_GET("derp", ssl, 1))},
{"plain", ?_assertEqual(ok, do_GET("derp", plain, 1))}].
+single_GET_absoluteURI_test_() ->
+ Uri = "https://example.com:123/x/",
+ ServerFun = fun (Req) ->
+ Req:ok({"text/plain", Req:get(path)})
+ end,
+ %% Note that all the scheme/host/port information is discarded from path
+ ClientFun = new_client_fun('GET', [#treq{path = Uri, xreply = <<"/x/">>}]),
+ [{atom_to_list(Transport),
+ ?_assertEqual(ok, with_server(Transport, ServerFun, ClientFun))}
+ || Transport <- [ssl, plain]].
+
single_CONNECT_test_() ->
[{"ssl", ?_assertEqual(ok, do_CONNECT(ssl, 1))},
{"plain", ?_assertEqual(ok, do_CONNECT(plain, 1))}].
+single_GET_any_test_() ->
+ ServerFun = fun (Req) ->
+ Req:ok({"text/plain", Req:get(path)})
+ end,
+ ClientFun = new_client_fun('GET', [#treq{path = "*", xreply = <<"*">>}]),
+ [{atom_to_list(Transport),
+ ?_assertEqual(ok, with_server(Transport, ServerFun, ClientFun))}
+ || Transport <- [ssl, plain]].
+
do_CONNECT(Transport, Times) ->
PathPrefix = "example.com:",
ReplyPrefix = "You requested: ",