Skip to content

Commit 78fbb9f

Browse files
committed
MEDIUM: fcgi-app: Add FCGI application and filter
The FCGI application handles all the configuration parameters used to format requests sent to an application. The configuration of an application is grouped in a dedicated section (fcgi-app <name>) and referenced in a backend to be used (use-fcgi-app <name>). To be valid, a FCGI application must at least define a document root. But it is also possible to set the default index, a regex to split the script name and the path-info from the request URI, parameters to set or unset... In addition, this patch also adds a FCGI filter, responsible for all processing on a stream.
1 parent 63bbf28 commit 78fbb9f

File tree

7 files changed

+1296
-2
lines changed

7 files changed

+1296
-2
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,7 @@ OBJS = src/http_ana.o src/cfgparse-listen.o src/stream.o \
787787
src/protocol.o src/arg.o src/hpack-huff.o src/base64.o src/ring.o \
788788
src/hash.o src/mailers.o src/activity.o src/version.o src/trace.o \
789789
src/mworker.o src/mworker-prog.o src/debug.o src/wdt.o src/dict.o \
790-
src/xprt_handshake.o src/h1_htx.o src/fcgi.o
790+
src/xprt_handshake.o src/h1_htx.o src/fcgi.o src/fcgi-app.o
791791
792792
EBTREE_OBJS = $(EBTREE_DIR)/ebtree.o $(EBTREE_DIR)/eb32sctree.o \
793793
$(EBTREE_DIR)/eb32tree.o $(EBTREE_DIR)/eb64tree.o \

include/proto/fcgi-app.h

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* include/proto/fcgi-app.h
3+
* This file defines function prototypes for FCGI applications.
4+
*
5+
* Copyright (C) 2019 HAProxy Technologies, Christopher Faulet <[email protected]>
6+
*
7+
* This library is free software; you can redistribute it and/or
8+
* modify it under the terms of the GNU Lesser General Public
9+
* License as published by the Free Software Foundation, version 2.1
10+
* exclusively.
11+
*
12+
* This library is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
* Lesser General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Lesser General Public
18+
* License along with this library; if not, write to the Free Software
19+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20+
*/
21+
22+
#ifndef _PROTO_HTTP_FCGI_H
23+
#define _PROTO_HTTP_FCGI_H
24+
25+
#include <common/htx.h>
26+
27+
#include <types/fcgi-app.h>
28+
#include <types/proxy.h>
29+
#include <types/stream.h>
30+
31+
struct fcgi_app *fcgi_app_find_by_name(const char *name);
32+
struct fcgi_flt_conf *find_px_fcgi_conf(struct proxy *px);
33+
struct fcgi_flt_ctx *find_strm_fcgi_ctx(struct stream *s);
34+
struct fcgi_app *get_px_fcgi_app(struct proxy *px);
35+
struct fcgi_app *get_strm_fcgi_app(struct stream *s);
36+
37+
#endif /* _PROTO_HTTP_FCGI_H */
38+
39+
/*
40+
* Local variables:
41+
* c-indent-level: 8
42+
* c-basic-offset: 8
43+
* End:
44+
*/

include/proto/filters.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ extern const char *trace_flt_id;
3333
extern const char *http_comp_flt_id;
3434
extern const char *cache_store_flt_id;
3535
extern const char *spoe_filter_id;
36+
extern const char *fcgi_flt_id;
3637

3738
#define FLT_ID(flt) (flt)->config->id
3839
#define FLT_CONF(flt) (flt)->config->conf

