Commit ba269f54 authored by Sander Striker's avatar Sander Striker
Browse files

Rewrite Cookies and other headers in mod_proxy_ajp as configured with

ProxyPassReverse and ProxyPassReverseCookiePath.

* modules/proxy/proxy_ajp.c

  (ap_proxy_ajp_request): Update call to ajp_parse_header().


* modules/proxy/ajp.h

  (ajp_msg_get_string): constify argument.

  (ajp_parse_header): Add conf argument.


* modules/proxy/proxy_util.c

  (ap_proxy_location_reverse_map): Promoted from mod_proxy_http.

  (ap_proxy_cookie_reverse_map): Promoted from mod_proxy_http;
    renamed from proxy_cookie_reverse_map.


* modules/proxy/ajp_msg.c

  (ajp_msg_get_string): constify argument.


* modules/proxy/proxy_http.c

  (ap_proxy_location_reverse_map, proxy_cookie_reverse_map: Removed.

  (process_proxy_header): Update header mapping table to reference the now
    public functions.


* modules/proxy/ajp_header.c

  (ajp_unmarshal_response): And conf argument.  Reverse map cookies and
    other headers.

  (ajp_parse_header): Update call to ajp_unmarshal_response().


* modules/proxy/mod_proxy.h

  (ap_proxy_location_reverse_map, ap_proxy_cookie_reverse_map): Declare
    functions that have been promoted to be public.

  (ap_proxy_header_reverse_map_fn): Typedef for the signature of the above
    two functions (currently used in mod_proxy_http).


git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@124901 13f79535-47bb-0310-9956-ffa450edef68
parent b76cca31
Loading
Loading
Loading
Loading
+5 −2
Changes for modules/proxy/ajp.h: 5 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -79,6 +79,8 @@
#include "http_log.h"
#endif

#include "mod_proxy.h"


/** AJP Specific error codes
 */
@@ -296,7 +298,7 @@ apr_status_t ajp_msg_peek_uint8(ajp_msg_t *msg, apr_byte_t *rvalue);
 * @param rvalue    Pointer where value will be returned
 * @return          APR_SUCCESS or error
 */
apr_status_t ajp_msg_get_string(ajp_msg_t *msg, char **rvalue);
apr_status_t ajp_msg_get_string(ajp_msg_t *msg, const char **rvalue);


/**
@@ -436,7 +438,8 @@ int ajp_parse_type(request_rec *r, ajp_msg_t *msg);
 * @param msg       AJP message
 * @return          APR_SUCCESS or error
 */
apr_status_t ajp_parse_header(request_rec  *r, ajp_msg_t *msg);
apr_status_t ajp_parse_header(request_rec *r, proxy_server_conf *conf,
                              ajp_msg_t *msg);

/** 
 * Parse the message body and return data address and length 
+21 −6
Changes for modules/proxy/ajp_header.c: 21 added lines, 6 removed lines.
Original line number Diff line number Diff line
@@ -447,7 +447,8 @@ body_chunk :=


static apr_status_t ajp_unmarshal_response(ajp_msg_t *msg,
                                  request_rec  *r)
                                           request_rec *r,
                                           proxy_server_conf *conf)
{
    apr_uint16_t status;
    apr_status_t rc;
@@ -491,8 +492,8 @@ static apr_status_t ajp_unmarshal_response(ajp_msg_t *msg,

    for(i = 0 ; i < (int) num_headers ; i++) {
        apr_uint16_t name;
        char *stringname;
        char *value;
        const char *stringname;
        const char *value;
        rc  = ajp_msg_peek_uint16(msg, &name);
        if (rc != APR_SUCCESS) {
            return APR_EGENERAL;
@@ -500,7 +501,7 @@ static apr_status_t ajp_unmarshal_response(ajp_msg_t *msg,
                
        if ((name & 0XFF00) == 0XA000) {
            ajp_msg_peek_uint16(msg, &name);
            stringname = (char *)long_res_header_for_sc(name);
            stringname = long_res_header_for_sc(name);
            if (stringname == NULL) {
                ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server,
                       "Error ajp_unmarshal_response - "
@@ -530,12 +531,25 @@ static apr_status_t ajp_unmarshal_response(ajp_msg_t *msg,
            return APR_EGENERAL;
        }

        /* Set-Cookie need additional processing */
        if (!strcasecmp(stringname, "Set-Cookie")) {
            value = ap_proxy_cookie_reverse_map(r, conf, value);
        }
        /* Location, Content-Location and URI need additional processing */
        else if (!strcasecmp(stringname, "Location")
                 || !strcasecmp(stringname, "Content-Location")
                 || !strcasecmp(stringname, "URI"))
        {
          value = ap_proxy_location_reverse_map(r, conf, value);
        }

#if defined(AS400) || defined(_OSD_POSIX)
        ap_xlate_proto_from_ascii(value, strlen(value));
#endif
        ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
               "ajp_unmarshal_response: Header[%d] [%s] = [%s]", 
                       i, stringname, value);

        apr_table_add(r->headers_out, stringname, value);

        /* Content-type needs an additional handling */
