httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From traw...@apache.org
Subject svn commit: r1674510 - in /httpd/httpd/trunk: CHANGES docs/manual/mod/mod_proxy_scgi.xml modules/proxy/mod_proxy_scgi.c
Date Sat, 18 Apr 2015 13:48:57 GMT
Author: trawick
Date: Sat Apr 18 13:48:57 2015
New Revision: 1674510

URL: http://svn.apache.org/r1674510
Log:
mod_proxy_scgi: ProxySCGIInternalRedirect now allows an alternate
response header to be used by the application, for when the application
or framework is unable to return Location in the internal-redirect
form.

Modified:
    httpd/httpd/trunk/CHANGES
    httpd/httpd/trunk/docs/manual/mod/mod_proxy_scgi.xml
    httpd/httpd/trunk/modules/proxy/mod_proxy_scgi.c

Modified: httpd/httpd/trunk/CHANGES
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/CHANGES?rev=1674510&r1=1674509&r2=1674510&view=diff
==============================================================================
--- httpd/httpd/trunk/CHANGES [utf-8] (original)
+++ httpd/httpd/trunk/CHANGES [utf-8] Sat Apr 18 13:48:57 2015
@@ -1,6 +1,11 @@
                                                          -*- coding: utf-8 -*-
 Changes with Apache 2.5.0
 
+  *) mod_proxy_scgi: ProxySCGIInternalRedirect now allows an alternate
+     response header to be used by the application, for when the application
+     or framework is unable to return Location in the internal-redirect
+     form.  [Jeff Trawick]
+
   *) ssl: Add a warning if protocol given in SSLProtocol or SSLProxyProtocol
      will override other parameters given in the same directive. This could be
      a missing + or - prefix.  PR 52820 [Christophe Jaillet]

Modified: httpd/httpd/trunk/docs/manual/mod/mod_proxy_scgi.xml
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/docs/manual/mod/mod_proxy_scgi.xml?rev=1674510&r1=1674509&r2=1674510&view=diff
==============================================================================
--- httpd/httpd/trunk/docs/manual/mod/mod_proxy_scgi.xml (original)
+++ httpd/httpd/trunk/docs/manual/mod/mod_proxy_scgi.xml Sat Apr 18 13:48:57 2015
@@ -144,8 +144,10 @@ ProxySCGISendfile X-Send-Static
 <name>ProxySCGIInternalRedirect</name>
 <description>Enable or disable internal redirect responses from the
 backend</description>
-<syntax>ProxySCGIInternalRedirect On|Off</syntax>
+<syntax>ProxySCGIInternalRedirect On|Off|<var>Headername</var></syntax>
 <default>ProxySCGIInternalRedirect On</default>
+<compatibility>The <var>Headername</var> feature is available in Apache
+httpd 2.5.0 and later.</compatibility>
 <contextlist><context>server config</context><context>virtual host</context>
 <context>directory</context></contextlist>
 
@@ -154,17 +156,23 @@ backend</description>
     to internally redirect the gateway to a different URL. This feature
     originates in <module>mod_cgi</module>, which internally redirects the
     response if the response status is <code>OK</code> (<code>200</code>)
and
-    the response contains a <code>Location</code> header and its value starts
-    with a slash (<code>/</code>). This value is interpreted as a new local
-    URL that Apache httpd internally redirects to.</p>
+    the response contains a <code>Location</code> (or configured alternate
+    header) and its value starts with a slash (<code>/</code>). This value is

+    interpreted as a new local URL that Apache httpd internally redirects to.</p>
 
     <p><module>mod_proxy_scgi</module> does the same as
     <module>mod_cgi</module> in this regard, except that you can turn off the
-    feature.</p>
+    feature or specify the use of a header other than <code>Location</code>.</p>
 
     <example><title>Example</title>
     <highlight language="config">
     ProxySCGIInternalRedirect Off
+
+# Django and some other frameworks will fully qualify "local URLs"
+# set by the application, so an alternate header must be used.
+&lt;Location /django-app/&gt;
+    ProxySCGIInternalRedirect X-Location
+&lt;/Location&gt;
     </highlight>
     </example>
 </usage>

