mirror of https://github.com/omar-polo/gmid.git
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.
This commit is contained in:
parent
08c0f676fd
commit
b27dc2b0a3
35
fcgi.c
35
fcgi.c
|
@ -373,12 +373,38 @@ fcgi_error(struct bufferevent *bev, short err, void *d)
|
||||||
void
|
void
|
||||||
fcgi_req(struct client *c, struct location *loc)
|
fcgi_req(struct client *c, struct location *loc)
|
||||||
{
|
{
|
||||||
char buf[22];
|
char buf[22], path[GEMINI_URL_LEN];
|
||||||
char *qs;
|
char *qs, *pathinfo, *scriptname = NULL;
|
||||||
|
size_t l;
|
||||||
time_t tim;
|
time_t tim;
|
||||||
|
int r;
|
||||||
struct tm tminfo;
|
struct tm tminfo;
|
||||||
struct envlist *p;
|
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_begin_request(c->cgibev);
|
||||||
fcgi_send_param(c->cgibev, "GATEWAY_INTERFACE", "CGI/1.1");
|
fcgi_send_param(c->cgibev, "GATEWAY_INTERFACE", "CGI/1.1");
|
||||||
fcgi_send_param(c->cgibev, "GEMINI_URL_PATH", c->iri.path);
|
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_PROTOCOL", "GEMINI");
|
||||||
fcgi_send_param(c->cgibev, "SERVER_SOFTWARE", GMID_VERSION);
|
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' &&
|
if (*c->iri.query != '\0' &&
|
||||||
strchr(c->iri.query, '=') == NULL &&
|
strchr(c->iri.query, '=') == NULL &&
|
||||||
(qs = strdup(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) {
|
TAILQ_FOREACH(p, &loc->params, envs) {
|
||||||
|
if (!strcmp(p->name, "SCRIPT_NAME"))
|
||||||
|
continue;
|
||||||
fcgi_send_param(c->cgibev, p->name, p->value);
|
fcgi_send_param(c->cgibev, p->name, p->value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue