2016-03-19 15:14:35 +00:00
# include "first.h"
2009-10-11 14:31:42 +00:00
# include <sys/types.h>
# include <errno.h>
2018-03-25 07:45:05 +00:00
# include <stdlib.h>
2009-10-11 14:31:42 +00:00
# include <string.h>
[core] shared code for socket backends
common codebase for socket backends, based off mod_fastcgi with
some features added for mod_proxy
(mostly intended to reduce code duplication and enhance code isolation)
mod_fastcgi and mod_scgi can now use fastcgi.balance and scgi.balance
for similar behavior as proxy.balance, but the balancing is per-host
and not per-proc. proxy.balance is also per-host and not per-proc.
mod_proxy and mod_scgi can now use proxy.map-extensions and
scgi.map-extensions, similar to fastcgi.map-extensions.
mod_fastcgi behavior change (affects only mod_status):
- statistics tags have been renamed from "fastcgi.*" to "gw.*"
"fastcgi.backend.*" -> "gw.backend.*"
"fastcgi.active-requests" -> "gw.active-requests"
("fastcgi.requests" remains "fastcgi.requests")
("proxy.requests" is new)
("scgi.requests" is new)
mod_scgi behavior change (likely minor):
- removed scgi_proclist_sort_down() and scgi_proclist_sort_up().
procs now chosen based on load as measured by num socket connnections
Note:
modules using gw_backend.[ch] are currently still independent modules.
If it had been written as a single module with fastcgi, scgi, proxy
implementations, then there would have been a chance of breaking some
existing user configurations where module ordering made a difference
for which module handled a given request, though for most people, this
would have made no difference.
Details about mod_fastcgi code transformations:
unsigned int debug -> int debug
fastcgi_env member removed from plugin_config
renamed "fcgi" and "fastcgi" to "gw", and "FCGI" to "GW"
reorganize routines for high-level and lower-level interfaces
some lower-level internal interfaces changed to use host,proc,debug
args rather than knowing about higher-level (app) hctx and plugin_data
tabs->spaces and reformatting
2017-07-14 05:29:18 +00:00
# include "gw_backend.h"
typedef gw_plugin_config plugin_config ;
typedef gw_plugin_data plugin_data ;
typedef gw_handler_ctx handler_ctx ;
# include "base.h"
# include "buffer.h"
# include "fdevent.h"
# include "http_chunk.h"
# include "log.h"
# include "status_counter.h"
2009-10-11 14:31:42 +00:00
2006-10-03 22:22:47 +00:00
# ifdef HAVE_FASTCGI_FASTCGI_H
2009-10-11 14:31:42 +00:00
# include <fastcgi / fastcgi.h>
2006-10-03 22:22:47 +00:00
# else
2009-10-11 14:31:42 +00:00
# ifdef HAVE_FASTCGI_H
# include <fastcgi.h>
# else
# include "fastcgi.h"
# endif
2006-10-03 22:22:47 +00:00
# endif /* HAVE_FASTCGI_FASTCGI_H */
2009-10-11 14:31:42 +00:00
[core] shared code for socket backends
common codebase for socket backends, based off mod_fastcgi with
some features added for mod_proxy
(mostly intended to reduce code duplication and enhance code isolation)
mod_fastcgi and mod_scgi can now use fastcgi.balance and scgi.balance
for similar behavior as proxy.balance, but the balancing is per-host
and not per-proc. proxy.balance is also per-host and not per-proc.
mod_proxy and mod_scgi can now use proxy.map-extensions and
scgi.map-extensions, similar to fastcgi.map-extensions.
mod_fastcgi behavior change (affects only mod_status):
- statistics tags have been renamed from "fastcgi.*" to "gw.*"
"fastcgi.backend.*" -> "gw.backend.*"
"fastcgi.active-requests" -> "gw.active-requests"
("fastcgi.requests" remains "fastcgi.requests")
("proxy.requests" is new)
("scgi.requests" is new)
mod_scgi behavior change (likely minor):
- removed scgi_proclist_sort_down() and scgi_proclist_sort_up().
procs now chosen based on load as measured by num socket connnections
Note:
modules using gw_backend.[ch] are currently still independent modules.
If it had been written as a single module with fastcgi, scgi, proxy
implementations, then there would have been a chance of breaking some
existing user configurations where module ordering made a difference
for which module handled a given request, though for most people, this
would have made no difference.
Details about mod_fastcgi code transformations:
unsigned int debug -> int debug
fastcgi_env member removed from plugin_config
renamed "fcgi" and "fastcgi" to "gw", and "FCGI" to "GW"
reorganize routines for high-level and lower-level interfaces
some lower-level internal interfaces changed to use host,proc,debug
args rather than knowing about higher-level (app) hctx and plugin_data
tabs->spaces and reformatting
2017-07-14 05:29:18 +00:00
# if GW_RESPONDER != FCGI_RESPONDER
# error "mismatched defines: (GW_RESPONDER != FCGI_RESPONDER)"
2005-02-20 14:27:00 +00:00
# endif
[core] shared code for socket backends
common codebase for socket backends, based off mod_fastcgi with
some features added for mod_proxy
(mostly intended to reduce code duplication and enhance code isolation)
mod_fastcgi and mod_scgi can now use fastcgi.balance and scgi.balance
for similar behavior as proxy.balance, but the balancing is per-host
and not per-proc. proxy.balance is also per-host and not per-proc.
mod_proxy and mod_scgi can now use proxy.map-extensions and
scgi.map-extensions, similar to fastcgi.map-extensions.
mod_fastcgi behavior change (affects only mod_status):
- statistics tags have been renamed from "fastcgi.*" to "gw.*"
"fastcgi.backend.*" -> "gw.backend.*"
"fastcgi.active-requests" -> "gw.active-requests"
("fastcgi.requests" remains "fastcgi.requests")
("proxy.requests" is new)
("scgi.requests" is new)
mod_scgi behavior change (likely minor):
- removed scgi_proclist_sort_down() and scgi_proclist_sort_up().
procs now chosen based on load as measured by num socket connnections
Note:
modules using gw_backend.[ch] are currently still independent modules.
If it had been written as a single module with fastcgi, scgi, proxy
implementations, then there would have been a chance of breaking some
existing user configurations where module ordering made a difference
for which module handled a given request, though for most people, this
would have made no difference.
Details about mod_fastcgi code transformations:
unsigned int debug -> int debug
fastcgi_env member removed from plugin_config
renamed "fcgi" and "fastcgi" to "gw", and "FCGI" to "GW"
reorganize routines for high-level and lower-level interfaces
some lower-level internal interfaces changed to use host,proc,debug
args rather than knowing about higher-level (app) hctx and plugin_data
tabs->spaces and reformatting
2017-07-14 05:29:18 +00:00
# if GW_AUTHORIZER != FCGI_AUTHORIZER
# error "mismatched defines: (GW_AUTHORIZER != FCGI_AUTHORIZER)"
# endif
# if GW_FILTER != FCGI_FILTER
# error "mismatched defines: (GW_FILTER != FCGI_FILTER)"
2005-02-20 14:27:00 +00:00
# endif
2016-04-01 01:59:32 +00:00
2005-02-20 14:27:00 +00:00
SETDEFAULTS_FUNC ( mod_fastcgi_set_defaults ) {
plugin_data * p = p_d ;
data_unset * du ;
size_t i = 0 ;
2006-10-04 13:26:23 +00:00
config_values_t cv [ ] = {
2005-02-20 14:27:00 +00:00
{ " fastcgi.server " , NULL , T_CONFIG_LOCAL , T_CONFIG_SCOPE_CONNECTION } , /* 0 */
2010-07-04 07:45:29 +00:00
{ " fastcgi.debug " , NULL , T_CONFIG_INT , T_CONFIG_SCOPE_CONNECTION } , /* 1 */
2006-01-31 12:05:03 +00:00
{ " fastcgi.map-extensions " , NULL , T_CONFIG_ARRAY , T_CONFIG_SCOPE_CONNECTION } , /* 2 */
[core] shared code for socket backends
common codebase for socket backends, based off mod_fastcgi with
some features added for mod_proxy
(mostly intended to reduce code duplication and enhance code isolation)
mod_fastcgi and mod_scgi can now use fastcgi.balance and scgi.balance
for similar behavior as proxy.balance, but the balancing is per-host
and not per-proc. proxy.balance is also per-host and not per-proc.
mod_proxy and mod_scgi can now use proxy.map-extensions and
scgi.map-extensions, similar to fastcgi.map-extensions.
mod_fastcgi behavior change (affects only mod_status):
- statistics tags have been renamed from "fastcgi.*" to "gw.*"
"fastcgi.backend.*" -> "gw.backend.*"
"fastcgi.active-requests" -> "gw.active-requests"
("fastcgi.requests" remains "fastcgi.requests")
("proxy.requests" is new)
("scgi.requests" is new)
mod_scgi behavior change (likely minor):
- removed scgi_proclist_sort_down() and scgi_proclist_sort_up().
procs now chosen based on load as measured by num socket connnections
Note:
modules using gw_backend.[ch] are currently still independent modules.
If it had been written as a single module with fastcgi, scgi, proxy
implementations, then there would have been a chance of breaking some
existing user configurations where module ordering made a difference
for which module handled a given request, though for most people, this
would have made no difference.
Details about mod_fastcgi code transformations:
unsigned int debug -> int debug
fastcgi_env member removed from plugin_config
renamed "fcgi" and "fastcgi" to "gw", and "FCGI" to "GW"
reorganize routines for high-level and lower-level interfaces
some lower-level internal interfaces changed to use host,proc,debug
args rather than knowing about higher-level (app) hctx and plugin_data
tabs->spaces and reformatting
2017-07-14 05:29:18 +00:00
{ " fastcgi.balance " , NULL , T_CONFIG_LOCAL , T_CONFIG_SCOPE_CONNECTION } , /* 3 */
2005-02-20 14:27:00 +00:00
{ NULL , NULL , T_CONFIG_UNSET , T_CONFIG_SCOPE_UNSET }
} ;
2006-10-04 13:26:23 +00:00
2013-11-13 11:43:26 +00:00
p - > config_storage = calloc ( 1 , srv - > config_context - > used * sizeof ( plugin_config * ) ) ;
[core] shared code for socket backends
common codebase for socket backends, based off mod_fastcgi with
some features added for mod_proxy
(mostly intended to reduce code duplication and enhance code isolation)
mod_fastcgi and mod_scgi can now use fastcgi.balance and scgi.balance
for similar behavior as proxy.balance, but the balancing is per-host
and not per-proc. proxy.balance is also per-host and not per-proc.
mod_proxy and mod_scgi can now use proxy.map-extensions and
scgi.map-extensions, similar to fastcgi.map-extensions.
mod_fastcgi behavior change (affects only mod_status):
- statistics tags have been renamed from "fastcgi.*" to "gw.*"
"fastcgi.backend.*" -> "gw.backend.*"
"fastcgi.active-requests" -> "gw.active-requests"
("fastcgi.requests" remains "fastcgi.requests")
("proxy.requests" is new)
("scgi.requests" is new)
mod_scgi behavior change (likely minor):
- removed scgi_proclist_sort_down() and scgi_proclist_sort_up().
procs now chosen based on load as measured by num socket connnections
Note:
modules using gw_backend.[ch] are currently still independent modules.
If it had been written as a single module with fastcgi, scgi, proxy
implementations, then there would have been a chance of breaking some
existing user configurations where module ordering made a difference
for which module handled a given request, though for most people, this
would have made no difference.
Details about mod_fastcgi code transformations:
unsigned int debug -> int debug
fastcgi_env member removed from plugin_config
renamed "fcgi" and "fastcgi" to "gw", and "FCGI" to "GW"
reorganize routines for high-level and lower-level interfaces
some lower-level internal interfaces changed to use host,proc,debug
args rather than knowing about higher-level (app) hctx and plugin_data
tabs->spaces and reformatting
2017-07-14 05:29:18 +00:00
force_assert ( p - > config_storage ) ;
2006-10-04 13:26:23 +00:00
2005-02-20 14:27:00 +00:00
for ( i = 0 ; i < srv - > config_context - > used ; i + + ) {
2015-11-07 12:51:11 +00:00
data_config const * config = ( data_config const * ) srv - > config_context - > data [ i ] ;
2005-02-20 14:27:00 +00:00
plugin_config * s ;
2006-10-04 13:26:23 +00:00
2017-05-01 00:37:33 +00:00
s = calloc ( 1 , sizeof ( plugin_config ) ) ;
[core] shared code for socket backends
common codebase for socket backends, based off mod_fastcgi with
some features added for mod_proxy
(mostly intended to reduce code duplication and enhance code isolation)
mod_fastcgi and mod_scgi can now use fastcgi.balance and scgi.balance
for similar behavior as proxy.balance, but the balancing is per-host
and not per-proc. proxy.balance is also per-host and not per-proc.
mod_proxy and mod_scgi can now use proxy.map-extensions and
scgi.map-extensions, similar to fastcgi.map-extensions.
mod_fastcgi behavior change (affects only mod_status):
- statistics tags have been renamed from "fastcgi.*" to "gw.*"
"fastcgi.backend.*" -> "gw.backend.*"
"fastcgi.active-requests" -> "gw.active-requests"
("fastcgi.requests" remains "fastcgi.requests")
("proxy.requests" is new)
("scgi.requests" is new)
mod_scgi behavior change (likely minor):
- removed scgi_proclist_sort_down() and scgi_proclist_sort_up().
procs now chosen based on load as measured by num socket connnections
Note:
modules using gw_backend.[ch] are currently still independent modules.
If it had been written as a single module with fastcgi, scgi, proxy
implementations, then there would have been a chance of breaking some
existing user configurations where module ordering made a difference
for which module handled a given request, though for most people, this
would have made no difference.
Details about mod_fastcgi code transformations:
unsigned int debug -> int debug
fastcgi_env member removed from plugin_config
renamed "fcgi" and "fastcgi" to "gw", and "FCGI" to "GW"
reorganize routines for high-level and lower-level interfaces
some lower-level internal interfaces changed to use host,proc,debug
args rather than knowing about higher-level (app) hctx and plugin_data
tabs->spaces and reformatting
2017-07-14 05:29:18 +00:00
force_assert ( s ) ;
2016-09-19 23:58:51 +00:00
s - > exts = NULL ;
s - > exts_auth = NULL ;
s - > exts_resp = NULL ;
2005-02-20 14:27:00 +00:00
s - > debug = 0 ;
2006-01-31 12:05:03 +00:00
s - > ext_mapping = array_init ( ) ;
2006-10-04 13:26:23 +00:00
2016-09-19 23:58:51 +00:00
cv [ 0 ] . destination = s - > exts ; /* not used; T_CONFIG_LOCAL */
2005-02-20 14:27:00 +00:00
cv [ 1 ] . destination = & ( s - > debug ) ;
2006-01-31 12:05:03 +00:00
cv [ 2 ] . destination = s - > ext_mapping ;
[core] shared code for socket backends
common codebase for socket backends, based off mod_fastcgi with
some features added for mod_proxy
(mostly intended to reduce code duplication and enhance code isolation)
mod_fastcgi and mod_scgi can now use fastcgi.balance and scgi.balance
for similar behavior as proxy.balance, but the balancing is per-host
and not per-proc. proxy.balance is also per-host and not per-proc.
mod_proxy and mod_scgi can now use proxy.map-extensions and
scgi.map-extensions, similar to fastcgi.map-extensions.
mod_fastcgi behavior change (affects only mod_status):
- statistics tags have been renamed from "fastcgi.*" to "gw.*"
"fastcgi.backend.*" -> "gw.backend.*"
"fastcgi.active-requests" -> "gw.active-requests"
("fastcgi.requests" remains "fastcgi.requests")
("proxy.requests" is new)
("scgi.requests" is new)
mod_scgi behavior change (likely minor):
- removed scgi_proclist_sort_down() and scgi_proclist_sort_up().
procs now chosen based on load as measured by num socket connnections
Note:
modules using gw_backend.[ch] are currently still independent modules.
If it had been written as a single module with fastcgi, scgi, proxy
implementations, then there would have been a chance of breaking some
existing user configurations where module ordering made a difference
for which module handled a given request, though for most people, this
would have made no difference.
Details about mod_fastcgi code transformations:
unsigned int debug -> int debug
fastcgi_env member removed from plugin_config
renamed "fcgi" and "fastcgi" to "gw", and "FCGI" to "GW"
reorganize routines for high-level and lower-level interfaces
some lower-level internal interfaces changed to use host,proc,debug
args rather than knowing about higher-level (app) hctx and plugin_data
tabs->spaces and reformatting
2017-07-14 05:29:18 +00:00
cv [ 3 ] . destination = NULL ; /* not used; T_CONFIG_LOCAL */
2006-10-04 13:26:23 +00:00
2005-02-20 14:27:00 +00:00
p - > config_storage [ i ] = s ;
2006-10-04 13:26:23 +00:00
2015-11-07 12:51:11 +00:00
if ( 0 ! = config_insert_values_global ( srv , config - > value , cv , i = = 0 ? T_CONFIG_SCOPE_SERVER : T_CONFIG_SCOPE_CONNECTION ) ) {
[core] shared code for socket backends
common codebase for socket backends, based off mod_fastcgi with
some features added for mod_proxy
(mostly intended to reduce code duplication and enhance code isolation)
mod_fastcgi and mod_scgi can now use fastcgi.balance and scgi.balance
for similar behavior as proxy.balance, but the balancing is per-host
and not per-proc. proxy.balance is also per-host and not per-proc.
mod_proxy and mod_scgi can now use proxy.map-extensions and
scgi.map-extensions, similar to fastcgi.map-extensions.
mod_fastcgi behavior change (affects only mod_status):
- statistics tags have been renamed from "fastcgi.*" to "gw.*"
"fastcgi.backend.*" -> "gw.backend.*"
"fastcgi.active-requests" -> "gw.active-requests"
("fastcgi.requests" remains "fastcgi.requests")
("proxy.requests" is new)
("scgi.requests" is new)
mod_scgi behavior change (likely minor):
- removed scgi_proclist_sort_down() and scgi_proclist_sort_up().
procs now chosen based on load as measured by num socket connnections
Note:
modules using gw_backend.[ch] are currently still independent modules.
If it had been written as a single module with fastcgi, scgi, proxy
implementations, then there would have been a chance of breaking some
existing user configurations where module ordering made a difference
for which module handled a given request, though for most people, this
would have made no difference.
Details about mod_fastcgi code transformations:
unsigned int debug -> int debug
fastcgi_env member removed from plugin_config
renamed "fcgi" and "fastcgi" to "gw", and "FCGI" to "GW"
reorganize routines for high-level and lower-level interfaces
some lower-level internal interfaces changed to use host,proc,debug
args rather than knowing about higher-level (app) hctx and plugin_data
tabs->spaces and reformatting
2017-07-14 05:29:18 +00:00
return HANDLER_ERROR ;
2005-02-20 14:27:00 +00:00
}
2016-09-19 00:23:59 +00:00
[core] shared code for socket backends
common codebase for socket backends, based off mod_fastcgi with
some features added for mod_proxy
(mostly intended to reduce code duplication and enhance code isolation)
mod_fastcgi and mod_scgi can now use fastcgi.balance and scgi.balance
for similar behavior as proxy.balance, but the balancing is per-host
and not per-proc. proxy.balance is also per-host and not per-proc.
mod_proxy and mod_scgi can now use proxy.map-extensions and
scgi.map-extensions, similar to fastcgi.map-extensions.
mod_fastcgi behavior change (affects only mod_status):
- statistics tags have been renamed from "fastcgi.*" to "gw.*"
"fastcgi.backend.*" -> "gw.backend.*"
"fastcgi.active-requests" -> "gw.active-requests"
("fastcgi.requests" remains "fastcgi.requests")
("proxy.requests" is new)
("scgi.requests" is new)
mod_scgi behavior change (likely minor):
- removed scgi_proclist_sort_down() and scgi_proclist_sort_up().
procs now chosen based on load as measured by num socket connnections
Note:
modules using gw_backend.[ch] are currently still independent modules.
If it had been written as a single module with fastcgi, scgi, proxy
implementations, then there would have been a chance of breaking some
existing user configurations where module ordering made a difference
for which module handled a given request, though for most people, this
would have made no difference.
Details about mod_fastcgi code transformations:
unsigned int debug -> int debug
fastcgi_env member removed from plugin_config
renamed "fcgi" and "fastcgi" to "gw", and "FCGI" to "GW"
reorganize routines for high-level and lower-level interfaces
some lower-level internal interfaces changed to use host,proc,debug
args rather than knowing about higher-level (app) hctx and plugin_data
tabs->spaces and reformatting
2017-07-14 05:29:18 +00:00
du = array_get_element ( config - > value , " fastcgi.server " ) ;
if ( ! gw_set_defaults_backend ( srv , p , du , i , 0 ) ) {
return HANDLER_ERROR ;
2016-10-25 21:44:45 +00:00
}
[core] shared code for socket backends
common codebase for socket backends, based off mod_fastcgi with
some features added for mod_proxy
(mostly intended to reduce code duplication and enhance code isolation)
mod_fastcgi and mod_scgi can now use fastcgi.balance and scgi.balance
for similar behavior as proxy.balance, but the balancing is per-host
and not per-proc. proxy.balance is also per-host and not per-proc.
mod_proxy and mod_scgi can now use proxy.map-extensions and
scgi.map-extensions, similar to fastcgi.map-extensions.
mod_fastcgi behavior change (affects only mod_status):
- statistics tags have been renamed from "fastcgi.*" to "gw.*"
"fastcgi.backend.*" -> "gw.backend.*"
"fastcgi.active-requests" -> "gw.active-requests"
("fastcgi.requests" remains "fastcgi.requests")
("proxy.requests" is new)
("scgi.requests" is new)
mod_scgi behavior change (likely minor):
- removed scgi_proclist_sort_down() and scgi_proclist_sort_up().
procs now chosen based on load as measured by num socket connnections
Note:
modules using gw_backend.[ch] are currently still independent modules.
If it had been written as a single module with fastcgi, scgi, proxy
implementations, then there would have been a chance of breaking some
existing user configurations where module ordering made a difference
for which module handled a given request, though for most people, this
would have made no difference.
Details about mod_fastcgi code transformations:
unsigned int debug -> int debug
fastcgi_env member removed from plugin_config
renamed "fcgi" and "fastcgi" to "gw", and "FCGI" to "GW"
reorganize routines for high-level and lower-level interfaces
some lower-level internal interfaces changed to use host,proc,debug
args rather than knowing about higher-level (app) hctx and plugin_data
tabs->spaces and reformatting
2017-07-14 05:29:18 +00:00
du = array_get_element ( config - > value , " fastcgi.balance " ) ;
if ( ! gw_set_defaults_balance ( srv , s , du ) ) {
return HANDLER_ERROR ;
2016-10-25 21:44:45 +00:00
}
}
2005-02-20 14:27:00 +00:00
return HANDLER_GO_ON ;
}
consistent, shared code to create CGI env
consolidated from CGI, FastCGI, SCGI, SSI
Note: due to prior inconsistencies between the code in mod_cgi,
mod_fastcgi, mod_scgi, and mod_ssi, there are some minor behavior
changes.
CONTENT_LENGTH is now always set, even if 0
(though CONTENT_LENGTH is never set for FASTCGI_AUTHORIZER)
PATH_INFO is created only if present, not if empty.
(mod_fastcgi and mod_ssi previously set PATH_INFO="" (blank value))
PATH_TRANSLATED is now set if PATH_INFO is present
(previously missing from mod_cgi and mod_ssi)
mod_ssi now sets DOCUMENT_ROOT to con->physical.basedir, like others
(previously, mod_ssi set DOCUMENT_ROOT to con->physical.doc_root,
which matched con->physical.basedir unless mod_alias changed basedir)
mod_ssi now sets REQUEST_URI to con->request.orig_uri, like others
(previously, mod_ssi set REQUEST_URI to con->request.uri, which
matched con->request.orig_uri except after redirects, error docs)
2016-10-10 17:37:36 +00:00
static int fcgi_env_add ( void * venv , const char * key , size_t key_len , const char * val , size_t val_len ) {
buffer * env = venv ;
2005-02-20 14:27:00 +00:00
size_t len ;
2015-02-08 19:10:39 +00:00
char len_enc [ 8 ] ;
size_t len_enc_len = 0 ;
2006-10-04 13:26:23 +00:00
2005-02-20 14:27:00 +00:00
if ( ! key | | ! val ) return - 1 ;
2006-10-04 13:26:23 +00:00
2005-02-20 14:27:00 +00:00
len = key_len + val_len ;
2006-10-04 13:26:23 +00:00
2005-02-20 14:27:00 +00:00
len + = key_len > 127 ? 4 : 1 ;
len + = val_len > 127 ? 4 : 1 ;
2006-10-04 13:26:23 +00:00
2015-02-08 19:10:39 +00:00
if ( buffer_string_length ( env ) + len > = FCGI_MAX_LENGTH ) {
2007-09-05 11:22:32 +00:00
/**
* we can ' t append more headers , ignore it
*/
return - 1 ;
}
2007-09-05 11:28:35 +00:00
/**
* field length can be 31 bit max
*
* HINT : this can ' t happen as FCGI_MAX_LENGTH is only 16 bit
*/
2015-02-08 19:10:39 +00:00
force_assert ( key_len < 0x7fffffffu ) ;
force_assert ( val_len < 0x7fffffffu ) ;
2007-09-05 11:28:35 +00:00
2015-02-08 19:10:39 +00:00
buffer_string_prepare_append ( env , len ) ;
2006-10-04 13:26:23 +00:00
2005-02-20 14:27:00 +00:00
if ( key_len > 127 ) {
2015-02-08 19:10:39 +00:00
len_enc [ len_enc_len + + ] = ( ( key_len > > 24 ) & 0xff ) | 0x80 ;
len_enc [ len_enc_len + + ] = ( key_len > > 16 ) & 0xff ;
len_enc [ len_enc_len + + ] = ( key_len > > 8 ) & 0xff ;
len_enc [ len_enc_len + + ] = ( key_len > > 0 ) & 0xff ;
2005-02-20 14:27:00 +00:00
} else {
2015-02-08 19:10:39 +00:00
len_enc [ len_enc_len + + ] = ( key_len > > 0 ) & 0xff ;
2005-02-20 14:27:00 +00:00
}
2006-10-04 13:26:23 +00:00
2005-02-20 14:27:00 +00:00
if ( val_len > 127 ) {
2015-02-08 19:10:39 +00:00
len_enc [ len_enc_len + + ] = ( ( val_len > > 24 ) & 0xff ) | 0x80 ;
len_enc [ len_enc_len + + ] = ( val_len > > 16 ) & 0xff ;
len_enc [ len_enc_len + + ] = ( val_len > > 8 ) & 0xff ;
len_enc [ len_enc_len + + ] = ( val_len > > 0 ) & 0xff ;
2005-02-20 14:27:00 +00:00
} else {
2015-02-08 19:10:39 +00:00
len_enc [ len_enc_len + + ] = ( val_len > > 0 ) & 0xff ;
2005-02-20 14:27:00 +00:00
}
2006-10-04 13:26:23 +00:00
2015-02-08 19:10:39 +00:00
buffer_append_string_len ( env , len_enc , len_enc_len ) ;
buffer_append_string_len ( env , key , key_len ) ;
buffer_append_string_len ( env , val , val_len ) ;
2006-10-04 13:26:23 +00:00
2005-02-20 14:27:00 +00:00
return 0 ;
}
[core] shared code for socket backends
common codebase for socket backends, based off mod_fastcgi with
some features added for mod_proxy
(mostly intended to reduce code duplication and enhance code isolation)
mod_fastcgi and mod_scgi can now use fastcgi.balance and scgi.balance
for similar behavior as proxy.balance, but the balancing is per-host
and not per-proc. proxy.balance is also per-host and not per-proc.
mod_proxy and mod_scgi can now use proxy.map-extensions and
scgi.map-extensions, similar to fastcgi.map-extensions.
mod_fastcgi behavior change (affects only mod_status):
- statistics tags have been renamed from "fastcgi.*" to "gw.*"
"fastcgi.backend.*" -> "gw.backend.*"
"fastcgi.active-requests" -> "gw.active-requests"
("fastcgi.requests" remains "fastcgi.requests")
("proxy.requests" is new)
("scgi.requests" is new)
mod_scgi behavior change (likely minor):
- removed scgi_proclist_sort_down() and scgi_proclist_sort_up().
procs now chosen based on load as measured by num socket connnections
Note:
modules using gw_backend.[ch] are currently still independent modules.
If it had been written as a single module with fastcgi, scgi, proxy
implementations, then there would have been a chance of breaking some
existing user configurations where module ordering made a difference
for which module handled a given request, though for most people, this
would have made no difference.
Details about mod_fastcgi code transformations:
unsigned int debug -> int debug
fastcgi_env member removed from plugin_config
renamed "fcgi" and "fastcgi" to "gw", and "FCGI" to "GW"
reorganize routines for high-level and lower-level interfaces
some lower-level internal interfaces changed to use host,proc,debug
args rather than knowing about higher-level (app) hctx and plugin_data
tabs->spaces and reformatting
2017-07-14 05:29:18 +00:00
static void fcgi_header ( FCGI_Header * header , unsigned char type , int request_id , int contentLength , unsigned char paddingLength ) {
2014-02-16 13:08:20 +00:00
force_assert ( contentLength < = FCGI_MAX_LENGTH ) ;
2007-09-05 11:22:32 +00:00
2005-02-20 14:27:00 +00:00
header - > version = FCGI_VERSION_1 ;
header - > type = type ;
header - > requestIdB0 = request_id & 0xff ;
header - > requestIdB1 = ( request_id > > 8 ) & 0xff ;
header - > contentLengthB0 = contentLength & 0xff ;
header - > contentLengthB1 = ( contentLength > > 8 ) & 0xff ;
header - > paddingLength = paddingLength ;
header - > reserved = 0 ;
}
[core] shared code for socket backends
common codebase for socket backends, based off mod_fastcgi with
some features added for mod_proxy
(mostly intended to reduce code duplication and enhance code isolation)
mod_fastcgi and mod_scgi can now use fastcgi.balance and scgi.balance
for similar behavior as proxy.balance, but the balancing is per-host
and not per-proc. proxy.balance is also per-host and not per-proc.
mod_proxy and mod_scgi can now use proxy.map-extensions and
scgi.map-extensions, similar to fastcgi.map-extensions.
mod_fastcgi behavior change (affects only mod_status):
- statistics tags have been renamed from "fastcgi.*" to "gw.*"
"fastcgi.backend.*" -> "gw.backend.*"
"fastcgi.active-requests" -> "gw.active-requests"
("fastcgi.requests" remains "fastcgi.requests")
("proxy.requests" is new)
("scgi.requests" is new)
mod_scgi behavior change (likely minor):
- removed scgi_proclist_sort_down() and scgi_proclist_sort_up().
procs now chosen based on load as measured by num socket connnections
Note:
modules using gw_backend.[ch] are currently still independent modules.
If it had been written as a single module with fastcgi, scgi, proxy
implementations, then there would have been a chance of breaking some
existing user configurations where module ordering made a difference
for which module handled a given request, though for most people, this
would have made no difference.
Details about mod_fastcgi code transformations:
unsigned int debug -> int debug
fastcgi_env member removed from plugin_config
renamed "fcgi" and "fastcgi" to "gw", and "FCGI" to "GW"
reorganize routines for high-level and lower-level interfaces
some lower-level internal interfaces changed to use host,proc,debug
args rather than knowing about higher-level (app) hctx and plugin_data
tabs->spaces and reformatting
2017-07-14 05:29:18 +00:00
static handler_t fcgi_stdin_append ( server * srv , handler_ctx * hctx ) {
2016-06-10 04:04:10 +00:00
FCGI_Header header ;
[core] shared code for socket backends
common codebase for socket backends, based off mod_fastcgi with
some features added for mod_proxy
(mostly intended to reduce code duplication and enhance code isolation)
mod_fastcgi and mod_scgi can now use fastcgi.balance and scgi.balance
for similar behavior as proxy.balance, but the balancing is per-host
and not per-proc. proxy.balance is also per-host and not per-proc.
mod_proxy and mod_scgi can now use proxy.map-extensions and
scgi.map-extensions, similar to fastcgi.map-extensions.
mod_fastcgi behavior change (affects only mod_status):
- statistics tags have been renamed from "fastcgi.*" to "gw.*"
"fastcgi.backend.*" -> "gw.backend.*"
"fastcgi.active-requests" -> "gw.active-requests"
("fastcgi.requests" remains "fastcgi.requests")
("proxy.requests" is new)
("scgi.requests" is new)
mod_scgi behavior change (likely minor):
- removed scgi_proclist_sort_down() and scgi_proclist_sort_up().
procs now chosen based on load as measured by num socket connnections
Note:
modules using gw_backend.[ch] are currently still independent modules.
If it had been written as a single module with fastcgi, scgi, proxy
implementations, then there would have been a chance of breaking some
existing user configurations where module ordering made a difference
for which module handled a given request, though for most people, this
would have made no difference.
Details about mod_fastcgi code transformations:
unsigned int debug -> int debug
fastcgi_env member removed from plugin_config
renamed "fcgi" and "fastcgi" to "gw", and "FCGI" to "GW"
reorganize routines for high-level and lower-level interfaces
some lower-level internal interfaces changed to use host,proc,debug
args rather than knowing about higher-level (app) hctx and plugin_data
tabs->spaces and reformatting
2017-07-14 05:29:18 +00:00
connection * con = hctx - > remote_conn ;
2016-06-10 04:04:10 +00:00
chunkqueue * req_cq = con - > request_content_queue ;
off_t offset , weWant ;
const off_t req_cqlen = req_cq - > bytes_in - req_cq - > bytes_out ;
[core] shared code for socket backends
common codebase for socket backends, based off mod_fastcgi with
some features added for mod_proxy
(mostly intended to reduce code duplication and enhance code isolation)
mod_fastcgi and mod_scgi can now use fastcgi.balance and scgi.balance
for similar behavior as proxy.balance, but the balancing is per-host
and not per-proc. proxy.balance is also per-host and not per-proc.
mod_proxy and mod_scgi can now use proxy.map-extensions and
scgi.map-extensions, similar to fastcgi.map-extensions.
mod_fastcgi behavior change (affects only mod_status):
- statistics tags have been renamed from "fastcgi.*" to "gw.*"
"fastcgi.backend.*" -> "gw.backend.*"
"fastcgi.active-requests" -> "gw.active-requests"
("fastcgi.requests" remains "fastcgi.requests")
("proxy.requests" is new)
("scgi.requests" is new)
mod_scgi behavior change (likely minor):
- removed scgi_proclist_sort_down() and scgi_proclist_sort_up().
procs now chosen based on load as measured by num socket connnections
Note:
modules using gw_backend.[ch] are currently still independent modules.
If it had been written as a single module with fastcgi, scgi, proxy
implementations, then there would have been a chance of breaking some
existing user configurations where module ordering made a difference
for which module handled a given request, though for most people, this
would have made no difference.
Details about mod_fastcgi code transformations:
unsigned int debug -> int debug
fastcgi_env member removed from plugin_config
renamed "fcgi" and "fastcgi" to "gw", and "FCGI" to "GW"
reorganize routines for high-level and lower-level interfaces
some lower-level internal interfaces changed to use host,proc,debug
args rather than knowing about higher-level (app) hctx and plugin_data
tabs->spaces and reformatting
2017-07-14 05:29:18 +00:00
int request_id = hctx - > request_id ;
2016-06-10 04:04:10 +00:00
/* something to send ? */
for ( offset = 0 ; offset ! = req_cqlen ; offset + = weWant ) {
weWant = req_cqlen - offset > FCGI_MAX_LENGTH ? FCGI_MAX_LENGTH : req_cqlen - offset ;
/* we announce toWrite octets
* now take all request_content chunks available
* */
fcgi_header ( & ( header ) , FCGI_STDIN , request_id , weWant , 0 ) ;
chunkqueue_append_mem ( hctx - > wb , ( const char * ) & header , sizeof ( header ) ) ;
2017-05-07 21:04:01 +00:00
if ( - 1 ! = hctx - > wb_reqlen ) {
if ( hctx - > wb_reqlen > = 0 ) {
hctx - > wb_reqlen + = sizeof ( header ) ;
} else {
hctx - > wb_reqlen - = sizeof ( header ) ;
}
}
2016-06-10 04:04:10 +00:00
2016-09-19 05:27:11 +00:00
if ( hctx - > conf . debug > 10 ) {
2016-06-10 04:04:10 +00:00
log_error_write ( srv , __FILE__ , __LINE__ , " soso " , " tosend: " , offset , " / " , req_cqlen ) ;
}
chunkqueue_steal ( hctx - > wb , req_cq , weWant ) ;
/*(hctx->wb_reqlen already includes content_length)*/
}
if ( hctx - > wb - > bytes_in = = hctx - > wb_reqlen ) {
/* terminate STDIN */
2017-05-07 21:04:01 +00:00
/* (future: must defer ending FCGI_STDIN
* if might later upgrade protocols
* and then have more data to send ) */
2016-06-10 04:04:10 +00:00
fcgi_header ( & ( header ) , FCGI_STDIN , request_id , 0 , 0 ) ;
chunkqueue_append_mem ( hctx - > wb , ( const char * ) & header , sizeof ( header ) ) ;
hctx - > wb_reqlen + = ( int ) sizeof ( header ) ;
}
[core] shared code for socket backends
common codebase for socket backends, based off mod_fastcgi with
some features added for mod_proxy
(mostly intended to reduce code duplication and enhance code isolation)
mod_fastcgi and mod_scgi can now use fastcgi.balance and scgi.balance
for similar behavior as proxy.balance, but the balancing is per-host
and not per-proc. proxy.balance is also per-host and not per-proc.
mod_proxy and mod_scgi can now use proxy.map-extensions and
scgi.map-extensions, similar to fastcgi.map-extensions.
mod_fastcgi behavior change (affects only mod_status):
- statistics tags have been renamed from "fastcgi.*" to "gw.*"
"fastcgi.backend.*" -> "gw.backend.*"
"fastcgi.active-requests" -> "gw.active-requests"
("fastcgi.requests" remains "fastcgi.requests")
("proxy.requests" is new)
("scgi.requests" is new)
mod_scgi behavior change (likely minor):
- removed scgi_proclist_sort_down() and scgi_proclist_sort_up().
procs now chosen based on load as measured by num socket connnections
Note:
modules using gw_backend.[ch] are currently still independent modules.
If it had been written as a single module with fastcgi, scgi, proxy
implementations, then there would have been a chance of breaking some
existing user configurations where module ordering made a difference
for which module handled a given request, though for most people, this
would have made no difference.
Details about mod_fastcgi code transformations:
unsigned int debug -> int debug
fastcgi_env member removed from plugin_config
renamed "fcgi" and "fastcgi" to "gw", and "FCGI" to "GW"
reorganize routines for high-level and lower-level interfaces
some lower-level internal interfaces changed to use host,proc,debug
args rather than knowing about higher-level (app) hctx and plugin_data
tabs->spaces and reformatting
2017-07-14 05:29:18 +00:00
return HANDLER_GO_ON ;
2016-06-10 04:04:10 +00:00
}
[core] shared code for socket backends
common codebase for socket backends, based off mod_fastcgi with
some features added for mod_proxy
(mostly intended to reduce code duplication and enhance code isolation)
mod_fastcgi and mod_scgi can now use fastcgi.balance and scgi.balance
for similar behavior as proxy.balance, but the balancing is per-host
and not per-proc. proxy.balance is also per-host and not per-proc.
mod_proxy and mod_scgi can now use proxy.map-extensions and
scgi.map-extensions, similar to fastcgi.map-extensions.
mod_fastcgi behavior change (affects only mod_status):
- statistics tags have been renamed from "fastcgi.*" to "gw.*"
"fastcgi.backend.*" -> "gw.backend.*"
"fastcgi.active-requests" -> "gw.active-requests"
("fastcgi.requests" remains "fastcgi.requests")
("proxy.requests" is new)
("scgi.requests" is new)
mod_scgi behavior change (likely minor):
- removed scgi_proclist_sort_down() and scgi_proclist_sort_up().
procs now chosen based on load as measured by num socket connnections
Note:
modules using gw_backend.[ch] are currently still independent modules.
If it had been written as a single module with fastcgi, scgi, proxy
implementations, then there would have been a chance of breaking some
existing user configurations where module ordering made a difference
for which module handled a given request, though for most people, this
would have made no difference.
Details about mod_fastcgi code transformations:
unsigned int debug -> int debug
fastcgi_env member removed from plugin_config
renamed "fcgi" and "fastcgi" to "gw", and "FCGI" to "GW"
reorganize routines for high-level and lower-level interfaces
some lower-level internal interfaces changed to use host,proc,debug
args rather than knowing about higher-level (app) hctx and plugin_data
tabs->spaces and reformatting
2017-07-14 05:29:18 +00:00
static handler_t fcgi_create_env ( server * srv , handler_ctx * hctx ) {
2005-02-20 14:27:00 +00:00
FCGI_BeginRequestRecord beginRecord ;
FCGI_Header header ;
2017-06-30 03:50:59 +00:00
int request_id ;
2006-10-04 13:26:23 +00:00
2017-07-04 17:27:06 +00:00
buffer * fcgi_env = buffer_init ( ) ;
[core] shared code for socket backends
common codebase for socket backends, based off mod_fastcgi with
some features added for mod_proxy
(mostly intended to reduce code duplication and enhance code isolation)
mod_fastcgi and mod_scgi can now use fastcgi.balance and scgi.balance
for similar behavior as proxy.balance, but the balancing is per-host
and not per-proc. proxy.balance is also per-host and not per-proc.
mod_proxy and mod_scgi can now use proxy.map-extensions and
scgi.map-extensions, similar to fastcgi.map-extensions.
mod_fastcgi behavior change (affects only mod_status):
- statistics tags have been renamed from "fastcgi.*" to "gw.*"
"fastcgi.backend.*" -> "gw.backend.*"
"fastcgi.active-requests" -> "gw.active-requests"
("fastcgi.requests" remains "fastcgi.requests")
("proxy.requests" is new)
("scgi.requests" is new)
mod_scgi behavior change (likely minor):
- removed scgi_proclist_sort_down() and scgi_proclist_sort_up().
procs now chosen based on load as measured by num socket connnections
Note:
modules using gw_backend.[ch] are currently still independent modules.
If it had been written as a single module with fastcgi, scgi, proxy
implementations, then there would have been a chance of breaking some
existing user configurations where module ordering made a difference
for which module handled a given request, though for most people, this
would have made no difference.
Details about mod_fastcgi code transformations:
unsigned int debug -> int debug
fastcgi_env member removed from plugin_config
renamed "fcgi" and "fastcgi" to "gw", and "FCGI" to "GW"
reorganize routines for high-level and lower-level interfaces
some lower-level internal interfaces changed to use host,proc,debug
args rather than knowing about higher-level (app) hctx and plugin_data
tabs->spaces and reformatting
2017-07-14 05:29:18 +00:00
gw_host * host = hctx - > host ;
2005-02-20 14:27:00 +00:00
connection * con = hctx - > remote_conn ;
2006-10-04 13:26:23 +00:00
consistent, shared code to create CGI env
consolidated from CGI, FastCGI, SCGI, SSI
Note: due to prior inconsistencies between the code in mod_cgi,
mod_fastcgi, mod_scgi, and mod_ssi, there are some minor behavior
changes.
CONTENT_LENGTH is now always set, even if 0
(though CONTENT_LENGTH is never set for FASTCGI_AUTHORIZER)
PATH_INFO is created only if present, not if empty.
(mod_fastcgi and mod_ssi previously set PATH_INFO="" (blank value))
PATH_TRANSLATED is now set if PATH_INFO is present
(previously missing from mod_cgi and mod_ssi)
mod_ssi now sets DOCUMENT_ROOT to con->physical.basedir, like others
(previously, mod_ssi set DOCUMENT_ROOT to con->physical.doc_root,
which matched con->physical.basedir unless mod_alias changed basedir)
mod_ssi now sets REQUEST_URI to con->request.orig_uri, like others
(previously, mod_ssi set REQUEST_URI to con->request.uri, which
matched con->request.orig_uri except after redirects, error docs)
2016-10-10 17:37:36 +00:00
http_cgi_opts opts = {
[core] shared code for socket backends
common codebase for socket backends, based off mod_fastcgi with
some features added for mod_proxy
(mostly intended to reduce code duplication and enhance code isolation)
mod_fastcgi and mod_scgi can now use fastcgi.balance and scgi.balance
for similar behavior as proxy.balance, but the balancing is per-host
and not per-proc. proxy.balance is also per-host and not per-proc.
mod_proxy and mod_scgi can now use proxy.map-extensions and
scgi.map-extensions, similar to fastcgi.map-extensions.
mod_fastcgi behavior change (affects only mod_status):
- statistics tags have been renamed from "fastcgi.*" to "gw.*"
"fastcgi.backend.*" -> "gw.backend.*"
"fastcgi.active-requests" -> "gw.active-requests"
("fastcgi.requests" remains "fastcgi.requests")
("proxy.requests" is new)
("scgi.requests" is new)
mod_scgi behavior change (likely minor):
- removed scgi_proclist_sort_down() and scgi_proclist_sort_up().
procs now chosen based on load as measured by num socket connnections
Note:
modules using gw_backend.[ch] are currently still independent modules.
If it had been written as a single module with fastcgi, scgi, proxy
implementations, then there would have been a chance of breaking some
existing user configurations where module ordering made a difference
for which module handled a given request, though for most people, this
would have made no difference.
Details about mod_fastcgi code transformations:
unsigned int debug -> int debug
fastcgi_env member removed from plugin_config
renamed "fcgi" and "fastcgi" to "gw", and "FCGI" to "GW"
reorganize routines for high-level and lower-level interfaces
some lower-level internal interfaces changed to use host,proc,debug
args rather than knowing about higher-level (app) hctx and plugin_data
tabs->spaces and reformatting
2017-07-14 05:29:18 +00:00
( hctx - > gw_mode = = FCGI_AUTHORIZER ) ,
consistent, shared code to create CGI env
consolidated from CGI, FastCGI, SCGI, SSI
Note: due to prior inconsistencies between the code in mod_cgi,
mod_fastcgi, mod_scgi, and mod_ssi, there are some minor behavior
changes.
CONTENT_LENGTH is now always set, even if 0
(though CONTENT_LENGTH is never set for FASTCGI_AUTHORIZER)
PATH_INFO is created only if present, not if empty.
(mod_fastcgi and mod_ssi previously set PATH_INFO="" (blank value))
PATH_TRANSLATED is now set if PATH_INFO is present
(previously missing from mod_cgi and mod_ssi)
mod_ssi now sets DOCUMENT_ROOT to con->physical.basedir, like others
(previously, mod_ssi set DOCUMENT_ROOT to con->physical.doc_root,
which matched con->physical.basedir unless mod_alias changed basedir)
mod_ssi now sets REQUEST_URI to con->request.orig_uri, like others
(previously, mod_ssi set REQUEST_URI to con->request.uri, which
matched con->request.orig_uri except after redirects, error docs)
2016-10-10 17:37:36 +00:00
host - > break_scriptfilename_for_php ,
host - > docroot ,
host - > strip_request_uri
} ;
2006-10-04 13:26:23 +00:00
2005-02-20 14:27:00 +00:00
/* send FCGI_BEGIN_REQUEST */
2006-10-04 13:26:23 +00:00
2017-06-30 03:50:59 +00:00
if ( hctx - > request_id = = 0 ) {
hctx - > request_id = 1 ; /* always use id 1 as we don't use multiplexing */
} else {
log_error_write ( srv , __FILE__ , __LINE__ , " sd " ,
" fcgi-request is already in use: " , hctx - > request_id ) ;
}
request_id = hctx - > request_id ;
2005-02-20 14:27:00 +00:00
fcgi_header ( & ( beginRecord . header ) , FCGI_BEGIN_REQUEST , request_id , sizeof ( beginRecord . body ) , 0 ) ;
[core] shared code for socket backends
common codebase for socket backends, based off mod_fastcgi with
some features added for mod_proxy
(mostly intended to reduce code duplication and enhance code isolation)
mod_fastcgi and mod_scgi can now use fastcgi.balance and scgi.balance
for similar behavior as proxy.balance, but the balancing is per-host
and not per-proc. proxy.balance is also per-host and not per-proc.
mod_proxy and mod_scgi can now use proxy.map-extensions and
scgi.map-extensions, similar to fastcgi.map-extensions.
mod_fastcgi behavior change (affects only mod_status):
- statistics tags have been renamed from "fastcgi.*" to "gw.*"
"fastcgi.backend.*" -> "gw.backend.*"
"fastcgi.active-requests" -> "gw.active-requests"
("fastcgi.requests" remains "fastcgi.requests")
("proxy.requests" is new)
("scgi.requests" is new)
mod_scgi behavior change (likely minor):
- removed scgi_proclist_sort_down() and scgi_proclist_sort_up().
procs now chosen based on load as measured by num socket connnections
Note:
modules using gw_backend.[ch] are currently still independent modules.
If it had been written as a single module with fastcgi, scgi, proxy
implementations, then there would have been a chance of breaking some
existing user configurations where module ordering made a difference
for which module handled a given request, though for most people, this
would have made no difference.
Details about mod_fastcgi code transformations:
unsigned int debug -> int debug
fastcgi_env member removed from plugin_config
renamed "fcgi" and "fastcgi" to "gw", and "FCGI" to "GW"
reorganize routines for high-level and lower-level interfaces
some lower-level internal interfaces changed to use host,proc,debug
args rather than knowing about higher-level (app) hctx and plugin_data
tabs->spaces and reformatting
2017-07-14 05:29:18 +00:00
beginRecord . body . roleB0 = hctx - > gw_mode ;
2005-02-20 14:27:00 +00:00
beginRecord . body . roleB1 = 0 ;
beginRecord . body . flags = 0 ;
memset ( beginRecord . body . reserved , 0 , sizeof ( beginRecord . body . reserved ) ) ;
2005-09-26 08:56:39 +00:00
2005-02-20 14:27:00 +00:00
/* send FCGI_PARAMS */
2017-07-04 17:27:06 +00:00
buffer_string_prepare_copy ( fcgi_env , 1023 ) ;
2005-02-20 14:27:00 +00:00
2017-07-04 17:27:06 +00:00
if ( 0 ! = http_cgi_headers ( srv , con , & opts , fcgi_env_add , fcgi_env ) ) {
consistent, shared code to create CGI env
consolidated from CGI, FastCGI, SCGI, SSI
Note: due to prior inconsistencies between the code in mod_cgi,
mod_fastcgi, mod_scgi, and mod_ssi, there are some minor behavior
changes.
CONTENT_LENGTH is now always set, even if 0
(though CONTENT_LENGTH is never set for FASTCGI_AUTHORIZER)
PATH_INFO is created only if present, not if empty.
(mod_fastcgi and mod_ssi previously set PATH_INFO="" (blank value))
PATH_TRANSLATED is now set if PATH_INFO is present
(previously missing from mod_cgi and mod_ssi)
mod_ssi now sets DOCUMENT_ROOT to con->physical.basedir, like others
(previously, mod_ssi set DOCUMENT_ROOT to con->physical.doc_root,
which matched con->physical.basedir unless mod_alias changed basedir)
mod_ssi now sets REQUEST_URI to con->request.orig_uri, like others
(previously, mod_ssi set REQUEST_URI to con->request.uri, which
matched con->request.orig_uri except after redirects, error docs)
2016-10-10 17:37:36 +00:00
con - > http_status = 400 ;
2017-07-04 17:27:06 +00:00
buffer_free ( fcgi_env ) ;
[core] shared code for socket backends
common codebase for socket backends, based off mod_fastcgi with
some features added for mod_proxy
(mostly intended to reduce code duplication and enhance code isolation)
mod_fastcgi and mod_scgi can now use fastcgi.balance and scgi.balance
for similar behavior as proxy.balance, but the balancing is per-host
and not per-proc. proxy.balance is also per-host and not per-proc.
mod_proxy and mod_scgi can now use proxy.map-extensions and
scgi.map-extensions, similar to fastcgi.map-extensions.
mod_fastcgi behavior change (affects only mod_status):
- statistics tags have been renamed from "fastcgi.*" to "gw.*"
"fastcgi.backend.*" -> "gw.backend.*"
"fastcgi.active-requests" -> "gw.active-requests"
("fastcgi.requests" remains "fastcgi.requests")
("proxy.requests" is new)
("scgi.requests" is new)
mod_scgi behavior change (likely minor):
- removed scgi_proclist_sort_down() and scgi_proclist_sort_up().
procs now chosen based on load as measured by num socket connnections
Note:
modules using gw_backend.[ch] are currently still independent modules.
If it had been written as a single module with fastcgi, scgi, proxy
implementations, then there would have been a chance of breaking some
existing user configurations where module ordering made a difference
for which module handled a given request, though for most people, this
would have made no difference.
Details about mod_fastcgi code transformations:
unsigned int debug -> int debug
fastcgi_env member removed from plugin_config
renamed "fcgi" and "fastcgi" to "gw", and "FCGI" to "GW"
reorganize routines for high-level and lower-level interfaces
some lower-level internal interfaces changed to use host,proc,debug
args rather than knowing about higher-level (app) hctx and plugin_data
tabs->spaces and reformatting
2017-07-14 05:29:18 +00:00
return HANDLER_FINISHED ;
2005-02-20 14:27:00 +00:00
} else {
2015-02-08 19:10:36 +00:00
buffer * b = buffer_init ( ) ;
2006-10-04 13:26:23 +00:00
2015-02-08 19:10:36 +00:00
buffer_copy_string_len ( b , ( const char * ) & beginRecord , sizeof ( beginRecord ) ) ;
2005-09-26 08:56:39 +00:00
2017-07-04 17:27:06 +00:00
fcgi_header ( & ( header ) , FCGI_PARAMS , request_id , buffer_string_length ( fcgi_env ) , 0 ) ;
2015-02-08 19:10:36 +00:00
buffer_append_string_len ( b , ( const char * ) & header , sizeof ( header ) ) ;
2017-07-04 17:27:06 +00:00
buffer_append_string_buffer ( b , fcgi_env ) ;
buffer_free ( fcgi_env ) ;
2015-02-08 19:10:36 +00:00
fcgi_header ( & ( header ) , FCGI_PARAMS , request_id , 0 , 0 ) ;
buffer_append_string_len ( b , ( const char * ) & header , sizeof ( header ) ) ;
2016-06-10 04:04:10 +00:00
hctx - > wb_reqlen = buffer_string_length ( b ) ;
2015-02-08 19:10:36 +00:00
chunkqueue_append_buffer ( hctx - > wb , b ) ;
buffer_free ( b ) ;
}
2005-09-26 08:56:39 +00:00
2017-05-07 21:04:01 +00:00
if ( con - > request . content_length ) {
/*chunkqueue_append_chunkqueue(hctx->wb, con->request_content_queue);*/
if ( con - > request . content_length > 0 )
hctx - > wb_reqlen + = con - > request . content_length ; /* (eventual) (minimal) total request size, not necessarily including all fcgi_headers around content length yet */
else /* as-yet-unknown total request size (Transfer-Encoding: chunked)*/
hctx - > wb_reqlen = - hctx - > wb_reqlen ;
}
[core] shared code for socket backends
common codebase for socket backends, based off mod_fastcgi with
some features added for mod_proxy
(mostly intended to reduce code duplication and enhance code isolation)
mod_fastcgi and mod_scgi can now use fastcgi.balance and scgi.balance
for similar behavior as proxy.balance, but the balancing is per-host
and not per-proc. proxy.balance is also per-host and not per-proc.
mod_proxy and mod_scgi can now use proxy.map-extensions and
scgi.map-extensions, similar to fastcgi.map-extensions.
mod_fastcgi behavior change (affects only mod_status):
- statistics tags have been renamed from "fastcgi.*" to "gw.*"
"fastcgi.backend.*" -> "gw.backend.*"
"fastcgi.active-requests" -> "gw.active-requests"
("fastcgi.requests" remains "fastcgi.requests")
("proxy.requests" is new)
("scgi.requests" is new)
mod_scgi behavior change (likely minor):
- removed scgi_proclist_sort_down() and scgi_proclist_sort_up().
procs now chosen based on load as measured by num socket connnections
Note:
modules using gw_backend.[ch] are currently still independent modules.
If it had been written as a single module with fastcgi, scgi, proxy
implementations, then there would have been a chance of breaking some
existing user configurations where module ordering made a difference
for which module handled a given request, though for most people, this
would have made no difference.
Details about mod_fastcgi code transformations:
unsigned int debug -> int debug
fastcgi_env member removed from plugin_config
renamed "fcgi" and "fastcgi" to "gw", and "FCGI" to "GW"
reorganize routines for high-level and lower-level interfaces
some lower-level internal interfaces changed to use host,proc,debug
args rather than knowing about higher-level (app) hctx and plugin_data
tabs->spaces and reformatting
2017-07-14 05:29:18 +00:00
fcgi_stdin_append ( srv , hctx ) ;
2005-09-26 08:56:39 +00:00
[core] shared code for socket backends
common codebase for socket backends, based off mod_fastcgi with
some features added for mod_proxy
(mostly intended to reduce code duplication and enhance code isolation)
mod_fastcgi and mod_scgi can now use fastcgi.balance and scgi.balance
for similar behavior as proxy.balance, but the balancing is per-host
and not per-proc. proxy.balance is also per-host and not per-proc.
mod_proxy and mod_scgi can now use proxy.map-extensions and
scgi.map-extensions, similar to fastcgi.map-extensions.
mod_fastcgi behavior change (affects only mod_status):
- statistics tags have been renamed from "fastcgi.*" to "gw.*"
"fastcgi.backend.*" -> "gw.backend.*"
"fastcgi.active-requests" -> "gw.active-requests"
("fastcgi.requests" remains "fastcgi.requests")
("proxy.requests" is new)
("scgi.requests" is new)
mod_scgi behavior change (likely minor):
- removed scgi_proclist_sort_down() and scgi_proclist_sort_up().
procs now chosen based on load as measured by num socket connnections
Note:
modules using gw_backend.[ch] are currently still independent modules.
If it had been written as a single module with fastcgi, scgi, proxy
implementations, then there would have been a chance of breaking some
existing user configurations where module ordering made a difference
for which module handled a given request, though for most people, this
would have made no difference.
Details about mod_fastcgi code transformations:
unsigned int debug -> int debug
fastcgi_env member removed from plugin_config
renamed "fcgi" and "fastcgi" to "gw", and "FCGI" to "GW"
reorganize routines for high-level and lower-level interfaces
some lower-level internal interfaces changed to use host,proc,debug
args rather than knowing about higher-level (app) hctx and plugin_data
tabs->spaces and reformatting
2017-07-14 05:29:18 +00:00
status_counter_inc ( srv , CONST_STR_LEN ( " fastcgi.requests " ) ) ;
return HANDLER_GO_ON ;
2005-02-20 14:27:00 +00:00
}
2005-09-08 10:00:32 +00:00
typedef struct {
2006-10-04 13:26:23 +00:00
buffer * b ;
2016-06-10 04:04:10 +00:00
unsigned int len ;
2005-09-08 10:00:32 +00:00
int type ;
int padding ;
2016-06-10 04:04:10 +00:00
int request_id ;
2005-09-08 10:00:32 +00:00
} fastcgi_response_packet ;
static int fastcgi_get_packet ( server * srv , handler_ctx * hctx , fastcgi_response_packet * packet ) {
2015-02-08 19:10:39 +00:00
chunk * c ;
2009-11-07 18:24:04 +00:00
size_t offset ;
size_t toread ;
2005-09-08 10:00:32 +00:00
FCGI_Header * header ;
if ( ! hctx - > rb - > first ) return - 1 ;
packet - > b = buffer_init ( ) ;
packet - > len = 0 ;
packet - > type = 0 ;
packet - > padding = 0 ;
packet - > request_id = 0 ;
2009-11-07 18:24:04 +00:00
offset = 0 ; toread = 8 ;
2005-09-08 10:00:32 +00:00
/* get at least the FastCGI header */
for ( c = hctx - > rb - > first ; c ; c = c - > next ) {
2015-02-08 19:10:39 +00:00
size_t weHave = buffer_string_length ( c - > mem ) - c - > offset ;
2009-06-07 17:46:11 +00:00
2009-11-07 18:24:04 +00:00
if ( weHave > toread ) weHave = toread ;
2009-06-07 17:46:11 +00:00
2015-02-08 19:10:39 +00:00
buffer_append_string_len ( packet - > b , c - > mem - > ptr + c - > offset , weHave ) ;
2009-11-07 18:24:04 +00:00
toread - = weHave ;
offset = weHave ; /* skip offset bytes in chunk for "real" data */
2005-09-08 10:00:32 +00:00
2009-11-07 18:24:04 +00:00
if ( 0 = = toread ) break ;
2005-09-08 10:00:32 +00:00
}
2015-02-08 19:10:44 +00:00
if ( buffer_string_length ( packet - > b ) < sizeof ( FCGI_Header ) ) {
2005-09-08 10:00:32 +00:00
/* no header */
2016-09-19 05:27:11 +00:00
if ( hctx - > conf . debug ) {
2015-02-08 19:10:44 +00:00
log_error_write ( srv , __FILE__ , __LINE__ , " sdsds " , " FastCGI: header too small: " , buffer_string_length ( packet - > b ) , " bytes < " , sizeof ( FCGI_Header ) , " bytes, waiting for more data " ) ;
2009-11-07 18:24:04 +00:00
}
2014-02-14 21:06:00 +00:00
buffer_free ( packet - > b ) ;
2005-09-08 10:00:32 +00:00
return - 1 ;
}
2006-10-04 13:26:23 +00:00
/* we have at least a header, now check how much me have to fetch */
2005-09-08 10:00:32 +00:00
header = ( FCGI_Header * ) ( packet - > b - > ptr ) ;
2006-10-04 13:26:23 +00:00
2005-09-08 10:00:32 +00:00
packet - > len = ( header - > contentLengthB0 | ( header - > contentLengthB1 < < 8 ) ) + header - > paddingLength ;
packet - > request_id = ( header - > requestIdB0 | ( header - > requestIdB1 < < 8 ) ) ;
packet - > type = header - > type ;
packet - > padding = header - > paddingLength ;
/* ->b should only be the content */
2015-02-08 19:10:44 +00:00
buffer_string_set_length ( packet - > b , 0 ) ;
2005-09-08 10:00:32 +00:00
if ( packet - > len ) {
/* copy the content */
2015-02-08 19:10:44 +00:00
for ( ; c & & ( buffer_string_length ( packet - > b ) < packet - > len ) ; c = c - > next ) {
size_t weWant = packet - > len - buffer_string_length ( packet - > b ) ;
size_t weHave = buffer_string_length ( c - > mem ) - c - > offset - offset ;
2005-09-29 12:29:04 +00:00
if ( weHave > weWant ) weHave = weWant ;
2006-10-04 13:26:23 +00:00
2005-09-29 12:29:04 +00:00
buffer_append_string_len ( packet - > b , c - > mem - > ptr + c - > offset + offset , weHave ) ;
2009-11-07 18:24:04 +00:00
/* we only skipped the first bytes as they belonged to the fcgi header */
2005-09-08 10:00:32 +00:00
offset = 0 ;
}
2015-02-08 19:10:44 +00:00
if ( buffer_string_length ( packet - > b ) < packet - > len ) {
2007-05-03 22:08:59 +00:00
/* we didn't get the full packet */
2005-09-08 10:00:32 +00:00
buffer_free ( packet - > b ) ;
return - 1 ;
}
2015-02-08 19:10:44 +00:00
buffer_string_set_length ( packet - > b , buffer_string_length ( packet - > b ) - packet - > padding ) ;
2005-09-08 10:00:32 +00:00
}
2015-08-22 17:04:02 +00:00
chunkqueue_mark_written ( hctx - > rb , packet - > len + sizeof ( FCGI_Header ) ) ;
2006-10-04 13:26:23 +00:00
2005-09-08 10:00:32 +00:00
return 0 ;
}
2005-02-20 14:27:00 +00:00
2017-05-06 03:57:55 +00:00
static handler_t fcgi_recv_parse ( server * srv , connection * con , struct http_response_opts_t * opts , buffer * b , size_t n ) {
handler_ctx * hctx = ( handler_ctx * ) opts - > pdata ;
2005-02-20 14:27:00 +00:00
int fin = 0 ;
2006-10-04 13:26:23 +00:00
2017-05-06 03:57:55 +00:00
if ( 0 = = n ) {
2018-03-18 23:01:32 +00:00
if ( - 1 = = hctx - > request_id ) return HANDLER_FINISHED ; /*(flag request ended)*/
if ( ! ( fdevent_event_get_interest ( srv - > ev , hctx - > fd ) & FDEVENT_IN )
& & ! ( con - > conf . stream_response_body & FDEVENT_STREAM_RESPONSE_POLLRDHUP ) )
return HANDLER_GO_ON ;
2006-10-04 13:26:23 +00:00
log_error_write ( srv , __FILE__ , __LINE__ , " ssdsb " ,
2005-02-20 14:27:00 +00:00
" unexpected end-of-file (perhaps the fastcgi process died): " ,
2017-05-06 03:57:55 +00:00
" pid: " , hctx - > proc - > pid ,
" socket: " , hctx - > proc - > connection_name ) ;
2006-10-04 13:26:23 +00:00
2017-05-06 03:57:55 +00:00
return HANDLER_ERROR ;
2005-02-20 14:27:00 +00:00
}
2005-09-08 10:00:32 +00:00
2017-05-06 03:57:55 +00:00
chunkqueue_append_buffer ( hctx - > rb , b ) ;
2005-09-08 10:00:32 +00:00
/*
* parse the fastcgi packets and forward the content to the write - queue
*
2006-10-04 13:26:23 +00:00
*/
2005-02-20 14:27:00 +00:00
while ( fin = = 0 ) {
2005-09-08 10:00:32 +00:00
fastcgi_response_packet packet ;
/* check if we have at least one packet */
if ( 0 ! = fastcgi_get_packet ( srv , hctx , & packet ) ) {
/* no full packet */
2005-02-20 14:27:00 +00:00
break ;
}
2005-09-08 10:00:32 +00:00
switch ( packet . type ) {
2005-02-20 14:27:00 +00:00
case FCGI_STDOUT :
2005-09-08 10:00:32 +00:00
if ( packet . len = = 0 ) break ;
/* is the header already finished */
if ( 0 = = con - > file_started ) {
2017-03-18 04:10:48 +00:00
/* split header from body */
[core] shared code for socket backends
common codebase for socket backends, based off mod_fastcgi with
some features added for mod_proxy
(mostly intended to reduce code duplication and enhance code isolation)
mod_fastcgi and mod_scgi can now use fastcgi.balance and scgi.balance
for similar behavior as proxy.balance, but the balancing is per-host
and not per-proc. proxy.balance is also per-host and not per-proc.
mod_proxy and mod_scgi can now use proxy.map-extensions and
scgi.map-extensions, similar to fastcgi.map-extensions.
mod_fastcgi behavior change (affects only mod_status):
- statistics tags have been renamed from "fastcgi.*" to "gw.*"
"fastcgi.backend.*" -> "gw.backend.*"
"fastcgi.active-requests" -> "gw.active-requests"
("fastcgi.requests" remains "fastcgi.requests")
("proxy.requests" is new)
("scgi.requests" is new)
mod_scgi behavior change (likely minor):
- removed scgi_proclist_sort_down() and scgi_proclist_sort_up().
procs now chosen based on load as measured by num socket connnections
Note:
modules using gw_backend.[ch] are currently still independent modules.
If it had been written as a single module with fastcgi, scgi, proxy
implementations, then there would have been a chance of breaking some
existing user configurations where module ordering made a difference
for which module handled a given request, though for most people, this
would have made no difference.
Details about mod_fastcgi code transformations:
unsigned int debug -> int debug
fastcgi_env member removed from plugin_config
renamed "fcgi" and "fastcgi" to "gw", and "FCGI" to "GW"
reorganize routines for high-level and lower-level interfaces
some lower-level internal interfaces changed to use host,proc,debug
args rather than knowing about higher-level (app) hctx and plugin_data
tabs->spaces and reformatting
2017-07-14 05:29:18 +00:00
buffer * hdrs = ( ! hctx - > response )
2017-03-18 04:10:48 +00:00
? packet . b
[core] shared code for socket backends
common codebase for socket backends, based off mod_fastcgi with
some features added for mod_proxy
(mostly intended to reduce code duplication and enhance code isolation)
mod_fastcgi and mod_scgi can now use fastcgi.balance and scgi.balance
for similar behavior as proxy.balance, but the balancing is per-host
and not per-proc. proxy.balance is also per-host and not per-proc.
mod_proxy and mod_scgi can now use proxy.map-extensions and
scgi.map-extensions, similar to fastcgi.map-extensions.
mod_fastcgi behavior change (affects only mod_status):
- statistics tags have been renamed from "fastcgi.*" to "gw.*"
"fastcgi.backend.*" -> "gw.backend.*"
"fastcgi.active-requests" -> "gw.active-requests"
("fastcgi.requests" remains "fastcgi.requests")
("proxy.requests" is new)
("scgi.requests" is new)
mod_scgi behavior change (likely minor):
- removed scgi_proclist_sort_down() and scgi_proclist_sort_up().
procs now chosen based on load as measured by num socket connnections
Note:
modules using gw_backend.[ch] are currently still independent modules.
If it had been written as a single module with fastcgi, scgi, proxy
implementations, then there would have been a chance of breaking some
existing user configurations where module ordering made a difference
for which module handled a given request, though for most people, this
would have made no difference.
Details about mod_fastcgi code transformations:
unsigned int debug -> int debug
fastcgi_env member removed from plugin_config
renamed "fcgi" and "fastcgi" to "gw", and "FCGI" to "GW"
reorganize routines for high-level and lower-level interfaces
some lower-level internal interfaces changed to use host,proc,debug
args rather than knowing about higher-level (app) hctx and plugin_data
tabs->spaces and reformatting
2017-07-14 05:29:18 +00:00
: ( buffer_append_string_buffer ( hctx - > response , packet . b ) , hctx - > response ) ;
2017-03-18 04:10:48 +00:00
handler_t rc = http_response_parse_headers ( srv , con , & hctx - > opts , hdrs ) ;
if ( rc ! = HANDLER_GO_ON ) {
2016-06-19 23:32:46 +00:00
hctx - > send_content_body = 0 ;
fin = 1 ;
2009-10-14 17:32:38 +00:00
break ;
}
2017-03-18 04:10:48 +00:00
if ( 0 = = con - > file_started ) {
[core] shared code for socket backends
common codebase for socket backends, based off mod_fastcgi with
some features added for mod_proxy
(mostly intended to reduce code duplication and enhance code isolation)
mod_fastcgi and mod_scgi can now use fastcgi.balance and scgi.balance
for similar behavior as proxy.balance, but the balancing is per-host
and not per-proc. proxy.balance is also per-host and not per-proc.
mod_proxy and mod_scgi can now use proxy.map-extensions and
scgi.map-extensions, similar to fastcgi.map-extensions.
mod_fastcgi behavior change (affects only mod_status):
- statistics tags have been renamed from "fastcgi.*" to "gw.*"
"fastcgi.backend.*" -> "gw.backend.*"
"fastcgi.active-requests" -> "gw.active-requests"
("fastcgi.requests" remains "fastcgi.requests")
("proxy.requests" is new)
("scgi.requests" is new)
mod_scgi behavior change (likely minor):
- removed scgi_proclist_sort_down() and scgi_proclist_sort_up().
procs now chosen based on load as measured by num socket connnections
Note:
modules using gw_backend.[ch] are currently still independent modules.
If it had been written as a single module with fastcgi, scgi, proxy
implementations, then there would have been a chance of breaking some
existing user configurations where module ordering made a difference
for which module handled a given request, though for most people, this
would have made no difference.
Details about mod_fastcgi code transformations:
unsigned int debug -> int debug
fastcgi_env member removed from plugin_config
renamed "fcgi" and "fastcgi" to "gw", and "FCGI" to "GW"
reorganize routines for high-level and lower-level interfaces
some lower-level internal interfaces changed to use host,proc,debug
args rather than knowing about higher-level (app) hctx and plugin_data
tabs->spaces and reformatting
2017-07-14 05:29:18 +00:00
if ( ! hctx - > response ) {
hctx - > response = packet . b ;
2017-03-18 04:10:48 +00:00
packet . b = NULL ;
2005-09-14 13:55:06 +00:00
}
2005-02-20 14:27:00 +00:00
}
[core] shared code for socket backends
common codebase for socket backends, based off mod_fastcgi with
some features added for mod_proxy
(mostly intended to reduce code duplication and enhance code isolation)
mod_fastcgi and mod_scgi can now use fastcgi.balance and scgi.balance
for similar behavior as proxy.balance, but the balancing is per-host
and not per-proc. proxy.balance is also per-host and not per-proc.
mod_proxy and mod_scgi can now use proxy.map-extensions and
scgi.map-extensions, similar to fastcgi.map-extensions.
mod_fastcgi behavior change (affects only mod_status):
- statistics tags have been renamed from "fastcgi.*" to "gw.*"
"fastcgi.backend.*" -> "gw.backend.*"
"fastcgi.active-requests" -> "gw.active-requests"
("fastcgi.requests" remains "fastcgi.requests")
("proxy.requests" is new)
("scgi.requests" is new)
mod_scgi behavior change (likely minor):
- removed scgi_proclist_sort_down() and scgi_proclist_sort_up().
procs now chosen based on load as measured by num socket connnections
Note:
modules using gw_backend.[ch] are currently still independent modules.
If it had been written as a single module with fastcgi, scgi, proxy
implementations, then there would have been a chance of breaking some
existing user configurations where module ordering made a difference
for which module handled a given request, though for most people, this
would have made no difference.
Details about mod_fastcgi code transformations:
unsigned int debug -> int debug
fastcgi_env member removed from plugin_config
renamed "fcgi" and "fastcgi" to "gw", and "FCGI" to "GW"
reorganize routines for high-level and lower-level interfaces
some lower-level internal interfaces changed to use host,proc,debug
args rather than knowing about higher-level (app) hctx and plugin_data
tabs->spaces and reformatting
2017-07-14 05:29:18 +00:00
else if ( hctx - > gw_mode = = GW_AUTHORIZER & &
2017-03-18 04:10:48 +00:00
( con - > http_status = = 0 | | con - > http_status = = 200 ) ) {
/* authorizer approved request; ignore the content here */
hctx - > send_content_body = 0 ;
}
} else if ( hctx - > send_content_body & & ! buffer_string_is_empty ( packet . b ) ) {
2016-05-25 20:45:09 +00:00
if ( 0 ! = http_chunk_append_buffer ( srv , con , packet . b ) ) {
/* error writing to tempfile;
* truncate response or send 500 if nothing sent yet */
fin = 1 ;
[core] option to stream response body to client (fixes #949, #760, #1283, #1387)
Set server.stream-response-body = 1 or server.stream-response-body = 2
to have lighttpd stream response body to client as it arrives from the
backend (CGI, FastCGI, SCGI, proxy).
default: buffer entire response body before sending response to client.
(This preserves existing behavior for now, but may in the future be
changed to stream response to client, which is the behavior more
commonly expected.)
x-ref:
"fastcgi, cgi, flush, php5 problem."
https://redmine.lighttpd.net/issues/949
"Random crashing on FreeBSD 6.1"
https://redmine.lighttpd.net/issues/760
"Memory usage increases when proxy+ssl+large file"
https://redmine.lighttpd.net/issues/1283
"lighttpd+fastcgi memory problem"
https://redmine.lighttpd.net/issues/1387
2016-06-11 15:04:01 +00:00
break ;
}
2005-02-20 14:27:00 +00:00
}
break ;
case FCGI_STDERR :
2007-02-05 13:14:21 +00:00
if ( packet . len = = 0 ) break ;
2013-03-25 17:22:32 +00:00
log_error_write_multiline_buffer ( srv , __FILE__ , __LINE__ , packet . b , " s " ,
" FastCGI-stderr: " ) ;
2006-10-04 13:26:23 +00:00
2005-02-20 14:27:00 +00:00
break ;
case FCGI_END_REQUEST :
2018-03-18 23:01:32 +00:00
hctx - > request_id = - 1 ; /*(flag request ended)*/
2005-02-20 14:27:00 +00:00
fin = 1 ;
break ;
default :
2006-10-04 13:26:23 +00:00
log_error_write ( srv , __FILE__ , __LINE__ , " sd " ,
2005-09-08 10:00:32 +00:00
" FastCGI: header.type not handled: " , packet . type ) ;
2005-02-20 14:27:00 +00:00
break ;
}
2005-09-08 10:00:32 +00:00
buffer_free ( packet . b ) ;
2005-02-20 14:27:00 +00:00
}
2006-10-04 13:26:23 +00:00
2017-05-06 03:57:55 +00:00
return 0 = = fin ? HANDLER_GO_ON : HANDLER_FINISHED ;
2005-02-20 14:27:00 +00:00
}
# define PATCH(x) \
p - > conf . x = s - > x ;
2005-08-08 10:27:07 +00:00
static int fcgi_patch_connection ( server * srv , connection * con , plugin_data * p ) {
2005-02-20 14:27:00 +00:00
size_t i , j ;
2005-08-08 10:27:07 +00:00
plugin_config * s = p - > config_storage [ 0 ] ;
2006-10-04 13:26:23 +00:00
2005-08-08 10:27:07 +00:00
PATCH ( exts ) ;
2016-09-19 23:58:51 +00:00
PATCH ( exts_auth ) ;
PATCH ( exts_resp ) ;
2005-08-08 10:27:07 +00:00
PATCH ( debug ) ;
2018-04-09 13:47:40 +00:00
PATCH ( balance ) ;
2006-01-31 12:05:03 +00:00
PATCH ( ext_mapping ) ;
2006-10-04 13:26:23 +00:00
2005-02-20 14:27:00 +00:00
/* skip the first, the global context */
for ( i = 1 ; i < srv - > config_context - > used ; i + + ) {
data_config * dc = ( data_config * ) srv - > config_context - > data [ i ] ;
2005-08-08 10:27:07 +00:00
s = p - > config_storage [ i ] ;
2006-10-04 13:26:23 +00:00
2005-02-20 14:27:00 +00:00
/* condition didn't match */
if ( ! config_check_cond ( srv , con , dc ) ) continue ;
2006-10-04 13:26:23 +00:00
2005-02-20 14:27:00 +00:00
/* merge config */
for ( j = 0 ; j < dc - > value - > used ; j + + ) {
data_unset * du = dc - > value - > data [ j ] ;
2006-10-04 13:26:23 +00:00
2005-02-20 14:27:00 +00:00
if ( buffer_is_equal_string ( du - > key , CONST_STR_LEN ( " fastcgi.server " ) ) ) {
PATCH ( exts ) ;
2016-09-19 23:58:51 +00:00
PATCH ( exts_auth ) ;
PATCH ( exts_resp ) ;
2005-02-20 14:27:00 +00:00
} else if ( buffer_is_equal_string ( du - > key , CONST_STR_LEN ( " fastcgi.debug " ) ) ) {
PATCH ( debug ) ;
2018-04-09 13:47:40 +00:00
} else if ( buffer_is_equal_string ( du - > key , CONST_STR_LEN ( " fastcgi.balance " ) ) ) {
PATCH ( balance ) ;
2006-01-31 12:05:03 +00:00
} else if ( buffer_is_equal_string ( du - > key , CONST_STR_LEN ( " fastcgi.map-extensions " ) ) ) {
PATCH ( ext_mapping ) ;
2005-02-20 14:27:00 +00:00
}
}
}
2006-10-04 13:26:23 +00:00
2005-02-20 14:27:00 +00:00
return 0 ;
}
# undef PATCH
static handler_t fcgi_check_extension ( server * srv , connection * con , void * p_d , int uri_path_handler ) {
plugin_data * p = p_d ;
[core] shared code for socket backends
common codebase for socket backends, based off mod_fastcgi with
some features added for mod_proxy
(mostly intended to reduce code duplication and enhance code isolation)
mod_fastcgi and mod_scgi can now use fastcgi.balance and scgi.balance
for similar behavior as proxy.balance, but the balancing is per-host
and not per-proc. proxy.balance is also per-host and not per-proc.
mod_proxy and mod_scgi can now use proxy.map-extensions and
scgi.map-extensions, similar to fastcgi.map-extensions.
mod_fastcgi behavior change (affects only mod_status):
- statistics tags have been renamed from "fastcgi.*" to "gw.*"
"fastcgi.backend.*" -> "gw.backend.*"
"fastcgi.active-requests" -> "gw.active-requests"
("fastcgi.requests" remains "fastcgi.requests")
("proxy.requests" is new)
("scgi.requests" is new)
mod_scgi behavior change (likely minor):
- removed scgi_proclist_sort_down() and scgi_proclist_sort_up().
procs now chosen based on load as measured by num socket connnections
Note:
modules using gw_backend.[ch] are currently still independent modules.
If it had been written as a single module with fastcgi, scgi, proxy
implementations, then there would have been a chance of breaking some
existing user configurations where module ordering made a difference
for which module handled a given request, though for most people, this
would have made no difference.
Details about mod_fastcgi code transformations:
unsigned int debug -> int debug
fastcgi_env member removed from plugin_config
renamed "fcgi" and "fastcgi" to "gw", and "FCGI" to "GW"
reorganize routines for high-level and lower-level interfaces
some lower-level internal interfaces changed to use host,proc,debug
args rather than knowing about higher-level (app) hctx and plugin_data
tabs->spaces and reformatting
2017-07-14 05:29:18 +00:00
handler_t rc ;
2006-10-04 13:26:23 +00:00
2008-08-01 16:13:34 +00:00
if ( con - > mode ! = DIRECT ) return HANDLER_GO_ON ;
2005-08-08 10:27:07 +00:00
fcgi_patch_connection ( srv , con , p ) ;
2016-09-19 23:58:51 +00:00
if ( NULL = = p - > conf . exts ) return HANDLER_GO_ON ;
[core] shared code for socket backends
common codebase for socket backends, based off mod_fastcgi with
some features added for mod_proxy
(mostly intended to reduce code duplication and enhance code isolation)
mod_fastcgi and mod_scgi can now use fastcgi.balance and scgi.balance
for similar behavior as proxy.balance, but the balancing is per-host
and not per-proc. proxy.balance is also per-host and not per-proc.
mod_proxy and mod_scgi can now use proxy.map-extensions and
scgi.map-extensions, similar to fastcgi.map-extensions.
mod_fastcgi behavior change (affects only mod_status):
- statistics tags have been renamed from "fastcgi.*" to "gw.*"
"fastcgi.backend.*" -> "gw.backend.*"
"fastcgi.active-requests" -> "gw.active-requests"
("fastcgi.requests" remains "fastcgi.requests")
("proxy.requests" is new)
("scgi.requests" is new)
mod_scgi behavior change (likely minor):
- removed scgi_proclist_sort_down() and scgi_proclist_sort_up().
procs now chosen based on load as measured by num socket connnections
Note:
modules using gw_backend.[ch] are currently still independent modules.
If it had been written as a single module with fastcgi, scgi, proxy
implementations, then there would have been a chance of breaking some
existing user configurations where module ordering made a difference
for which module handled a given request, though for most people, this
would have made no difference.
Details about mod_fastcgi code transformations:
unsigned int debug -> int debug
fastcgi_env member removed from plugin_config
renamed "fcgi" and "fastcgi" to "gw", and "FCGI" to "GW"
reorganize routines for high-level and lower-level interfaces
some lower-level internal interfaces changed to use host,proc,debug
args rather than knowing about higher-level (app) hctx and plugin_data
tabs->spaces and reformatting
2017-07-14 05:29:18 +00:00
rc = gw_check_extension ( srv , con , p , uri_path_handler , 0 ) ;
if ( HANDLER_GO_ON ! = rc ) return rc ;
2006-10-04 13:26:23 +00:00
[core] shared code for socket backends
common codebase for socket backends, based off mod_fastcgi with
some features added for mod_proxy
(mostly intended to reduce code duplication and enhance code isolation)
mod_fastcgi and mod_scgi can now use fastcgi.balance and scgi.balance
for similar behavior as proxy.balance, but the balancing is per-host
and not per-proc. proxy.balance is also per-host and not per-proc.
mod_proxy and mod_scgi can now use proxy.map-extensions and
scgi.map-extensions, similar to fastcgi.map-extensions.
mod_fastcgi behavior change (affects only mod_status):
- statistics tags have been renamed from "fastcgi.*" to "gw.*"
"fastcgi.backend.*" -> "gw.backend.*"
"fastcgi.active-requests" -> "gw.active-requests"
("fastcgi.requests" remains "fastcgi.requests")
("proxy.requests" is new)
("scgi.requests" is new)
mod_scgi behavior change (likely minor):
- removed scgi_proclist_sort_down() and scgi_proclist_sort_up().
procs now chosen based on load as measured by num socket connnections
Note:
modules using gw_backend.[ch] are currently still independent modules.
If it had been written as a single module with fastcgi, scgi, proxy
implementations, then there would have been a chance of breaking some
existing user configurations where module ordering made a difference
for which module handled a given request, though for most people, this
would have made no difference.
Details about mod_fastcgi code transformations:
unsigned int debug -> int debug
fastcgi_env member removed from plugin_config
renamed "fcgi" and "fastcgi" to "gw", and "FCGI" to "GW"
reorganize routines for high-level and lower-level interfaces
some lower-level internal interfaces changed to use host,proc,debug
args rather than knowing about higher-level (app) hctx and plugin_data
tabs->spaces and reformatting
2017-07-14 05:29:18 +00:00
if ( con - > mode = = p - > id ) {
handler_ctx * hctx = con - > plugin_ctx [ p - > id ] ;
hctx - > opts . backend = BACKEND_FASTCGI ;
hctx - > opts . parse = fcgi_recv_parse ;
hctx - > opts . pdata = hctx ;