diff options
author | Omar Polo <op@omarpolo.com> | 2022-11-29 23:08:23 +0000 |
---|---|---|
committer | Omar Polo <op@omarpolo.com> | 2022-11-29 23:08:23 +0000 |
commit | a057e3a49c3d893382b0a6e19348bec3d8a4f819 (patch) | |
tree | 66632a973618fe8ed7367b699059fff2637b1e97 | |
parent | fb6a629e6969c519b2523c343153f9b76e217843 (diff) |
add an implicit fastcgi parameter: GEMINI_SEARCH_STRING
backport of 97b306cbee6d105885a761e04274f661a0ec3757
it’s the QUERY_STRING decoded if it’s a search-string (i.e. not a
key-value pair.) It’s useful for scripts to avoid percent-decoding
the querystring in the most common case of a query, because in Gemini
querystrings key-value paired are not common.
Idea from a discussion with Allen Sobot.
-rw-r--r-- | fcgi.c | 9 | ||||
-rw-r--r-- | gmid.conf.5 | 6 | ||||
-rw-r--r-- | iri.c | 4 |
3 files changed, 18 insertions, 1 deletions
@@ -344,6 +344,7 @@ void fcgi_req(struct client *c) { char addr[NI_MAXHOST], buf[22]; + char *qs; int e; time_t tim; struct tm tminfo; @@ -368,6 +369,14 @@ fcgi_req(struct client *c) fcgi_send_param(c->cgibev, "SERVER_PROTOCOL", "GEMINI"); fcgi_send_param(c->cgibev, "SERVER_SOFTWARE", GMID_VERSION); + if (*c->iri.query != '\0' && + strchr(c->iri.query, '=') == NULL && + (qs = strdup(c->iri.query)) != NULL) { + pct_decode_str(qs); + fcgi_send_param(c->cgibev, "GEMINI_SEARCH_STRING", qs); + free(qs); + } + TAILQ_FOREACH(p, &c->host->params, envs) { fcgi_send_param(c->cgibev, p->name, p->value); } diff --git a/gmid.conf.5 b/gmid.conf.5 index 6df2320..34d78f6 100644 --- a/gmid.conf.5 +++ b/gmid.conf.5 @@ -231,6 +231,12 @@ Full path to the CGI script being executed. The full IRI of the request. .It Ev GEMINI_URL_PATH The path of the request. +.It Ev GEMINI_SEARCH_STRING +The decoded +.Ev QUERY_STRING +if defined in the request and if it doesn't contain any unencoded +.Sq = +characters, otherwise unset. .It Ev PATH_INFO The portion of the requested path that is derived from the the IRI path hierarchy following the part that identifies the script itself. @@ -488,7 +488,9 @@ pct_decode_str(char *s) char *t; for (t = s; *t; ++t) { - if (*t == '%' && valid_pct_enc_string(t)) + if (*t == '+') + *t = ' '; + else if (*t == '%' && valid_pct_enc_string(t)) pct_decode(t); } |