Skip to content
Browse files

added redirect_self to yaws_api

git-svn-id: https://erlyaws.svn.sourceforge.net/svnroot/erlyaws/trunk/yaws@1276 9fbdc01b-0d2c-0410-bfb7-fb27d70d8b52
  • Loading branch information...
1 parent ee9376f commit 883fa5a69dafd88de4b13108ca4b14044d085832 @klacke committed Sep 12, 2008
Showing with 64 additions and 1 deletion.
  1. +8 −0 include/yaws_api.hrl
  2. +20 −0 man/yaws_api.5
  3. +36 −1 src/yaws_api.erl
View
8 include/yaws_api.hrl
@@ -98,6 +98,14 @@
version}).
+-record(redir_self, {
+ host, %% string() - our own host
+ scheme, %% http | https
+ scheme_str, %% "https://" | "http://"
+ port, %% integer() - our own port
+ port_str %% "" | ":<int>" - the optional port part
+ %% to append to the url
+ }).
View
20 man/yaws_api.5
@@ -158,6 +158,26 @@ out(Arg) ->
.TP
+\fBredirect_self(Arg)\fR
+If we want to issue a redirect to ourselves, this function
+is useful. It returns a record \fI#redir_self{}\fR defined in
+\fIyaws_api.hrl\fR. The record contains fields to construct
+a URL to ourselves.
+\fI
+.nf
+
+-record(redir_self, {
+ host, %% string() - our own host
+ scheme, %% http | https
+ scheme_str, %% "https://" | "http://"
+ port, %% integer() - our own port
+ port_str %% "" | ":<int>" - the optional port part
+ %% to append to the url
+ }).
+.nf
+
+
+.TP
\fBget_line(String)\fR
This function is convenient when getting \\r\\n terminated lines
from a stream of data. It returns:
View
37 src/yaws_api.erl
@@ -57,7 +57,7 @@
postvar/2, queryvar/2, getvar/2]).
-export([binding/1,binding_exists/1,
- dir_listing/1, dir_listing/2]).
+ dir_listing/1, dir_listing/2, redirect_self/1]).
-import(lists, [map/2, flatten/1, reverse/1]).
@@ -1766,3 +1766,38 @@ dir_listing(Arg, RelDir) ->
%% make sure it's a valid path here
ok
end.
+
+%% Returns #redir_self{} record
+redirect_self(A) ->
+ {Port, PortStr} =
+ case {SC#sconf.rmethod, SC#sconf.ssl, SC#sconf.port} of
+ {"https", _, 443} -> {443, ""};
+ {"http", _, 80} -> {80, ""};
+ {_, undefined, 80} -> {80, ""};
+ {_, undefined, Port} ->
+ {port, [$:|integer_to_list(Port)]};
+ {_, _SSL, 443} ->
+ {443, ""};
+ {_, _SSL, Port} ->
+ {Port, [$:|integer_to_list(Port)]}
+ end,
+ H = A#arg.headers,
+ Host = yaws:redirect_host(get(sc), H#headers.host),
+ {Scheme, SchemeStr} =
+ case {SC#sconf.ssl,SC#sconf.rmethod} of
+ {_, Method} when list(Method) ->
+ {list_to_atom(Method), Method++"://"};
+ {undefined,_} ->
+ {http, "http://"};
+ {_SSl,_} ->
+ {https, "https://"}
+ end,
+ #redir_self{host = Host,
+ scheme = Scheme,
+ scheme_str = SchemeStr,
+ port = Port,
+ port_str = PortStr}.
+
+
+
+

0 comments on commit 883fa5a

Please sign in to comment.
Something went wrong with that request. Please try again.