lighttpd 1.4.x https://www.lighttpd.net/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

563 lines
18 KiB

[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
4 years ago
[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
4 years ago
[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
4 years ago
[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
4 years ago
[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
4 years ago
[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
4 years ago
[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
4 years ago
[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
4 years ago
[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
4 years ago
[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
4 years ago
[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
4 years ago
[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
4 years ago
[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
4 years ago
[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
4 years ago
[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
4 years ago
[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
4 years ago
[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
4 years ago
[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
4 years ago
  1. #include "first.h"
  2. #include <sys/types.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include "gw_backend.h"
  6. typedef gw_plugin_config plugin_config;
  7. typedef gw_plugin_data plugin_data;
  8. typedef gw_handler_ctx handler_ctx;
  9. #include "base.h"
  10. #include "buffer.h"
  11. #include "fdevent.h"
  12. #include "http_chunk.h"
  13. #include "log.h"
  14. #include "status_counter.h"
  15. #include "compat/fastcgi.h"
  16. #if GW_RESPONDER != FCGI_RESPONDER
  17. #error "mismatched defines: (GW_RESPONDER != FCGI_RESPONDER)"
  18. #endif
  19. #if GW_AUTHORIZER != FCGI_AUTHORIZER
  20. #error "mismatched defines: (GW_AUTHORIZER != FCGI_AUTHORIZER)"
  21. #endif
  22. #if GW_FILTER != FCGI_FILTER
  23. #error "mismatched defines: (GW_FILTER != FCGI_FILTER)"
  24. #endif
  25. static void mod_fastcgi_merge_config_cpv(plugin_config * const pconf, const config_plugin_value_t * const cpv) {
  26. switch (cpv->k_id) { /* index into static config_plugin_keys_t cpk[] */
  27. case 0: /* fastcgi.server */
  28. if (cpv->vtype == T_CONFIG_LOCAL) {
  29. gw_plugin_config * const gw = cpv->v.v;
  30. pconf->exts = gw->exts;
  31. pconf->exts_auth = gw->exts_auth;
  32. pconf->exts_resp = gw->exts_resp;
  33. }
  34. break;
  35. case 1: /* fastcgi.balance */
  36. /*if (cpv->vtype == T_CONFIG_LOCAL)*//*always true here for this param*/
  37. pconf->balance = (int)cpv->v.u;
  38. break;
  39. case 2: /* fastcgi.debug */
  40. pconf->debug = (int)cpv->v.u;
  41. break;
  42. case 3: /* fastcgi.map-extensions */
  43. pconf->ext_mapping = cpv->v.a;
  44. break;
  45. default:/* should not happen */
  46. return;
  47. }
  48. }
  49. static void mod_fastcgi_merge_config(plugin_config * const pconf, const config_plugin_value_t *cpv) {
  50. do {
  51. mod_fastcgi_merge_config_cpv(pconf, cpv);
  52. } while ((++cpv)->k_id != -1);
  53. }
  54. static void mod_fastcgi_patch_config(request_st * const r, plugin_data * const p) {
  55. memcpy(&p->conf, &p->defaults, sizeof(plugin_config));
  56. for (int i = 1, used = p->nconfig; i < used; ++i) {
  57. if (config_check_cond(r, (uint32_t)p->cvlist[i].k_id))
  58. mod_fastcgi_merge_config(&p->conf,p->cvlist + p->cvlist[i].v.u2[0]);
  59. }
  60. }
  61. SETDEFAULTS_FUNC(mod_fastcgi_set_defaults) {
  62. static const config_plugin_keys_t cpk[] = {
  63. { CONST_STR_LEN("fastcgi.server"),
  64. T_CONFIG_ARRAY_KVARRAY,
  65. T_CONFIG_SCOPE_CONNECTION }
  66. ,{ CONST_STR_LEN("fastcgi.balance"),
  67. T_CONFIG_STRING,
  68. T_CONFIG_SCOPE_CONNECTION }
  69. ,{ CONST_STR_LEN("fastcgi.debug"),
  70. T_CONFIG_INT,
  71. T_CONFIG_SCOPE_CONNECTION }
  72. ,{ CONST_STR_LEN("fastcgi.map-extensions"),
  73. T_CONFIG_ARRAY_KVSTRING,
  74. T_CONFIG_SCOPE_CONNECTION }
  75. ,{ NULL, 0,
  76. T_CONFIG_UNSET,
  77. T_CONFIG_SCOPE_UNSET }
  78. };
  79. plugin_data * const p = p_d;
  80. if (!config_plugin_values_init(srv, p, cpk, "mod_fastcgi"))
  81. return HANDLER_ERROR;
  82. /* process and validate config directives
  83. * (init i to 0 if global context; to 1 to skip empty global context) */
  84. for (int i = !p->cvlist[0].v.u2[1]; i < p->nconfig; ++i) {
  85. config_plugin_value_t *cpv = p->cvlist + p->cvlist[i].v.u2[0];
  86. for (; -1 != cpv->k_id; ++cpv) {
  87. switch (cpv->k_id) {
  88. case 0:{/* fastcgi.server */
  89. gw_plugin_config *gw = calloc(1, sizeof(gw_plugin_config));
  90. force_assert(gw);
  91. if (!gw_set_defaults_backend(srv, p, cpv->v.a, gw, 0,
  92. cpk[cpv->k_id].k)) {
  93. gw_plugin_config_free(gw);
  94. return HANDLER_ERROR;
  95. }
  96. cpv->v.v = gw;
  97. cpv->vtype = T_CONFIG_LOCAL;
  98. break;
  99. }
  100. case 1: /* fastcgi.balance */
  101. cpv->v.u = (unsigned int)gw_get_defaults_balance(srv, cpv->v.b);
  102. break;
  103. case 2: /* fastcgi.debug */
  104. case 3: /* fastcgi.map-extensions */
  105. break;
  106. default:/* should not happen */
  107. break;
  108. }
  109. }
  110. }
  111. /* default is 0 */
  112. /*p->defaults.balance = (unsigned int)gw_get_defaults_balance(srv, NULL);*/
  113. /* initialize p->defaults from global config context */
  114. if (p->nconfig > 0 && p->cvlist->v.u2[1]) {
  115. const config_plugin_value_t *cpv = p->cvlist + p->cvlist->v.u2[0];
  116. if (-1 != cpv->k_id)
  117. mod_fastcgi_merge_config(&p->defaults, cpv);
  118. }
  119. return HANDLER_GO_ON;
  120. }
  121. static int fcgi_env_add(void *venv, const char *key, size_t key_len, const char *val, size_t val_len) {
  122. buffer *env = venv;
  123. size_t len;
  124. char len_enc[8];
  125. size_t len_enc_len = 0;
  126. char *dst;
  127. if (!key || (!val && val_len)) return -1;
  128. len = key_len + val_len;
  129. len += key_len > 127 ? 4 : 1;
  130. len += val_len > 127 ? 4 : 1;
  131. if (buffer_string_length(env) + len >= FCGI_MAX_LENGTH + sizeof(FCGI_BeginRequestRecord) + sizeof(FCGI_Header)) {
  132. /**
  133. * we can't append more headers, ignore it
  134. */
  135. return -1;
  136. }
  137. /**
  138. * field length can be 31bit max
  139. *
  140. * HINT: this can't happen as FCGI_MAX_LENGTH is only 16bit
  141. */
  142. force_assert(key_len < 0x7fffffffu);
  143. force_assert(val_len < 0x7fffffffu);
  144. if (buffer_string_space(env) < len) {
  145. size_t extend = env->size * 2 - buffer_string_length(env);
  146. extend = extend > len ? extend : len + 4095;
  147. buffer_string_prepare_append(env, extend);
  148. }
  149. if (key_len > 127) {
  150. len_enc[len_enc_len++] = ((key_len >> 24) & 0xff) | 0x80;
  151. len_enc[len_enc_len++] = (key_len >> 16) & 0xff;
  152. len_enc[len_enc_len++] = (key_len >> 8) & 0xff;
  153. len_enc[len_enc_len++] = (key_len >> 0) & 0xff;
  154. } else {
  155. len_enc[len_enc_len++] = (key_len >> 0) & 0xff;
  156. }
  157. if (val_len > 127) {
  158. len_enc[len_enc_len++] = ((val_len >> 24) & 0xff) | 0x80;
  159. len_enc[len_enc_len++] = (val_len >> 16) & 0xff;
  160. len_enc[len_enc_len++] = (val_len >> 8) & 0xff;
  161. len_enc[len_enc_len++] = (val_len >> 0) & 0xff;
  162. } else {
  163. len_enc[len_enc_len++] = (val_len >> 0) & 0xff;
  164. }
  165. dst = buffer_string_prepare_append(env, len);
  166. memcpy(dst, len_enc, len_enc_len);
  167. memcpy(dst + len_enc_len, key, key_len);
  168. memcpy(dst + len_enc_len + key_len, val, val_len);
  169. buffer_commit(env, len);
  170. return 0;
  171. }
  172. static void fcgi_header(FCGI_Header * header, unsigned char type, int request_id, int contentLength, unsigned char paddingLength) {
  173. force_assert(contentLength <= FCGI_MAX_LENGTH);
  174. header->version = FCGI_VERSION_1;
  175. header->type = type;
  176. header->requestIdB0 = request_id & 0xff;
  177. header->requestIdB1 = (request_id >> 8) & 0xff;
  178. header->contentLengthB0 = contentLength & 0xff;
  179. header->contentLengthB1 = (contentLength >> 8) & 0xff;
  180. header->paddingLength = paddingLength;
  181. header->reserved = 0;
  182. }
  183. static handler_t fcgi_stdin_append(handler_ctx *hctx) {
  184. FCGI_Header header;
  185. chunkqueue * const req_cq = &hctx->r->reqbody_queue;
  186. off_t offset, weWant;
  187. off_t req_cqlen = chunkqueue_length(req_cq);
  188. int request_id = hctx->request_id;
  189. if (req_cqlen > MAX_WRITE_LIMIT) req_cqlen = MAX_WRITE_LIMIT;
  190. /* something to send ? */
  191. for (offset = 0; offset != req_cqlen; offset += weWant) {
  192. weWant = req_cqlen - offset > FCGI_MAX_LENGTH ? FCGI_MAX_LENGTH : req_cqlen - offset;
  193. if (-1 != hctx->wb_reqlen) {
  194. if (hctx->wb_reqlen >= 0) {
  195. hctx->wb_reqlen += sizeof(header);
  196. } else {
  197. hctx->wb_reqlen -= sizeof(header);
  198. }
  199. }
  200. fcgi_header(&(header), FCGI_STDIN, request_id, weWant, 0);
  201. (chunkqueue_is_empty(&hctx->wb) || hctx->wb.first->type == MEM_CHUNK) /* else FILE_CHUNK for temp file */
  202. ? chunkqueue_append_mem(&hctx->wb, (const char *)&header, sizeof(header))
  203. : chunkqueue_append_mem_min(&hctx->wb, (const char *)&header, sizeof(header));
  204. chunkqueue_steal(&hctx->wb, req_cq, weWant);
  205. /*(hctx->wb_reqlen already includes reqbody_length)*/
  206. }
  207. if (hctx->wb.bytes_in == hctx->wb_reqlen) {
  208. /* terminate STDIN */
  209. /* (future: must defer ending FCGI_STDIN
  210. * if might later upgrade protocols
  211. * and then have more data to send) */
  212. fcgi_header(&(header), FCGI_STDIN, request_id, 0, 0);
  213. chunkqueue_append_mem(&hctx->wb, (const char *)&header, sizeof(header));
  214. hctx->wb_reqlen += (int)sizeof(header);
  215. }
  216. return HANDLER_GO_ON;
  217. }
  218. static handler_t fcgi_create_env(handler_ctx *hctx) {
  219. FCGI_BeginRequestRecord beginRecord;
  220. FCGI_Header header;
  221. int request_id;
  222. gw_host *host = hctx->host;
  223. request_st * const r = hctx->r;
  224. http_cgi_opts opts = {
  225. (hctx->gw_mode == FCGI_AUTHORIZER),
  226. host->break_scriptfilename_for_php,
  227. host->docroot,
  228. host->strip_request_uri
  229. };
  230. size_t rsz = (size_t)(r->read_queue.bytes_out - hctx->wb.bytes_in);
  231. if (rsz >= 65536) rsz = r->rqst_header_len;
  232. buffer * const b = chunkqueue_prepend_buffer_open_sz(&hctx->wb, rsz);
  233. /* send FCGI_BEGIN_REQUEST */
  234. if (hctx->request_id == 0) {
  235. hctx->request_id = 1; /* always use id 1 as we don't use multiplexing */
  236. } else {
  237. log_error(r->conf.errh, __FILE__, __LINE__,
  238. "fcgi-request is already in use: %d", hctx->request_id);
  239. }
  240. request_id = hctx->request_id;
  241. fcgi_header(&(beginRecord.header), FCGI_BEGIN_REQUEST, request_id, sizeof(beginRecord.body), 0);
  242. beginRecord.body.roleB0 = hctx->gw_mode;
  243. beginRecord.body.roleB1 = 0;
  244. beginRecord.body.flags = 0;
  245. memset(beginRecord.body.reserved, 0, sizeof(beginRecord.body.reserved));
  246. buffer_copy_string_len(b, (const char *)&beginRecord, sizeof(beginRecord));
  247. fcgi_header(&header, FCGI_PARAMS, request_id, 0, 0); /*(set aside space to fill in later)*/
  248. buffer_append_string_len(b, (const char *)&header, sizeof(header));
  249. /* send FCGI_PARAMS */
  250. if (0 != http_cgi_headers(r, &opts, fcgi_env_add, b)) {
  251. r->http_status = 400;
  252. r->handler_module = NULL;
  253. buffer_clear(b);
  254. chunkqueue_remove_finished_chunks(&hctx->wb);
  255. return HANDLER_FINISHED;
  256. } else {
  257. fcgi_header(&(header), FCGI_PARAMS, request_id,
  258. buffer_string_length(b) - sizeof(FCGI_BeginRequestRecord) - sizeof(FCGI_Header), 0);
  259. memcpy(b->ptr+sizeof(FCGI_BeginRequestRecord), (const char *)&header, sizeof(header));
  260. fcgi_header(&(header), FCGI_PARAMS, request_id, 0, 0);
  261. buffer_append_string_len(b, (const char *)&header, sizeof(header));
  262. hctx->wb_reqlen = buffer_string_length(b);
  263. chunkqueue_prepend_buffer_commit(&hctx->wb);
  264. }
  265. if (r->reqbody_length) {
  266. /*chunkqueue_append_chunkqueue(&hctx->wb, &r->reqbody_queue);*/
  267. if (r->reqbody_length > 0)
  268. hctx->wb_reqlen += r->reqbody_length;/* (eventual) (minimal) total request size, not necessarily including all fcgi_headers around content length yet */
  269. else /* as-yet-unknown total request size (Transfer-Encoding: chunked)*/
  270. hctx->wb_reqlen = -hctx->wb_reqlen;
  271. }
  272. fcgi_stdin_append(hctx);
  273. status_counter_inc(CONST_STR_LEN("fastcgi.requests"));
  274. return HANDLER_GO_ON;
  275. }
  276. typedef struct {
  277. unsigned int len;
  278. int type;
  279. int padding;
  280. int request_id;
  281. } fastcgi_response_packet;
  282. static int fastcgi_get_packet(handler_ctx *hctx, fastcgi_response_packet *packet) {
  283. FCGI_Header header;
  284. off_t rblen = chunkqueue_length(hctx->rb);
  285. if (rblen < (off_t)sizeof(FCGI_Header)) {
  286. /* no header */
  287. if (hctx->conf.debug && 0 != rblen) {
  288. log_error(hctx->r->conf.errh, __FILE__, __LINE__,
  289. "FastCGI: header too small: %lld bytes < %zu bytes, "
  290. "waiting for more data", (long long)rblen, sizeof(FCGI_Header));
  291. }
  292. return -1;
  293. }
  294. char *ptr = (char *)&header;
  295. uint32_t rd = sizeof(FCGI_Header);
  296. if (chunkqueue_peek_data(hctx->rb, &ptr, &rd, hctx->r->conf.errh) < 0)
  297. return -1;
  298. if (rd != sizeof(FCGI_Header))
  299. return -1;
  300. if (ptr != (char *)&header) /* copy into aligned struct */
  301. memcpy(&header, ptr, sizeof(FCGI_Header));
  302. /* we have at least a header, now check how much we have to fetch */
  303. packet->len = (header.contentLengthB0 | (header.contentLengthB1 << 8)) + header.paddingLength;
  304. packet->request_id = (header.requestIdB0 | (header.requestIdB1 << 8));
  305. packet->type = header.type;
  306. packet->padding = header.paddingLength;
  307. if (packet->len > (unsigned int)rblen-sizeof(FCGI_Header)) {
  308. return -1; /* we didn't get the full packet */
  309. }
  310. chunkqueue_mark_written(hctx->rb, sizeof(FCGI_Header));
  311. return 0;
  312. }
  313. static void fastcgi_get_packet_body(buffer * const b, handler_ctx * const hctx, const fastcgi_response_packet * const packet) {
  314. /* copy content; hctx->rb must contain at least packet->len content */
  315. /* (read entire packet and then truncate padding, if present) */
  316. const uint32_t blen = buffer_string_length(b);
  317. if (chunkqueue_read_data(hctx->rb,
  318. buffer_string_prepare_append(b, packet->len),
  319. packet->len, hctx->r->conf.errh) < 0)
  320. return; /*(should not happen; should all be in memory)*/
  321. buffer_string_set_length(b, blen + packet->len - packet->padding);
  322. }
  323. __attribute_cold__
  324. __attribute_noinline__
  325. static int
  326. mod_fastcgi_chunk_decode_transfer_cqlen (request_st * const r, chunkqueue * const src, const unsigned int len)
  327. {
  328. if (0 == len) return 0;
  329. /* specialized for mod_fastcgi to decode chunked encoding;
  330. * FastCGI packet data is all type MEM_CHUNK
  331. * entire src cq is processed, minus packet.padding at end
  332. * (This extra work can be avoided if FastCGI backend does not send
  333. * Transfer-Encoding: chunked, which FastCGI is not supposed to do) */
  334. uint32_t remain = len, wr;
  335. for (const chunk *c = src->first; c && remain; c = c->next, remain -= wr) {
  336. /*assert(c->type == MEM_CHUNK);*/
  337. wr = buffer_string_length(c->mem) - c->offset;
  338. if (wr > remain) wr = remain;
  339. if (0 != http_chunk_decode_append_mem(r, c->mem->ptr+c->offset, wr))
  340. return -1;
  341. }
  342. chunkqueue_mark_written(src, len);
  343. return 0;
  344. }
  345. static int
  346. mod_fastcgi_transfer_cqlen (request_st * const r, chunkqueue * const src, const unsigned int len)
  347. {
  348. return (!r->resp_decode_chunked)
  349. ? http_chunk_transfer_cqlen(r, src, len)
  350. : mod_fastcgi_chunk_decode_transfer_cqlen(r, src, len);
  351. }
  352. static handler_t fcgi_recv_parse(request_st * const r, struct http_response_opts_t *opts, buffer *b, size_t n) {
  353. handler_ctx *hctx = (handler_ctx *)opts->pdata;
  354. int fin = 0;
  355. if (0 == n) {
  356. if (-1 == hctx->request_id) return HANDLER_FINISHED; /*(flag request ended)*/
  357. if (!(fdevent_fdnode_interest(hctx->fdn) & FDEVENT_IN)
  358. && !(r->conf.stream_response_body & FDEVENT_STREAM_RESPONSE_POLLRDHUP))
  359. return HANDLER_GO_ON;
  360. log_error(r->conf.errh, __FILE__, __LINE__,
  361. "unexpected end-of-file (perhaps the fastcgi process died):"
  362. "pid: %d socket: %s",
  363. hctx->proc->pid, hctx->proc->connection_name->ptr);
  364. return HANDLER_ERROR;
  365. }
  366. chunkqueue_append_buffer(hctx->rb, b);
  367. /*
  368. * parse the fastcgi packets and forward the content to the write-queue
  369. *
  370. */
  371. while (fin == 0) {
  372. fastcgi_response_packet packet;
  373. /* check if we have at least one packet */
  374. if (0 != fastcgi_get_packet(hctx, &packet)) {
  375. /* no full packet */
  376. break;
  377. }
  378. switch(packet.type) {
  379. case FCGI_STDOUT:
  380. if (packet.len == 0) break;
  381. /* is the header already finished */
  382. if (0 == r->resp_body_started) {
  383. /* split header from body */
  384. buffer *hdrs = hctx->response;
  385. if (NULL == hdrs) {
  386. hdrs = r->tmp_buf;
  387. buffer_clear(hdrs);
  388. }
  389. fastcgi_get_packet_body(hdrs, hctx, &packet);
  390. if (HANDLER_GO_ON != http_response_parse_headers(r, &hctx->opts, hdrs)) {
  391. hctx->send_content_body = 0;
  392. fin = 1;
  393. break;
  394. }
  395. if (0 == r->resp_body_started) {
  396. if (!hctx->response) {
  397. hctx->response = chunk_buffer_acquire();
  398. buffer_copy_buffer(hctx->response, hdrs);
  399. }
  400. }
  401. else if (hctx->gw_mode == GW_AUTHORIZER &&
  402. (r->http_status == 0 || r->http_status == 200)) {
  403. /* authorizer approved request; ignore the content here */
  404. hctx->send_content_body = 0;
  405. }
  406. } else if (hctx->send_content_body) {
  407. if (0 != mod_fastcgi_transfer_cqlen(r, hctx->rb, packet.len - packet.padding)) {
  408. /* error writing to tempfile;
  409. * truncate response or send 500 if nothing sent yet */
  410. fin = 1;
  411. }
  412. if (packet.padding) chunkqueue_mark_written(hctx->rb, packet.padding);
  413. } else {
  414. chunkqueue_mark_written(hctx->rb, packet.len);
  415. }
  416. break;
  417. case FCGI_STDERR:
  418. if (packet.len) {
  419. buffer * const tb = r->tmp_buf;
  420. buffer_clear(tb);
  421. fastcgi_get_packet_body(tb, hctx, &packet);
  422. log_error_multiline_buffer(r->conf.errh, __FILE__, __LINE__, tb,
  423. "FastCGI-stderr:");
  424. }
  425. break;
  426. case FCGI_END_REQUEST:
  427. hctx->request_id = -1; /*(flag request ended)*/
  428. fin = 1;
  429. break;
  430. default:
  431. log_error(r->conf.errh, __FILE__, __LINE__,
  432. "FastCGI: header.type not handled: %d", packet.type);
  433. chunkqueue_mark_written(hctx->rb, packet.len);
  434. break;
  435. }
  436. }
  437. return 0 == fin ? HANDLER_GO_ON : HANDLER_FINISHED;
  438. }
  439. static handler_t fcgi_check_extension(request_st * const r, void *p_d, int uri_path_handler) {
  440. plugin_data *p = p_d;
  441. handler_t rc;
  442. if (NULL != r->handler_module) return HANDLER_GO_ON;
  443. mod_fastcgi_patch_config(r, p);
  444. if (NULL == p->conf.exts) return HANDLER_GO_ON;
  445. rc = gw_check_extension(r, p, uri_path_handler, 0);
  446. if (HANDLER_GO_ON != rc) return rc;
  447. if (r->handler_module == p->self) {
  448. handler_ctx *hctx = r->plugin_ctx[p->id];
  449. hctx->opts.backend = BACKEND_FASTCGI;
  450. hctx->opts.parse = fcgi_recv_parse;
  451. hctx->opts.pdata = hctx;
  452. hctx->stdin_append = fcgi_stdin_append;
  453. hctx->create_env = fcgi_create_env;
  454. if (!hctx->rb) {
  455. hctx->rb = chunkqueue_init(NULL);
  456. }
  457. else {
  458. chunkqueue_reset(hctx->rb);
  459. }
  460. }
  461. return HANDLER_GO_ON;
  462. }
  463. /* uri-path handler */
  464. static handler_t fcgi_check_extension_1(request_st * const r, void *p_d) {
  465. return fcgi_check_extension(r, p_d, 1);
  466. }
  467. /* start request handler */
  468. static handler_t fcgi_check_extension_2(request_st * const r, void *p_d) {
  469. return fcgi_check_extension(r, p_d, 0);
  470. }
  471. int mod_fastcgi_plugin_init(plugin *p);
  472. int mod_fastcgi_plugin_init(plugin *p) {
  473. p->version = LIGHTTPD_VERSION_ID;
  474. p->name = "fastcgi";
  475. p->init = gw_init;
  476. p->cleanup = gw_free;
  477. p->set_defaults = mod_fastcgi_set_defaults;
  478. p->handle_request_reset = gw_handle_request_reset;
  479. p->handle_uri_clean = fcgi_check_extension_1;
  480. p->handle_subrequest_start = fcgi_check_extension_2;
  481. p->handle_subrequest = gw_handle_subrequest;
  482. p->handle_trigger = gw_handle_trigger;
  483. p->handle_waitpid = gw_handle_waitpid_cb;
  484. return 0;
  485. }