@@ -624,7 +638,8 @@ int ajp_parse_type(request_rec *r, ajp_msg_t *msg)
}

/* parse the header */
apr_status_t ajp_parse_header(request_rec  *r, ajp_msg_t *msg)
apr_status_t ajp_parse_header(request_rec  *r, proxy_server_conf *conf,
                              ajp_msg_t *msg)
{
    apr_byte_t result;
    apr_status_t rc;
@@ -640,7 +655,7 @@ apr_status_t ajp_parse_header(request_rec *r, ajp_msg_t *msg)
               "ajp_parse_headers: wrong type %02x expecting 0x04", result);
        return APR_EGENERAL;
    }
    return ajp_unmarshal_response(msg, r);
    return ajp_unmarshal_response(msg, r, conf);
}

/* parse the body and return data address and length */
+2 −2
Changes for modules/proxy/ajp_msg.c: 2 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -417,7 +417,7 @@ apr_status_t ajp_msg_get_uint8(ajp_msg_t *msg, apr_byte_t *rvalue)
 * @param rvalue    Pointer where value will be returned
 * @return          APR_SUCCESS or error
 */
apr_status_t ajp_msg_get_string(ajp_msg_t *msg, char **rvalue)
apr_status_t ajp_msg_get_string(ajp_msg_t *msg, const char **rvalue)
{
    apr_uint16_t size;
    apr_size_t   start;
@@ -433,7 +433,7 @@ apr_status_t ajp_msg_get_string(ajp_msg_t *msg, char **rvalue)
    msg->pos += (apr_size_t)size;
    msg->pos++;                   /* a String in AJP is NULL terminated */

    *rvalue = (char *)(msg->buf + start);
    *rvalue = (const char *)(msg->buf + start);
    return APR_SUCCESS;
}

+21 −0
Changes for modules/proxy/mod_proxy.h: 21 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -399,6 +399,27 @@ PROXY_DECLARE(int) ap_proxy_connect_to_backend(apr_socket_t **, const char *, ap
PROXY_DECLARE(int) ap_proxy_ssl_enable(conn_rec *c);
PROXY_DECLARE(int) ap_proxy_ssl_disable(conn_rec *c);

/* Header mapping functions, and a typedef of their signature */
PROXY_DECLARE(const char *) ap_proxy_location_reverse_map(request_rec *r, proxy_server_conf *conf, const char *url);
PROXY_DECLARE(const char *) ap_proxy_cookie_reverse_map(request_rec *r, proxy_server_conf *conf, const char *str);

#if !defined(WIN32)
typedef const char *(*ap_proxy_header_reverse_map_fn)(request_rec *,
                       proxy_server_conf *, const char *);
#elif defined(PROXY_DECLARE_STATIC)
typedef const char *(__stdcall *ap_proxy_header_reverse_map_fn)(request_rec *,
                                 proxy_server_conf *, const char *);
#elif defined(PROXY_DECLARE_EXPORT)
typedef __declspec(dllexport) const char *
  (__stdcall *ap_proxy_header_reverse_map_fn)(request_rec *,
               proxy_server_conf *, const char *);
#else
typedef __declspec(dllimport) const char *
  (__stdcall *ap_proxy_header_reverse_map_fn)(request_rec *,
               proxy_server_conf *, const char *);
#endif


/* Connection pool API */
/**
 * Get the worker from proxy configuration
+1 −1
Changes for modules/proxy/proxy_ajp.c: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -261,7 +261,7 @@ static int ap_proxy_ajp_request(apr_pool_t *p, request_rec *r,
                break;
            case CMD_AJP13_SEND_HEADERS:
                /* AJP13_SEND_HEADERS: process them */
                status = ajp_parse_header(r, conn->data);
                status = ajp_parse_header(r, conf, conn->data);
                if (status != APR_SUCCESS) {
                    isok=0;
                }
Loading