include/types/fcgi-app.h

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
/*
2+
* include/types/fcgi-app.h
3+
* This file defines everything related to FCGI applications.
4+
*
5+
* Copyright (C) 2019 HAProxy Technologies, Christopher Faulet <[email protected]>
6+
*
7+
* This library is free software; you can redistribute it and/or
8+
* modify it under the terms of the GNU Lesser General Public
9+
* License as published by the Free Software Foundation, version 2.1
10+
* exclusively.
11+
*
12+
* This library is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
* Lesser General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Lesser General Public
18+
* License along with this library; if not, write to the Free Software
19+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20+
*/
21+
22+
#ifndef _TYPES_HTTP_FCGI_H
23+
#define _TYPES_HTTP_FCGI_H
24+
25+
#include <common/config.h>
26+
#include <common/ist.h>
27+
#include <common/fcgi.h>
28+
#include <common/mini-clist.h>
29+
#include <common/regex.h>
30+
31+
#include <ebistree.h>
32+
33+
#include <types/acl.h>
34+
#include <types/filters.h>
35+
36+
#define FCGI_APP_FL_KEEP_CONN 0x00000001 /* Keep the connection alive */
37+
#define FCGI_APP_FL_GET_VALUES 0x00000002 /* Retrieve FCGI variables on connection establishment */
38+
#define FCGI_APP_FL_MPXS_CONNS 0x00000004 /* FCGI APP supports connection multiplexing */
39+
40+
41+
enum fcgi_rule_type {
42+
FCGI_RULE_SET_PARAM = 0,
43+
FCGI_RULE_UNSET_PARAM,
44+
FCGI_RULE_PASS_HDR,
45+
FCGI_RULE_HIDE_HDR,
46+
};
47+
48+
/* Used during configuration parsing only and converted into fcgi_rule when
49+
* filter is created.
50+
*/
51+
struct fcgi_rule_conf {
52+
enum fcgi_rule_type type;
53+
char *name;
54+
char *value;
55+
struct acl_cond *cond; /* acl condition to set/unset the param */
56+
struct list list;
57+
};
58+
59+
/* parameter rule evaluated during request analyzis */
60+
struct fcgi_rule {
61+
enum fcgi_rule_type type;
62+
struct ist name; /* name of the parameter/header */
63+
struct list value; /* log-format compatible expression, may be empty */
64+
struct acl_cond *cond; /* acl condition to set the param */
65+
struct list list;
66+
};
67+
68+
/* parameter rule to set/unset a param at the end of the analyzis */
69+
struct fcgi_param_rule {
70+
struct ist name;
71+
struct list *value; /* if empty , unset the parameter */
72+
struct ebpt_node node;
73+
};
74+
75+
/* header rule to pass/hide a header at the end of the analyzis */
76+
struct fcgi_hdr_rule {
77+
struct ist name;
78+
int pass; /* 1 to pass the header, 0 Otherwise */
79+
struct ebpt_node node;
80+
};
81+
82+
struct fcgi_app {
83+
char *name; /* name to identify this set of params */
84+
struct ist docroot; /* FCGI docroot */
85+
struct ist index; /* filename to append to URI ending by a '/' */
86+
struct my_regex *pathinfo_re; /* Regex to use to split scriptname and path-info */
87+
unsigned int flags; /* FCGI_APP_FL_* */
88+
struct list logsrvs; /* log servers */
89+
unsigned int maxreqs; /* maximum number of concurrent requests */
90+
91+
struct list acls; /* list of acls declared for this application */
92+
93+
struct {
94+
char *file; /* file where the section appears */
95+
int line; /* line where the section appears */
96+
struct list rules; /* list of rules used during config parsing */
97+
struct arg_list args; /* sample arg list that need to be resolved */
98+
} conf; /* config information */
99+
struct fcgi_app *next; /* used to chain fcgi-app */
100+
};
101+
102+
/* FCGI config attached to backend proxies */
103+
struct fcgi_flt_conf {
104+
char *name; /* fcgi-app name used during config parsing */
105+
struct fcgi_app *app; /* configuration of the fcgi application */
106+
107+
struct list param_rules; /* list of set/unset rules */
108+
struct list hdr_rules; /* list of pass/add rules */
109+
};
110+
111+
/* FCGI context attached to streames */
112+
struct fcgi_flt_ctx {
113+
struct filter *filter;
114+
struct fcgi_app *app;
115+
};
116+
117+
#endif /* _TYPES_HTTP_FCGI_H */
118+
119+
/*
120+
* Local variables:
121+
* c-indent-level: 8
122+
* c-basic-offset: 8
123+
* End:
124+
*/

src/cache.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,11 @@ cache_store_check(struct proxy *px, struct flt_conf *fconf)
181181
}
182182
else if (f->id == http_comp_flt_id)
183183
comp = 1;
184+
else if (f->id == fcgi_flt_id)
185+
continue;
184186
else if ((f->id != fconf->id) && (cconf->flags & CACHE_FLT_F_IMPLICIT_DECL)) {
185187
/* Implicit declaration is only allowed with the
186-
* compression. For other filters, an implicit
188+
* compression and fcgi. For other filters, an implicit
187189
* declaration is required. */
188190
ha_alert("config: %s '%s': require an explicit filter declaration "
189191
"to use the cache '%s'.\n", proxy_type_str(px), px->id, cache->id);

0 commit comments

Comments
 (0)