Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interface to get scheme used in request #4

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/inets_bridge_modules/inets_request_bridge.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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),
Expand Down
5 changes: 4 additions & 1 deletion src/misultin_bridge_modules/misultin_request_bridge.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -27,6 +27,9 @@ path(Req) ->
uri(Req) ->
Req:get(uri).

scheme(_Req) ->
undefined.

peer_ip(Req) ->
Req:get(peer_addr).

Expand Down
5 changes: 4 additions & 1 deletion src/mochiweb_bridge_modules/mochiweb_request_bridge.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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),
Expand Down
1 change: 1 addition & 0 deletions src/simple_bridge_request.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 3 additions & 0 deletions src/simple_bridge_request_wrapper.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
4 changes: 4 additions & 0 deletions src/webmachine_bridge_modules/webmachine_request_bridge.erl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
request_method/1,
path/1,
uri/1,
scheme/1,
peer_ip/1,
peer_port/1,
headers/1,
Expand All @@ -36,6 +37,9 @@ uri(Req) ->
{_, QueryString, _} = mochiweb_util:urlsplit_path(RawPath),
QueryString.

scheme(_Req) ->
undefined.

peer_ip(_Req) ->
throw(unsupported).

Expand Down
19 changes: 18 additions & 1 deletion src/yaws_bridge_modules/yaws_request_bridge.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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),
Expand Down