5 # usage: config <global config> <stuff for localhost>
6 # generates a configuration file reg.conf
23 ./../gmid -n -c reg.conf
27 # return the body of the request on stdout
29 ./../gg -b "gemini://localhost:10965/$1"
33 # return the meta response line on stdout
35 ./../gg -h "gemini://localhost:10965/$1"
39 # return both header and body
41 ./../gg "gemini://localhost:10965/$1"
45 # filter out logs for GET requests
46 (./../gmid -c reg.conf 2>&1 | grep -v GET) >&2 &
48 # give gmid time to bind the port, otherwise we end up
49 # executing gg when gmid isn't ready yet.
53 # usage: check [exit-message]
54 # check if gmid is still running
56 if ! ps $pid >/dev/null; then
57 echo ${1:-"gmid crashed?"}
68 # usage: eq a b errmsg
69 # if a and b aren't equal strings, exit with errmsg
71 if ! [ "$1" = "$2" ]; then
72 echo "$3: \"$1\" not equal \"$2\""
78 rm -f bigfile bigfile.sha
84 trap 'onexit' INT TERM EXIT
93 eq "$(head /)" "20 text/gemini" "Unexpected head for /"
94 eq "$(get /)" "# hello world$ln" "Unexpected body for /"
97 eq "$(head /foo)" "51 not found" "Unexpected head /foo"
98 eq "$(get /foo)" "" "Unexpected body /foo"
101 # should redirect if asked for a directory but without the trailing /
102 eq "$(head /dir)" "30 /dir/" "Unexpected redirect for /dir"
103 eq "$(get /dir)" "" "Unexpected body for redirect"
106 # 51 for a directory without index.gmi
107 eq "$(head /dir/)" "51 not found" "Unexpected head for /"
108 eq "$(get /dir/)" "" "Unexpected body for error"
111 eq "$(head /dir/foo.gmi)" "20 text/gemini" "Unexpected head for /dir/foo.gmi"
112 eq "$(get /dir/foo.gmi)" "# hello world$ln" "Unexpected body for /dir/foo.gmi"
113 echo OK GET /dir/foo.gmi
116 eq "$(head /bigfile)" "20 application/octet-stream" "Unexpected head for /bigfile"
117 get /bigfile > bigfile
118 ./sha bigfile bigfile.sha
119 eq "$(cat bigfile.sha)" "$(cat testdata/bigfile.sha)" "Unexpected sha for /bigfile"
122 # shouldn't be executing cgi scripts
123 eq "$(head /hello)" "20 application/octet-stream" "Unexpected head for /hello"
126 check "should be running"
129 # try with custom mime
130 config 'mime "text/x-funny-text" "gmi"' 'default type "application/x-trash"'
134 eq "$(head /)" "20 text/x-funny-text" "Unexpected head for /"
135 echo OK GET / with custom mime
137 eq "$(head /hello)" "20 application/x-trash" "Unexpected head for /hello"
138 echo OK GET /hello with custom mime
140 check "should be running"
143 # try with custom lang
144 config '' 'lang "it"'
148 eq "$(head /)" "20 text/gemini; lang=it" "Unexpected head for /"
149 echo OK GET / with custom lang
151 check "should be running"
154 # finally try with CGI scripts
159 eq "$(head /hello)" "20 text/gemini" "Unexpected head for /hello"
160 eq "$(get /hello)" "# hello world$ln" "Unexpected body for /hello"
161 echo OK GET /hello with cgi
163 eq "$(head /slow)" "20 text/gemini" "Unexpected head for /slow"
164 eq "$(get /slow)" "# hello world$ln" "Unexpected body for /slow"
165 echo OK GET /slow with cgi
167 eq "$(head /err)" "" "Unexpected head for /err"
168 eq "$(get /err)" "" "Unexpected body for /err"
169 echo OK GET /err with cgi
171 eq "$(raw /invalid | wc -c | xargs)" 2048 "Unexpected body for /invalid"
172 echo OK GET /invalid with cgi
175 eq "$(head /serve-bigfile)" "20 application/octet-stream" "Unexpected head for /serve-bigfile"
176 get /bigfile > bigfile
177 ./sha bigfile bigfile.sha
178 eq "$(cat bigfile.sha)" "$(cat testdata/bigfile.sha)" "Unexpected sha for /serve-bigfile"
179 echo OK GET /serve-bigfile with cgi
181 check "should be running"
184 config '' 'index "foo.gmi"'
188 eq "$(head /dir/)" "20 text/gemini" "Unexpected head for /"
189 eq "$(get /dir/)" "# hello world$ln" "Unexpected body for error"
190 echo OK GET /dir/ with custom index
192 check "should be running"