add the ``entrypoint'' option

This commit is contained in:
Omar Polo 2021-02-06 18:28:43 +00:00
parent afc025ff60
commit e3ddf39095
9 changed files with 38 additions and 4 deletions

View File

@ -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>

8
gmid.1
View File

@ -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

1
gmid.c
View File

@ -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);

1
gmid.h
View File

@ -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

1
lex.l
View File

@ -72,6 +72,7 @@ auto return TAUTO;
strip return TSTRIP;
block return TBLOCK;
return return TRETURN;
entrypoint return TENTRYPOINT;
[{}] return *yytext;

View File

@ -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
;

View File

@ -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

View File

@ -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

View File

@ -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