You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by zw...@apache.org on 2010/02/03 22:45:28 UTC
svn commit: r906258 - in /incubator/trafficserver/traffic/trunk/proxy:
RemapAPI.h http2/remap/RemapPlugins.cc http2/remap/UrlRewrite.cc
Author: zwoop
Date: Wed Feb 3 21:45:27 2010
New Revision: 906258
URL: http://svn.apache.org/viewvc?rev=906258&view=rev
Log:
TS-23: Support matrix parameters in remap plugins.
Modified:
incubator/trafficserver/traffic/trunk/proxy/RemapAPI.h
incubator/trafficserver/traffic/trunk/proxy/http2/remap/RemapPlugins.cc
incubator/trafficserver/traffic/trunk/proxy/http2/remap/UrlRewrite.cc
Modified: incubator/trafficserver/traffic/trunk/proxy/RemapAPI.h
URL: http://svn.apache.org/viewvc/incubator/trafficserver/traffic/trunk/proxy/RemapAPI.h?rev=906258&r1=906257&r2=906258&view=diff
==============================================================================
--- incubator/trafficserver/traffic/trunk/proxy/RemapAPI.h (original)
+++ incubator/trafficserver/traffic/trunk/proxy/RemapAPI.h Wed Feb 3 21:45:27 2010
@@ -120,6 +120,9 @@
const char *request_query; /* request query string */
int request_query_size; /* request query string size. A negative size means remove it completely. */
+ const char *request_matrix; /* request matrix string */
+ int request_matrix_size; /* request matrix string size. A negative size means remove it completely. */
+
const char *from_scheme; /* The "from" scheme (e.g. HTTP) */
int from_scheme_len; /* The len of the "from" scheme */
@@ -138,6 +141,8 @@
int new_path_size; /* new path string size (0 - do not change request path) */
char new_query[TSREMAP_RRI_MAX_PATH_SIZE]; /* new query string */
int new_query_size; /* new query string size (0 - do not change request query) */
+ char new_matrix[TSREMAP_RRI_MAX_PATH_SIZE]; /* new matrix parameter string */
+ int new_matrix_size; /* new matrix parameter string size (0 - do not change matrix parameters) */
char redirect_url[TSREMAP_RRI_MAX_REDIRECT_URL]; /* redirect url (to redirect/reject request) */
int redirect_url_size; /* redirect url size (0 - empty redirect url string) */
int require_ssl; /* Require the toScheme to become SSL (e.g. HTTPS). */
Modified: incubator/trafficserver/traffic/trunk/proxy/http2/remap/RemapPlugins.cc
URL: http://svn.apache.org/viewvc/incubator/trafficserver/traffic/trunk/proxy/http2/remap/RemapPlugins.cc?rev=906258&r1=906257&r2=906258&view=diff
==============================================================================
--- incubator/trafficserver/traffic/trunk/proxy/http2/remap/RemapPlugins.cc (original)
+++ incubator/trafficserver/traffic/trunk/proxy/http2/remap/RemapPlugins.cc Wed Feb 3 21:45:27 2010
@@ -123,6 +123,9 @@
// Get request query
rri.request_query = _request_url->query_get(&rri.request_query_size);
+ // Get request matrix parameters
+ rri.request_matrix = _request_url->params_get(&rri.request_matrix_size);
+
// Get toURL host
rri.remap_to_host = toHost;
rri.remap_to_host_size = toHostLen;
@@ -142,7 +145,12 @@
rri.require_ssl = -1; // By default, the plugin will not modify the to_scheme
// Used to see if plugin changed anything.
- rri.new_port = (rri.new_host_size = (rri.new_path_size = (rri.redirect_url_size = (rri.new_query_size = 0))));
+ rri.new_port = 0;
+ rri.new_host_size = 0;
+ rri.new_path_size = 0;
+ rri.redirect_url_size = 0;
+ rri.new_query_size = 0;
+ rri.new_matrix_size = 0;
// Get request Host
rri.request_host = _request_url->host_get(&rri.request_host_size);
@@ -200,7 +208,7 @@
_request_url->path_set(rri.new_path, rri.new_path_size);
*plugin_modified_path = true;
}
- // Finally, update the query string. This has a special case, where a negative
+ // Update the query string. This has a special case, where a negative
// size value means to remove the query string entirely.
if (rri.new_query_size != 0) {
if (rri.new_query_size < 0)
@@ -208,6 +216,14 @@
else
_request_url->query_set(rri.new_query, rri.new_query_size);
}
+ // Update the matrix parameter string. This has a special case, where a negative
+ // size value means to remove the matrix parameter string entirely.
+ if (rri.new_matrix_size != 0) {
+ if (rri.new_matrix_size < 0)
+ _request_url->params_set(NULL, 0);
+ else
+ _request_url->params_set(rri.new_matrix, rri.new_matrix_size);
+ }
// If require_ssl is set, make sure our toScheme is SSL'ified. It's done this way
// to avoid dealing with weirness (say, a plugin trying to modify the "toScheme"
// from FTP to HTTPS).
Modified: incubator/trafficserver/traffic/trunk/proxy/http2/remap/UrlRewrite.cc
URL: http://svn.apache.org/viewvc/incubator/trafficserver/traffic/trunk/proxy/http2/remap/UrlRewrite.cc?rev=906258&r1=906257&r2=906258&view=diff
==============================================================================
--- incubator/trafficserver/traffic/trunk/proxy/http2/remap/UrlRewrite.cc (original)
+++ incubator/trafficserver/traffic/trunk/proxy/http2/remap/UrlRewrite.cc Wed Feb 3 21:45:27 2010
@@ -881,162 +881,6 @@
if (plugin || debug_on)
request_url->string_get_buf(origURLBuf, sizeof(origURLBuf), &origURLBufSize);
-#if 0 // Dead code here?
- if (plugin) {
- bool do_x_proto_check = true;
- TSRemapRequestInfo rri;
-
- // Get request port
- rri.request_port = requestPort;
-
- // Set request path
- rri.request_path = requestPath;
- rri.request_path_size = requestPathLen;
-
- // Get request query
- rri.request_query = request_url->query_get(&rri.request_query_size);
-
- // Get toURL host
- rri.remap_to_host = toHost;
- rri.remap_to_host_size = toHostLen;
-
- // Set "remap from" path
- rri.remap_from_path = fromPath;
- rri.remap_from_path_size = fromPathLen;
-
- // Set "remap to" path
- rri.remap_to_path = toPath;
- rri.remap_to_path_size = toPathLen;
-
- rri.size = sizeof(rri);
- rri.orig_url = &origURLBuf[0];
- rri.orig_url_size = origURLBufSize;
-
- rri.remap_from_port = map_from->port_get();
- rri.remap_to_port = map_to->port_get();
-
- // Set the schemes for this map
- if (unlikely(mapPtr->wildcard_from_scheme)) {
- rri.from_scheme = request_url->scheme_get(&rri.from_scheme_len);
- } else {
- rri.from_scheme = map_from->scheme_get(&rri.from_scheme_len);
- }
- rri.to_scheme = map_to->scheme_get(&rri.to_scheme_len);
- rri.require_ssl = -1; // By default, the plugin will not modify the to_scheme
-
- // Used to see if plugin changed anything.
- rri.new_port = (rri.new_host_size = (rri.new_path_size = (rri.redirect_url_size = (rri.new_query_size = 0))));
-
- // Get fromURL Host
- rri.remap_from_host = map_from->host_get(&rri.remap_from_host_size);
- // Get request Host
- rri.request_host = request_url->host_get(&rri.request_host_size);
- // Copy client IP address
- rri.client_ip = s ? s->client_info.ip : 0;
-
- // Get Cookie header
- if (request_header->presence(MIME_PRESENCE_COOKIE)) {
- rri.request_cookie = request_header->value_get(MIME_FIELD_COOKIE, MIME_LEN_COOKIE, &rri.request_cookie_size);
- } else {
- rri.request_cookie = NULL;
- rri.request_cookie_size = 0;
- }
- // Prepare State for the future
- if (s) {
- s->fp_tsremap_os_response = plugin->fp_tsremap_os_response;
- s->remap_plugin_instance = mapPtr->remap_plugin_instance;
- }
-
- plugin_retcode =
- plugin->fp_tsremap_remap(mapPtr->remap_plugin_instance, s ? (rhandle) (s->state_machine) : NULL, &rri);
-
- // First step after plugin remap must be "redirect url" check
- if (redirect && plugin_retcode && rri.redirect_url_size > 0) {
- *redirect =
- rri.redirect_url[0] ? xstrndup(rri.redirect_url, rri.redirect_url_size) : xstrdup("http://www.apache.org");
- return rri.redirect_url_size; // we must return redirect buffer immeditely
- }
-
- if (plugin_retcode) {
- // Modify the host
- if (rri.new_host_size > 0) {
- request_url->host_set(rri.new_host, rri.new_host_size);
- plugin_modified_host = true;
- }
- // Modify the port, but only if it's different than the request port
- if (rri.new_port != 0) {
- if (requestPort != rri.new_port)
- request_url->port_set(rri.new_port);
- plugin_modified_port = true;
- }
- // Modify the path
- if (rri.new_path_size != 0) {
- if (rri.new_path_size < 0)
- request_url->path_set(NULL, 0);
- else
- request_url->path_set(rri.new_path, rri.new_path_size);
- plugin_modified_path = true;
- }
- // Finally, update the query string. This has a special case, where a negative
- // size value means to remove the query string entirely.
- if (rri.new_query_size != 0) {
- if (rri.new_query_size < 0)
- request_url->query_set(NULL, 0);
- else
- request_url->query_set(rri.new_query, rri.new_query_size);
- }
- // If require_ssl is set, make sure our toScheme is SSL'ified. It's done this way
- // to avoid dealing with weirness (say, a plugin trying to modify the "toScheme"
- // from FTP to HTTPS).
- if (rri.require_ssl != -1) {
- // TODO add other protocols here if/when necessary
- if (rri.require_ssl == 1) // Plugin wish to turn on SSL (if not already set)
- {
- if ((rri.to_scheme_len == URL_LEN_HTTP) && (rri.to_scheme == URL_SCHEME_HTTP)) {
- request_url->scheme_set(URL_SCHEME_HTTPS, URL_LEN_HTTPS);
- do_x_proto_check = false;
- Debug("url_rewrite", "Plugin changed protocol from HTTP to HTTPS");
- }
- } else // Plugin wish to turn off SSL (if already set)
- {
- if ((rri.to_scheme_len == URL_LEN_HTTPS) && (rri.to_scheme == URL_SCHEME_HTTPS)) {
- request_url->scheme_set(URL_SCHEME_HTTP, URL_LEN_HTTP);
- do_x_proto_check = false;
- Debug("url_rewrite", "Plugin changed protocol from HTTPS to HTTP");
- }
- }
- }
- // Check to see if this a cross protocol mapping
- // If so we need to create a new URL since the URL*
- // we get from the request_hdr really points to a subclass
- // of URL that is specific to the protocol
- //
- if (do_x_proto_check && (rri.from_scheme != rri.to_scheme)) {
- request_url->scheme_set(rri.to_scheme, rri.to_scheme_len);
- if (is_debug_tag_set("url_rewrite")) {
- char tmp_buf[2048];
- Debug("url_rewrite", "Cross protocol mapping to %s in plugin",
- request_url->string_get_buf(tmp_buf, (int) sizeof(tmp_buf)));
- }
- }
- }
- } else {
- // Handle cross protocol mapping when there are no remap plugin(s).
- // This is almost identical to above, but has to fetch the schemes.
- int to_len, from_len;
- const char *to_scheme = map_to->scheme_get(&to_len);
-
- if (to_scheme != request_url->scheme_get(&from_len)) {
- request_url->scheme_set(to_scheme, to_len);
- if (is_debug_tag_set("url_rewrite")) {
- char tmp_buf[2048];
- Debug("url_rewrite", "Cross protocol mapping to %s",
- request_url->string_get_buf(tmp_buf, (int) sizeof(tmp_buf)));
- }
- }
- }
-#endif
-
// Fall back to "remap" maps if plugin didn't change things already
if (!plugin_modified_host)
request_url->host_set(toHost, toHostLen);