5 Mirage_crypto_rng_lwt.initialize
(module Mirage_crypto_rng.Fortuna
);
6 Unix.chdir
"../../../test/"
8 let tc_script_url_dir () =
9 "/seppo.cgi" |> Cgi.Request.script_url_dir
|> check
string __LOC__
"/";
10 "/apchk.cgi" |> Cgi.Request.script_url_dir
|> check
string __LOC__
"/";
11 "/cgi-bin/subdi/seppo.cgi" |> Cgi.Request.script_url_dir
|> check
string __LOC__
"/subdi/";
12 "/suhu/.cgi" |> Cgi.Request.script_url_dir
|> check
string __LOC__
"/suhu/";
13 "/cgi-bin/suha/.cgi" |> Cgi.Request.script_url_dir
|> check
string __LOC__
"/suha/";
14 "/cgi-bun/suha/.cgi" |> Cgi.Request.script_url_dir
|> check
string __LOC__
"/cgi-bun/suha/";
18 let env l s
= l
|> List.assoc_opt s
in
19 let r = Cgi.Request.(from_env ~getenv_opt
:(env [
20 (* hCONTENT_LENGTH, "CONTENT_LENGTH" ; *)
21 (* hCONTENT_TYPE, "CONTENT_TYPE" ; *)
22 (* hHTTP_COOKIE, "HTTP_COOKIE" ; *)
23 (* hHTTP_HOST, "example.com" ; *)
24 (* hHTTP_USER_AGENT, "agent" ; *)
25 (* hHTTP_X_FORWARDED_FOR, "217.88.75.197" ; *)
26 (* hHTTP_X_FORWARDED_PROTO, "https" ; *)
27 (* hHTTPS, "HTTPS" ; *)
28 (* hPATH_INFO, "path_info" ; *)
29 (* hQUERY_STRING, "" ; *)
30 hREMOTE_ADDR
, "192.0.2.7" ; (* https://www.rfc-editor.org/rfc/rfc5735#section-3 *)
31 hREQUEST_METHOD
, "GET" ;
32 (* hREQUEST_URI, "/i.cgi" ; *)
33 hSCRIPT_NAME
, "/i.cgi" ;
34 hSERVER_NAME
, "example.com" ;
36 ]) () |> consolidate
|> proxy
) |> Result.get_ok
in
37 r.host
|> check
string __LOC__
"example.com";
38 r.path_info
|> check
string __LOC__
"";
39 r.remote_addr
|> check
string __LOC__
"192.0.2.7";
40 r.scheme
|> check
string __LOC__
"http";
41 r.script_name
|> check
string __LOC__
"/i.cgi";
42 r.server_port
|> check
string __LOC__
"80";
45 let tc_from_env_proxy () =
46 let env l s
= l
|> List.assoc_opt s
in
47 let r = Cgi.Request.(from_env ~getenv_opt
:(env [
48 (* hCONTENT_LENGTH, "CONTENT_LENGTH" ; *)
49 (* hCONTENT_TYPE, "CONTENT_TYPE" ; *)
50 (* hHTTP_COOKIE, "HTTP_COOKIE" ; *)
51 (* hHTTP_HOST, "example.com" ; *)
52 (* hHTTP_USER_AGENT, "agent" ; *)
53 hHTTP_X_FORWARDED_FOR
, "192.0.2.7" ; (* https://www.rfc-editor.org/rfc/rfc5735#section-3 *)
54 hHTTP_X_FORWARDED_PROTO
, "https" ;
55 (* hHTTPS, "HTTPS" ; *)
56 (* hPATH_INFO, "path_info" ; *)
57 (* hQUERY_STRING, "" ; *)
58 hREMOTE_ADDR
, "127.0.0.1" ;
59 hREQUEST_METHOD
, "GET" ;
60 (* hREQUEST_URI, "/i.cgi" ; *)
61 hSCRIPT_NAME
, "/i.cgi" ;
62 hSERVER_NAME
, "example.com" ;
64 ]) () |> consolidate
|> proxy
) |> Result.get_ok
in
65 r.host
|> check
string __LOC__
"example.com";
66 r.path_info
|> check
string __LOC__
"";
67 r.remote_addr
|> check
string __LOC__
"192.0.2.7";
68 r.scheme
|> check
string __LOC__
"https";
69 r.script_name
|> check
string __LOC__
"/i.cgi";
70 r.server_port
|> check
string __LOC__
"443";
74 let env l s
= l
|> List.assoc_opt s
in
75 let r = Cgi.Request.(from_env ~getenv_opt
:(env [
76 hHTTP_X_FORWARDED_FOR
, "192.0.2.7" ; (* https://www.rfc-editor.org/rfc/rfc5735#section-3 *)
77 hHTTP_X_FORWARDED_PROTO
, "https" ;
78 hREMOTE_ADDR
, "127.0.0.1" ;
79 hREQUEST_METHOD
, "GET" ;
80 hSCRIPT_NAME
, "/i.cgi" ;
81 hSERVER_NAME
, "example.com" ;
83 ]) () |> proxy
) |> Result.get_ok
in
85 |> Uri.to_string
|> check
string __LOC__
"https://example.com";
87 |> Uri.to_string
|> check
string __LOC__
"https://example.com/i.cgi"
93 "set_up" , `Quick
, set_up;
94 "tc_script_url_dir ", `Quick
, tc_script_url_dir ;
95 "tc_from_env " , `Quick
, tc_from_env ;
96 "tc_from_env_proxy ", `Quick
, tc_from_env_proxy ;
97 "tc_abs " , `Quick
, tc_abs ;