Interface to get scheme used in request #4

Open
wants to merge 2 commits into
from
View
5 src/inets_bridge_modules/inets_request_bridge.erl
@@ -8,7 +8,7 @@
-include_lib ("simple_bridge.hrl").
-export ([
init/1,
- request_method/1, path/1, uri/1,
+ request_method/1, path/1, uri/1, scheme/1,
peer_ip/1, peer_port/1,
headers/1, cookies/1,
query_params/1, post_params/1, request_body/1,
@@ -29,6 +29,9 @@ path(Req) ->
uri(Req) ->
Req#mod.request_uri.
+scheme(_Req) ->
+ undefined.
+
peer_ip(Req) ->
Socket = Req#mod.socket,
{ok, {IP, _Port}} = inet:peername(Socket),
View
5 src/misultin_bridge_modules/misultin_request_bridge.erl
@@ -3,7 +3,7 @@
-include_lib ("simple_bridge.hrl").
-export ([
init/1,
- request_method/1, path/1, uri/1,
+ request_method/1, path/1, uri/1, scheme/1,
peer_ip/1, peer_port/1,
headers/1, cookies/1,
query_params/1, post_params/1, request_body/1
@@ -27,6 +27,9 @@ path(Req) ->
uri(Req) ->
Req:get(uri).
+scheme(_Req) ->
+ undefined.
+
peer_ip(Req) ->
Req:get(peer_addr).
View
5 src/mochiweb_bridge_modules/mochiweb_request_bridge.erl
@@ -7,7 +7,7 @@
-include_lib ("simple_bridge.hrl").
-export ([
init/1,
- request_method/1, path/1, uri/1,
+ request_method/1, path/1, uri/1, scheme/1,
peer_ip/1, peer_port/1,
headers/1, cookies/1,
query_params/1, post_params/1, request_body/1,
@@ -28,6 +28,9 @@ path({Req, _DocRoot}) ->
uri({Req, _DocRoot}) ->
Req:get(raw_path).
+scheme(_Req) ->
+ undefined.
+
peer_ip({Req, _DocRoot}) ->
Socket = Req:get(socket),
{ok, {IP, _Port}} = inet:peername(Socket),
View
1 src/simple_bridge_request.erl
@@ -37,6 +37,7 @@ behaviour_info(callbacks) -> [
{request_method, 1}, % GET, POST, etc.
{uri, 1}, % The uri (path and querystring)
{path, 1}, % Just the path. (http://server.com/<PATH>?querystring)
+ {scheme, 1}, % http, https, spdy, gopher, ..., undefined
{headers, 1}, % Return a proplist of headers, key and value are strings.
{cookies, 1}, % Return a proplist of cookies, key and value are strings.
View
3 src/simple_bridge_request_wrapper.erl
@@ -15,6 +15,9 @@ set_error(Error1) ->
request_method() -> Mod:request_method(Req).
path() -> Mod:path(Req).
uri() -> Mod:uri(Req).
+scheme() -> Mod:scheme(Req).
+
+port() -> Mod:port(Req).
peer_ip() -> Mod:peer_ip(Req).
peer_port() -> Mod:peer_port(Req).
View
4 src/webmachine_bridge_modules/webmachine_request_bridge.erl
@@ -11,6 +11,7 @@
request_method/1,
path/1,
uri/1,
+ scheme/1,
peer_ip/1,
peer_port/1,
headers/1,
@@ -36,6 +37,9 @@ uri(Req) ->
{_, QueryString, _} = mochiweb_util:urlsplit_path(RawPath),
QueryString.
+scheme(_Req) ->
+ undefined.
+
peer_ip(_Req) ->
throw(unsupported).
View
19 src/yaws_bridge_modules/yaws_request_bridge.erl
@@ -7,7 +7,8 @@
-include_lib ("simple_bridge.hrl").
-export ([
init/1,
- request_method/1, path/1, uri/1,
+ request_method/1, path/1, uri/1, scheme/1,
+ port/1,
peer_ip/1, peer_port/1,
headers/1, cookie/2, cookies/1,
query_params/1, post_params/1, request_body/1,
@@ -28,6 +29,22 @@ uri(Arg) ->
{abs_path, Path} = Req#http_request.path,
Path.
+scheme(Arg) ->
+ case {Arg#arg.req, Arg#arg.clisock} of
+ {#http_request{}, {sslsocket, _, _}} -> https;
+ {#http_request{}, _} -> http;
+ _ -> undefined
+ end.
+
+port(Arg) ->
+ case Arg#arg.clisock of
+ Socket when is_port(Socket) ->
+ {ok, Port} = inet:port(Socket),
+ Port;
+ _ ->
+ undefined
+ end.
+
peer_ip(Arg) ->
Socket = socket(Arg),
{ok, {IP, _Port}} = inet:peername(Socket),