URL Rewrite Architecture

URL rewrite or "remapping" means changing the URL used in the in the proxy request. This is initially the same as in the client request and remains so if no URL rewriting is done.

Rewriting is configured by an ordered list of rules. Each rule contains _parameters_ and _arguments_. Parameters are required and describe the basic rule. On top of the parameters are arguments, which are optional and adjust the behavior of the basic rule. These are distinguished by a leading '@' character, which marks an argument. Otherwise it is a parameter.

Implementation

class acl_filter_rule

An access check to determine if a rule is enabled for a request. The filter has a set of matching criteria and an action, which is either ALLOW or DENY. If the filter matches the request the action is used, otherwise the next filter is checked.

class UrlRewrite

The top level remapping structure. This is created from a configuration file and then used during a transaction to perform remapping. Data that is shared or needs to persist as long as the configuration is stored in this class. These are

The rules are stored here in one of several containers. The rule type is implicit in which container contains the rule. It is assumed that all rules in a container have the data needed for the rule type of that container.

class RegexMapping

A container for a regular expression mapping. This contains the base mapping along with the regular expression and a format string. The format string is annotated with the locations of regular expression match group substitutions so that if the regular expression matches, the results can be efficiently assembled in to the output host name.

' Licensed under the Apache License, Version 2.0 (the "License");
' you may not use this file except in compliance with the License.
' You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
' Unless required by  applicable law or agreed to in writing, software distributed under the License is distributed
' on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
' See the License for the specific language governing permissions and limitations under the License.

@startuml

hide empty members

class UrlRewrite << RefCountObj >> {
  forward_mappings
  reverse_mappings
  permanent_redirects
  temporary_redirects
  forward_mappings_with_recv_port
}

UrlRewrite --* MappingStore

class MappingStore {
  Rule collection
}

MappingStore --* "1" RegexMappingList
MappingStore --* "1" URLTable

class URLTable <<std::unordered_map>> {
  key: FQDN
  value: UrlMappingPathIndex
}

URLTable --* "*" UrlMappingPathIndex

class acl_filter_rule {
  Access check
  ============
  string name
  IpMap src_ip
  IpMap proxy_ip
  std::vector<RemapArg> argv
}

acl_filter_rule --* "next" acl_filter_rule
' acl_filter_rule --* "*" RemapArg
' acl_filter_rule --* "2" IpMap

class url_mapping {
  rewrite rule
  ================
  URL from
  URL to
}
note right: Mapping type is determined by\nwhich MappingStore owns\nthis mapping.

url_mapping --* "1" acl_filter_rule
note bottom: Local rule and copies of defined filters

url_mapping --* "1" "std::vector<RemapPluginInfo*>"
url_mapping --* "1" "std::vector<void*>"
note bottom: "Plugin instance data"
url_mapping --* "1" referrer_info
url_mapping --* "1" redirect_tag_str
url_mapping --* "2" URL

"std::vector<RemapPluginInfo*>" --o "*" RemapPluginInfo

redirect_tag_str --* "next" redirect_tag_str
note bottom: Redirect URL format elements

class referrer_info {
  Host rewrite Referer data
}

referrer_info --* "next" referrer_info

class UrlMappingPathIndex {
}

class UrlMappingTrie << Trie >> {
  key: path
  value: url_mapping
}

class UrlMappingGroup << std::map >> {
  key: { scheme, port }
  value: UrlMappingTrie
}

UrlMappingPathIndex --* "1" UrlMappingGroup
UrlMappingGroup --* "*" UrlMappingTrie
UrlMappingTrie --* "*" url_mapping

RegexMappingList --* "*" url_mapping

class RegexMappingList << Queue >> {
}

@enduml