aboutsummaryrefslogtreecommitdiff
path: root/fcgi.c
diff options
context:
space:
mode:
authorOmar Polo <op@omarpolo.com>2023-08-08 16:06:17 +0000
committerOmar Polo <op@omarpolo.com>2023-08-08 16:06:17 +0000
commitb27dc2b0a33b5087f2c505b82dcf2cc73208dcaa (patch)
tree9069f980b7b229953dca5f3678a25f3afe4627c1 /fcgi.c
parent08c0f676fdb596b51b491a21913d73af141eb3fc (diff)
draft the PATH_INFO and SCRIPT_NAME handling
The idea is to require SCRIPT_NAME to be defined and strip it from the beginning of the path to get PATH_INFO. Soon(tm) a `fastcgi request strip' option will be added too. Maybe even `fastcgi script name "path"` that sets SCRIPT_NAME automatically.
Diffstat (limited to 'fcgi.c')
-rw-r--r--fcgi.c35
1 files changed, 33 insertions, 2 deletions
diff --git a/fcgi.c b/fcgi.c
index 281dfaa..1874c85 100644
--- a/fcgi.c
+++ b/fcgi.c
@@ -373,12 +373,38 @@ fcgi_error(struct bufferevent *bev, short err, void *d)
void
fcgi_req(struct client *c, struct location *loc)
{
- char buf[22];
- char *qs;
+ char buf[22], path[GEMINI_URL_LEN];
+ char *qs, *pathinfo, *scriptname = NULL;
+ size_t l;
time_t tim;
+ int r;
struct tm tminfo;
struct envlist *p;
+ TAILQ_FOREACH(p, &loc->params, envs) {
+ if (!strcmp(p->name, "SCRIPT_NAME")) {
+ scriptname = p->value;
+ break;
+ }
+ }
+ if (scriptname == NULL)
+ scriptname = "";
+
+ r = snprintf(path, sizeof(path), "/%s", c->iri.path);
+ if (r < 0 || (size_t)r >= sizeof(c->iri.path)) {
+ log_warn("snprintf failure?");
+ fcgi_error(c->cgibev, EVBUFFER_ERROR, c);
+ return;
+ }
+
+ pathinfo = path;
+ l = strlen(scriptname);
+ while (l > 0 && scriptname[l - 1] == '/')
+ l--;
+ if (!strncmp(scriptname, pathinfo, l))
+ pathinfo += l;
+ log_warnx("scriptname=%s ; pathinfo=%s", scriptname, pathinfo);
+
fcgi_begin_request(c->cgibev);
fcgi_send_param(c->cgibev, "GATEWAY_INTERFACE", "CGI/1.1");
fcgi_send_param(c->cgibev, "GEMINI_URL_PATH", c->iri.path);
@@ -390,6 +416,9 @@ fcgi_req(struct client *c, struct location *loc)
fcgi_send_param(c->cgibev, "SERVER_PROTOCOL", "GEMINI");
fcgi_send_param(c->cgibev, "SERVER_SOFTWARE", GMID_VERSION);
+ fcgi_send_param(c->cgibev, "SCRIPT_NAME", scriptname);
+ fcgi_send_param(c->cgibev, "PATH_INFO", pathinfo);
+
if (*c->iri.query != '\0' &&
strchr(c->iri.query, '=') == NULL &&
(qs = strdup(c->iri.query)) != NULL) {
@@ -399,6 +428,8 @@ fcgi_req(struct client *c, struct location *loc)
}
TAILQ_FOREACH(p, &loc->params, envs) {
+ if (!strcmp(p->name, "SCRIPT_NAME"))
+ continue;
fcgi_send_param(c->cgibev, p->name, p->value);
}