Modified: httpd/httpd/trunk/modules/proxy/mod_proxy_scgi.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/proxy/mod_proxy_scgi.c?rev=1674510&r1=1674509&r2=1674510&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/proxy/mod_proxy_scgi.c (original)
+++ httpd/httpd/trunk/modules/proxy/mod_proxy_scgi.c Sat Apr 18 13:48:57 2015
@@ -64,10 +64,12 @@ typedef struct {
 
 const char *scgi_sendfile_off = "off";
 const char *scgi_sendfile_on = "X-Sendfile";
+const char *scgi_internal_redirect_off = "off";
+const char *scgi_internal_redirect_on = "Location";
 
 typedef struct {
     const char *sendfile;
-    int internal_redirect;
+    const char *internal_redirect;
 } scgi_config;
 
 
@@ -417,11 +419,29 @@ static int pass_response(request_rec *r,
         }
     }
 
-    if (conf->internal_redirect && r->status == HTTP_OK) {
-        location = apr_table_get(r->headers_out, "Location");
+    if (r->status == HTTP_OK 
+        && (!conf->internal_redirect /* default === On */
+            || conf->internal_redirect != scgi_internal_redirect_off)) {
+        short err = 1;
+        const char *location_header = conf->internal_redirect ? 
+            conf->internal_redirect : scgi_internal_redirect_on;
+
+        location = apr_table_get(r->err_headers_out, location_header);
+        if (!location) {
+            err = 0;
+            location = apr_table_get(r->headers_out, location_header);
+        }
         if (location && *location == '/') {
             scgi_request_config *req_conf = apr_palloc(r->pool,
                                                        sizeof(*req_conf));
+            if (strcasecmp(location_header, "Location")) {
+                if (err) {
+                    apr_table_unset(r->err_headers_out, location_header);
+                }
+                else {
+                    apr_table_unset(r->headers_out, location_header);
+                }
+            }
             req_conf->location = location;
             req_conf->type = scgi_internal_redirect;
             ap_set_module_config(r->request_config, &proxy_scgi_module,
@@ -565,8 +585,8 @@ static void *create_scgi_config(apr_pool
 {
     scgi_config *conf=apr_palloc(p, sizeof(*conf));
 
-    conf->sendfile = NULL;
-    conf->internal_redirect = -1;
+    conf->sendfile = NULL; /* === default (off) */
+    conf->internal_redirect = NULL; /* === default (on) */
 
     return conf;
 }
@@ -577,7 +597,7 @@ static void *merge_scgi_config(apr_pool_
     scgi_config *base=base_, *add=add_, *conf=apr_palloc(p, sizeof(*conf));
 
     conf->sendfile = add->sendfile ? add->sendfile: base->sendfile;
-    conf->internal_redirect =   (add->internal_redirect != -1)
+    conf->internal_redirect = add->internal_redirect
                               ? add->internal_redirect
                               : base->internal_redirect;
     return conf;
@@ -602,16 +622,33 @@ static const char *scgi_set_send_file(cm
 }
 
 
+static const char *scgi_set_internal_redirect(cmd_parms *cmd, void *mconfig,
+                                              const char *arg)
+{
+    scgi_config *conf = mconfig;
+
+    if (!strcasecmp(arg, "Off")) {
+        conf->internal_redirect = scgi_internal_redirect_off;
+    }
+    else if (!strcasecmp(arg, "On")) {
+        conf->internal_redirect = scgi_internal_redirect_on;
+    }
+    else {
+        conf->internal_redirect = arg;
+    }
+    return NULL;
+}
+
+
 static const command_rec scgi_cmds[] =
 {
     AP_INIT_TAKE1("ProxySCGISendfile", scgi_set_send_file, NULL,
                   RSRC_CONF|ACCESS_CONF,
-                  "The name of the X-Sendfile peudo response header or "
+                  "The name of the X-Sendfile pseudo response header or "
                   "On or Off"),
-    AP_INIT_FLAG("ProxySCGIInternalRedirect", ap_set_flag_slot,
-                 (void*)APR_OFFSETOF(scgi_config, internal_redirect),
-                 RSRC_CONF|ACCESS_CONF,
-                 "Off if internal redirect responses should not be accepted"),
+    AP_INIT_TAKE1("ProxySCGIInternalRedirect", scgi_set_internal_redirect, NULL,
+                  RSRC_CONF|ACCESS_CONF,
+                  "The name of the pseudo response header or On or Off"),
     {NULL}
 };
 



Mime
View raw message