aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog1
-rw-r--r--gmid.18
-rw-r--r--gmid.c1
-rw-r--r--gmid.h1
-rw-r--r--lex.l1
-rw-r--r--parse.y7
-rw-r--r--regress/Makefile2
-rwxr-xr-xregress/runtime10
-rw-r--r--server.c11
9 files changed, 38 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index a9e08cc..8c06711 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,7 @@
2021-02-06 Omar Polo <op@omarpolo.com>
* parse.y (locopt): added ``block return'' and ``strip'' options
+ (servopt): add the ``entrypoint'' option
2021-02-05 Omar Polo <op@omarpolo.com>
diff --git a/gmid.1 b/gmid.1
index 58fa9cb..012d599 100644
--- a/gmid.1
+++ b/gmid.1
@@ -230,7 +230,8 @@ A
.Ic location
section may include most of the server configuration rules
except
-.Ic cert , Ic key , Ic root , Ic location No and Ic cgi .
+.Ic cert , Ic key , Ic root , Ic location No ,
+.Ic entrypoint No and Ic cgi .
.It Ic block Op Ic return Ar code Op Ar meta
Send a reply and close the connection;
.Ar code
@@ -269,6 +270,11 @@ It's only considered for the
.Ar meta
parameter in the scope of a matching
.Ic block return .
+.It Ic entrypoint Pa path
+Make the CGI script at
+.Pa path
+.Pq relative to the Ic root No directory
+handle all the requests for the current virtual host
.El
.Sh CGI
When a request for an executable file matches the
diff --git a/gmid.c b/gmid.c
index 1a1bd59..8a9a52b 100644
--- a/gmid.c
+++ b/gmid.c
@@ -433,6 +433,7 @@ free_config(void)
free((char*)h->key);
free((char*)h->dir);
free((char*)h->cgi);
+ free((char*)h->entrypoint);
for (l = h->locations; l->match != NULL; ++l) {
free((char*)l->match);
diff --git a/gmid.h b/gmid.h
index e4dd437..1701c98 100644
--- a/gmid.h
+++ b/gmid.h
@@ -80,6 +80,7 @@ struct vhost {
const char *key;
const char *dir;
const char *cgi;
+ const char *entrypoint;
int dirfd;
/* the first location rule is always '*' and holds the default
diff --git a/lex.l b/lex.l
index 04d902a..8f233fb 100644
--- a/lex.l
+++ b/lex.l
@@ -72,6 +72,7 @@ auto return TAUTO;
strip return TSTRIP;
block return TBLOCK;
return return TRETURN;
+entrypoint return TENTRYPOINT;
[{}] return *yytext;
diff --git a/parse.y b/parse.y
index 77a3558..c89ed5d 100644
--- a/parse.y
+++ b/parse.y
@@ -125,6 +125,13 @@ servopt : TCERT TSTRING { host->cert = ensure_absolute_path($2); }
memmove($2, $2+1, strlen($2));
host->cgi = $2;
}
+ | TENTRYPOINT TSTRING {
+ if (host->entrypoint != NULL)
+ yyerror("`entrypoint' specified more than once");
+ while (*$2 == '/')
+ memmove($2, $2+1, strlen($2));
+ host->entrypoint = $2;
+ }
| locopt
;
diff --git a/regress/Makefile b/regress/Makefile
index b94e5c9..8a29ce5 100644
--- a/regress/Makefile
+++ b/regress/Makefile
@@ -38,7 +38,7 @@ testdata: fill-file
./sha testdata/bigfile testdata/bigfile.sha
printf "# hello world\n" > testdata/index.gmi
./sha testdata/index.gmi testdata/index.gmi.sha
- cp hello slow err invalid serve-bigfile testdata/
+ cp hello slow err invalid serve-bigfile env testdata/
mkdir testdata/dir
cp hello testdata/dir
cp testdata/index.gmi testdata/dir/foo.gmi
diff --git a/regress/runtime b/regress/runtime
index 4d53f1c..9492b1d 100755
--- a/regress/runtime
+++ b/regress/runtime
@@ -255,4 +255,14 @@ echo OK GET /bigfile with strip and block
check "should be running"
+# test the entrypoint
+
+config '' 'entrypoint "/env"'
+checkconf
+restart
+
+eq "$(head /foo/bar)" "20 text/plain; lang=en" "Unknown head for /foo/bar"
+eq "$(get /foo/bar|grep PATH_INFO)" "PATH_INFO=/foo/bar" "Unexpected PATH_INFO"
+echo OK GET /foo/bar with entrypoint
+
quit
diff --git a/server.c b/server.c
index ec44649..33eda69 100644
--- a/server.c
+++ b/server.c
@@ -481,8 +481,15 @@ handle_open_conn(struct pollfd *fds, struct client *c)
return;
}
- if (!apply_block_return(fds, c))
- open_file(fds, c);
+ if (apply_block_return(fds, c))
+ return;
+
+ if (c->host->entrypoint != NULL) {
+ start_cgi(c->host->entrypoint, c->iri.path, fds, c);
+ return;
+ }
+
+ open_file(fds, c);
}
static void