Add a configuration variable "fastcgi" to enable it per server or location.
authorreyk <reyk@openbsd.org>
Thu, 31 Jul 2014 09:34:57 +0000 (09:34 +0000)
committerreyk <reyk@openbsd.org>
Thu, 31 Jul 2014 09:34:57 +0000 (09:34 +0000)
usr.sbin/httpd/config.c
usr.sbin/httpd/httpd.conf.5
usr.sbin/httpd/httpd.h
usr.sbin/httpd/parse.y
usr.sbin/httpd/server_http.c

index 44cd419..cc8060f 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: config.c,v 1.7 2014/07/30 13:49:48 reyk Exp $ */
+/*     $OpenBSD: config.c,v 1.8 2014/07/31 09:34:57 reyk Exp $ */
 
 /*
  * Copyright (c) 2011 - 2014 Reyk Floeter <reyk@openbsd.org>
@@ -245,6 +245,10 @@ config_getserver_config(struct httpd *env, struct server *srv,
                            sizeof(srv_conf->docroot));
                }
 
+               f = SRVFLAG_FCGI|SRVFLAG_NO_FCGI;
+               if ((srv_conf->flags & f) == 0)
+                       srv_conf->flags |= srv->srv_conf.flags & f;
+
                DPRINTF("%s: %s %d received location \"%s\", parent \"%s\"",
                    __func__, ps->ps_title[privsep_process], ps->ps_instance,
                    srv_conf->location, srv->srv_conf.name);
index 9c056da..7cd03a8 100644 (file)
@@ -1,4 +1,4 @@
-.\"    $OpenBSD: httpd.conf.5,v 1.10 2014/07/30 10:05:14 reyk Exp $
+.\"    $OpenBSD: httpd.conf.5,v 1.11 2014/07/31 09:34:57 reyk Exp $
 .\"
 .\" Copyright (c) 2014 Reyk Floeter <reyk@openbsd.org>
 .\"
@@ -14,7 +14,7 @@
 .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 .\"
-.Dd $Mdocdate: July 30 2014 $
+.Dd $Mdocdate: July 31 2014 $
 .Dt HTTPD.CONF 5
 .Os
 .Sh NAME
@@ -128,6 +128,8 @@ If not specified, it defaults to
 Disable the directory index.
 .Nm httpd
 will neither display nor generate a directory index.
+.It Oo Ic no Oc Ic fastcgi
+Enable FastCGI instead of serving files.
 .It Ic listen on Ar address Ic port Ar number
 Set the listen address and port.
 .It Ic location Ar path { ... }
index 852a93f..66c047c 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: httpd.h,v 1.20 2014/07/31 09:23:53 florian Exp $      */
+/*     $OpenBSD: httpd.h,v 1.21 2014/07/31 09:34:57 reyk Exp $ */
 
 /*
  * Copyright (c) 2006 - 2014 Reyk Floeter <reyk@openbsd.org>
@@ -279,9 +279,12 @@ SPLAY_HEAD(client_tree, client);
 #define SRVFLAG_NO_AUTO_INDEX  0x08
 #define SRVFLAG_DOCROOT                0x10
 #define SRVFLAG_LOCATION       0x20
+#define SRVFLAG_FCGI           0x40
+#define SRVFLAG_NO_FCGI                0x80
 
 #define SRVFLAG_BITS                                           \
-       "\10\01INDEX\02NO_INDEX\03AUTO_INDEX\04NO_AUTO_INDEX\05LOCATION"
+       "\10\01INDEX\02NO_INDEX\03AUTO_INDEX\04NO_AUTO_INDEX"   \
+       "\05LOCATION\06FCGI\07NO_FCGI"
 
 #define TCPFLAG_NODELAY                0x01
 #define TCPFLAG_NNODELAY       0x02
index 3947f71..253664b 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: parse.y,v 1.10 2014/07/30 13:49:48 reyk Exp $ */
+/*     $OpenBSD: parse.y,v 1.11 2014/07/31 09:34:57 reyk Exp $ */
 
 /*
  * Copyright (c) 2007 - 2014 Reyk Floeter <reyk@openbsd.org>
@@ -126,8 +126,8 @@ typedef struct {
 
 %}
 
-%token ALL AUTO DIRECTORY INDEX LISTEN LOCATION LOG NO ON PORT PREFORK ROOT
-%token SERVER TYPES UPDATES VERBOSE
+%token ALL AUTO DIRECTORY FCGI INDEX LISTEN LOCATION LOG NO ON PORT
+%token PREFORK ROOT SERVER TYPES UPDATES VERBOSE
 %token ERROR INCLUDE
 %token <v.string>      STRING
 %token  <v.number>     NUMBER
@@ -296,6 +296,14 @@ serveroptsl        : LISTEN ON STRING port {
                }
                | DIRECTORY dirflags
                | DIRECTORY '{' dirflags_l '}'
+               | NO FCGI               {
+                       srv->srv_conf.flags &= ~SRVFLAG_FCGI;
+                       srv->srv_conf.flags |= SRVFLAG_NO_FCGI;
+               }
+               | FCGI                  {
+                       srv->srv_conf.flags &= ~SRVFLAG_NO_FCGI;
+                       srv->srv_conf.flags |= SRVFLAG_FCGI;
+               }
                | LOCATION STRING               {
                        struct server   *s;
 
@@ -535,6 +543,7 @@ lookup(char *s)
                { "all",                ALL },
                { "auto",               AUTO },
                { "directory",          DIRECTORY },
+               { "fastcgi",            FCGI },
                { "include",            INCLUDE },
                { "index",              INDEX },
                { "listen",             LISTEN },
index da60d15..3eff410 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: server_http.c,v 1.22 2014/07/31 09:23:53 florian Exp $        */
+/*     $OpenBSD: server_http.c,v 1.23 2014/07/31 09:34:57 reyk Exp $   */
 
 /*
  * Copyright (c) 2006 - 2014 Reyk Floeter <reyk@openbsd.org>
@@ -748,18 +748,17 @@ server_response(struct httpd *httpd, struct client *clt)
                    fnmatch(location->location, desc->http_path,
                    FNM_CASEFOLD) == 0) {
                        /* Replace host configuration */
-                       clt->clt_srv_conf = location;
-                       srv_conf = NULL;
+                       clt->clt_srv_conf = srv_conf = location;
                        break;
                }
        }
 
-       if (strlen(desc->http_path) > strlen("/cgi-bin/") &&
-           strncmp("/cgi-bin/", desc->http_path, strlen("/cgi-bin/")) == 0) {
-               if ((ret = server_fcgi(httpd, clt)) == -1)
-                       return (-1);
-       } else if ((ret = server_file(httpd, clt)) == -1)
-               return (-1);
+       if (srv_conf->flags & SRVFLAG_FCGI)
+               ret = server_fcgi(httpd, clt);
+       else
+               ret = server_file(httpd, clt);
+       if (ret == -1)
+               return (ret);
 
        server_reset_http(clt);