diff options
-rw-r--r-- | ChangeLog | 1 | ||||
-rw-r--r-- | gmid.1 | 8 | ||||
-rw-r--r-- | gmid.c | 1 | ||||
-rw-r--r-- | gmid.h | 1 | ||||
-rw-r--r-- | lex.l | 1 | ||||
-rw-r--r-- | parse.y | 7 | ||||
-rw-r--r-- | regress/Makefile | 2 | ||||
-rwxr-xr-x | regress/runtime | 10 | ||||
-rw-r--r-- | server.c | 11 |
9 files changed, 38 insertions, 4 deletions
@@ -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> @@ -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 @@ -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); @@ -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 @@ -72,6 +72,7 @@ auto return TAUTO; strip return TSTRIP; block return TBLOCK; return return TRETURN; +entrypoint return TENTRYPOINT; [{}] return *yytext; @@ -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 @@ -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 |