[m-rev.] for review: make mdprof_cgi respect CGI environment variables

Julien Fischer juliensf at csse.unimelb.edu.au
Mon Apr 2 12:16:13 AEST 2007


On Mon, 2 Apr 2007, Peter Wang wrote:

> Branches: main
>
> deep_profiler/conf.m:
> deep_profiler/html_format.m:
> deep_profiler/interface.m:
> deep_profiler/mdprof_cgi.m:
> deep_profiler/mdprof_feedback.m:
> deep_profiler/mdprof_test.m:
> deep_profiler/profile.m:
> deep_profiler/startup.m:
> 	Respect the CGI environment variables SERVER_NAME, SERVER_PORT and
> 	SCRIPT_NAME.  This allows the mdprof_cgi to be used with any web
> 	server, on an arbitrary port, at any URL.
>
> Index: conf.m
> ===================================================================
> RCS file: /home/mercury1/repository/mercury/deep_profiler/conf.m,v
> retrieving revision 1.9
> diff -u -r1.9 conf.m
> --- conf.m	12 Oct 2006 06:30:21 -0000	1.9
> +++ conf.m	2 Apr 2007 00:50:20 -0000
> @@ -25,9 +25,15 @@
>     %
> :- func make_pipe_cmd(string) = string.
>
> -    % The name of the server on which mdprof is being run.
> +    % The name of the server and, optionally, the port on which mdprof is
> +    % being run.
>     %
> -:- pred server_name(string::out, io::di, io::uo) is det.
> +:- pred server_name_port(string::out, io::di, io::uo) is det.
> +
> +    % The virtual path under which this program is being executed, used for
> +    % self-referencing URLs.
> +    %
> +:- pred script_name(string::out, io::di, io::uo) is det.
>
> :- func getpid = int.
>
> @@ -37,6 +43,7 @@
> :- implementation.
>
> :- import_module list.
> +:- import_module maybe.
> :- import_module require.
> :- import_module string.
>
> @@ -50,7 +57,31 @@
>         string.format("%s %s", [s(CmdName), s(PipeName)], Cmd)
>     ).
>
> +server_name_port(Machine, !IO) :-
> +    server_name(ServerName, !IO),
> +    maybe_server_port(MaybeServerPort, !IO),
> +    (
> +        MaybeServerPort = yes(Port),
> +        Machine = ServerName ++ ":" ++ Port
> +    ;
> +        MaybeServerPort = no,
> +        Machine = ServerName
> +    ).
> +
> +:- pred server_name(string::out, io::di, io::uo) is det.
> +
> server_name(ServerName, !IO) :-
> +    io.get_environment_var("SERVER_NAME", MaybeServerName, !IO),
> +    (
> +        MaybeServerName = yes(ServerName)
> +    ;
> +        MaybeServerName = no,
> +        server_name_2(ServerName, !IO)
> +    ).
> +
> +:- pred server_name_2(string::out, io::di, io::uo) is det.
> +
> +server_name_2(ServerName, !IO) :-
>     io.make_temp(TmpFile, !IO),
>     hostname_cmd(HostnameCmd),
>     ServerRedirectCmd =
> @@ -78,6 +109,21 @@
>         io.remove_file(TmpFile, _, !IO)
>     ;
>         error("cannot execute cmd to find the server's name")
> +    ).
> +
> +:- pred maybe_server_port(maybe(string)::out, io::di, io::uo) is det.
> +
> +maybe_server_port(MaybeServerPort, !IO) :-
> +    io.get_environment_var("SERVER_PORT", MaybeServerPort, !IO).
> +
> +script_name(ScriptName, !IO) :-
> +    io.get_environment_var("SCRIPT_NAME", MaybeScriptName, !IO),
> +    (
> +        MaybeScriptName = yes(ScriptName)
> +    ;
> +        MaybeScriptName = no,
> +        % XXX not sure how to handle this, but should not occur in practice
> +        ScriptName = "/"

Then perhaps calling error/1 would be a better thing to do.

The rest of the change looks fine.

Julien.

--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to:       mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions:          mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the reviews mailing list